Advertisement
grea09

foo/__init__.py

Mar 18th, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. """Support to embed Foo."""
  4. from homeassistant import config_entries
  5. from homeassistant.helpers import config_entry_flow
  6.  
  7.  
  8. DOMAIN = 'foo'
  9.  
  10.  
  11. async def async_setup(hass, config):
  12.     """Set up the Foo component."""
  13.     conf = config.get(DOMAIN)
  14.  
  15.     hass.data[DOMAIN] = conf or {}
  16.  
  17.     if conf is not None:
  18.         hass.async_create_task(hass.config_entries.flow.async_init(
  19.             DOMAIN, context={'source': config_entries.SOURCE_IMPORT}))
  20.  
  21.     return True
  22.  
  23.  
  24. async def async_setup_entry(hass, entry):
  25.     """Set up Foo from a config entry."""
  26.     hass.async_create_task(hass.config_entries.async_forward_entry_setup(
  27.         entry, 'switch'))
  28.     return True
  29.  
  30.  
  31. async def _async_has_devices(hass):
  32.     """Return if there are devices that can be discovered."""
  33.     def discover():
  34.         return [{'name': 'super_switch', 'host': '1.1.1.1', 'uid': '42'}]
  35.  
  36.     return await hass.async_add_executor_job(discover)
  37.  
  38.  
  39. config_entry_flow.register_discovery_flow(
  40.     DOMAIN, 'Foo', _async_has_devices, config_entries.CONN_CLASS_LOCAL_PUSH)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement