Python homeassistant.helpers.discovery.load_platform() Examples
The following are 8
code examples of homeassistant.helpers.discovery.load_platform().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
homeassistant.helpers.discovery
, or try the search function
.
Example #1
Source File: __init__.py From pyvesync with MIT License | 6 votes |
def setup(hass, config): """Set up the VeSync component.""" from pyvesync.vesync import VeSync conf = config[DOMAIN] manager = VeSync(conf.get(CONF_USERNAME), conf.get(CONF_PASSWORD), time_zone=conf.get(CONF_TIME_ZONE)) if not manager.login(): _LOGGER.error("Unable to login to VeSync") return manager.update() hass.data[DOMAIN] = { 'manager': manager } discovery.load_platform(hass, 'switch', DOMAIN, {}, config) discovery.load_platform(hass, 'fan', DOMAIN, {}, config) return True
Example #2
Source File: __init__.py From home-assistant-archive with MIT License | 6 votes |
def setup(hass, config: dict): """Set up the BMW connected drive components.""" accounts = [] for name, account_config in config[DOMAIN].items(): accounts.append(setup_account(account_config, hass, name)) hass.data[DOMAIN] = accounts def _update_all(call) -> None: """Update all BMW accounts.""" for cd_account in hass.data[DOMAIN]: cd_account.update() # Service to manually trigger updates for all accounts. hass.services.register(DOMAIN, SERVICE_UPDATE_STATE, _update_all) _update_all(None) for component in BMW_COMPONENTS: discovery.load_platform(hass, component, DOMAIN, {}, config) return True
Example #3
Source File: __init__.py From hass-smartthinq with MIT License | 6 votes |
def setup(hass, config): if DOMAIN not in config: LOGGER.warning(DEPRECATION_WARNING) return True if KEY_SMARTTHINQ_DEVICES not in hass.data: hass.data[KEY_SMARTTHINQ_DEVICES] = [] refresh_token = config[DOMAIN].get(CONF_TOKEN) region = config[DOMAIN].get(CONF_REGION) language = config[DOMAIN].get(CONF_LANGUAGE) client = wideq.Client.from_token(refresh_token, region, language) hass.data[CONF_TOKEN] = refresh_token hass.data[CONF_REGION] = region hass.data[CONF_LANGUAGE] = language for device in client.devices: hass.data[KEY_SMARTTHINQ_DEVICES].append(device.id) for component in SMARTTHINQ_COMPONENTS: discovery.load_platform(hass, component, DOMAIN, {}, config) return True
Example #4
Source File: __init__.py From HASS-sonoff-ewelink with MIT License | 6 votes |
def async_setup(hass, config): """Setup the eWelink/Sonoff component.""" _LOGGER.debug("Create the main object") hass.data[DOMAIN] = Sonoff(hass, config) if hass.data[DOMAIN].get_wshost(): # make sure login was successful for component in ['switch','sensor']: discovery.load_platform(hass, component, DOMAIN, {}, config) hass.bus.async_listen('sonoff_state', hass.data[DOMAIN].state_listener) # close the websocket when HA stops # hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, hass.data[DOMAIN].get_ws().close()) def update_devices(event_time): asyncio.run_coroutine_threadsafe( hass.data[DOMAIN].async_update(), hass.loop) async_track_time_interval(hass, update_devices, hass.data[DOMAIN].get_scan_interval()) return True
Example #5
Source File: my_sleepiq.py From HomeAssistantConfig with MIT License | 5 votes |
def setup(hass, config): """Set up the SleepIQ component. Will automatically load sensor components to support devices discovered on the account. """ # pylint: disable=global-statement global DATA from sleepyq import Sleepyq username = config[DOMAIN][CONF_USERNAME] password = config[DOMAIN][CONF_PASSWORD] client = Sleepyq(username, password) try: DATA = SleepIQData(client) DATA.update() except HTTPError: message = """ SleepIQ failed to login, double check your username and password" """ _LOGGER.error(message) return False discovery.load_platform(hass, 'sensor', DOMAIN, {}, config) discovery.load_platform(hass, 'binary_sensor', DOMAIN, {}, config) return True
Example #6
Source File: __init__.py From ShellyForHASS with MIT License | 5 votes |
def _async_block_added(self, block): block.cb_updated.append(self._block_updated) discover_block = self.discover \ or self._get_device_config(block.id) != {} block.hass_data = { 'allow_upgrade_switch' : self._get_specific_config_root(CONF_UPGRADE_SWITCH, block.id), 'sensor_cfg' : self._get_sensor_config(block.id), 'discover': discover_block } #Config block if block.unavailable_after_sec is None: block.unavailable_after_sec \ = self._get_specific_config_root(CONF_UNAVALABLE_AFTER_SEC, block.id) # dev_reg = await self.hass.helpers.device_registry.async_get_registry() # dev_reg.async_get_or_create( # config_entry_id=block.id, # identifiers={(DOMAIN, block.id)}, # manufacturer="Allterco", # name=block.friendly_name(), # model=block.type_name(), # sw_version=block.fw_version(), # ) #if conf.get(CONF_ADDITIONAL_INFO): #block.update_status_information() # cfg_sensors = conf.get(CONF_SENSORS) # for sensor in cfg_sensors: # sensor_type = ALL_SENSORS[sensor] # if 'attr' in sensor_type: # attr = {'sensor_type':sensor_type['attr'], # SHELLY_BLOCK_ID : block_key} # discovery.load_platform(hass, 'sensor', DOMAIN, attr, # config)
Example #7
Source File: dlna.py From HomeAssistant_Components with Apache License 2.0 | 4 votes |
def async_setup(hass, config): dlna = Dlnadriver() regDevices = [] @asyncio.coroutine def scan_devices(now): """Scan for MediaPlayer.""" devices = yield from hass.loop.run_in_executor( None, dlna.discover_MediaPlayer) for device in devices: isFind = False devUUID = device.get('uuid') for regDev in regDevices: regUUID = regDev.get('uuid') if devUUID == regUUID: isFind = True if isFind == False: regDevices.append(device) load_platform(hass, 'media_player', DOMAIN, device) _LOGGER.info('RegDevice:{}'.format(device.get('friendly_name'))) else: isFind = False # if device not in regDevices: # regDevices.append(device) # load_platform(hass,'media_player',DOMAIN,device) # _LOGGER.info('RegDevice:{}'.format(device.get('friendly_name'))) uuid = device.get('uuid') if uuid != '': hass.data[uuid] = device async_track_point_in_utc_time(hass, scan_devices, dt_util.utcnow() + SCAN_INTERVAL) @callback def schedule_first(event): """Schedule the first discovery when Home Assistant starts up.""" async_track_point_in_utc_time(hass, scan_devices, dt_util.utcnow()) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, schedule_first) return True
Example #8
Source File: __init__.py From home-assistant-custom-components with MIT License | 4 votes |
def setup(hass, config): """Setup Volkswagen Carnet component""" username = config[DOMAIN].get(CONF_USERNAME) password = config[DOMAIN].get(CONF_PASSWORD) interval = config[DOMAIN].get(CONF_UPDATE_INTERVAL) state = hass.data[DATA_KEY] = VolkswagenData(config) # create carnet connection connection = Connection(username, password) # login to carnet _LOGGER.debug("Creating connection to carnet") connection._login() if not connection.logged_in: _LOGGER.warning('Could not login to carnet') def discover_vehicle(vehicle): """Load relevant platforms.""" state.entities[vehicle.vin] = [] for attr, (component, *_) in RESOURCES.items(): if (getattr(vehicle, attr + '_supported', True) and attr in config[DOMAIN].get(CONF_RESOURCES, [attr])): discovery.load_platform( hass, component, DOMAIN, (vehicle.vin, attr), config) def update_vehicle(vehicle): """Review updated information on vehicle.""" state.vehicles[vehicle.vin] = vehicle if vehicle.vin not in state.entities: discover_vehicle(vehicle) for entity in state.entities[vehicle.vin]: entity.schedule_update_ha_state() dispatcher_send(hass, SIGNAL_VEHICLE_SEEN, vehicle) def update(now): """Update status from Volkswagen Carnet""" try: if not connection.logged_in: connection._login() if not connection.logged_in: _LOGGER.warning('Could not login to carnet') else: if not connection.update(): _LOGGER.warning("Could not query carnet") return False else: _LOGGER.debug("Updating data from carnet") for vehicle in connection.vehicles: update_vehicle(vehicle) return True finally: track_point_in_utc_time(hass, update, utcnow() + interval) _LOGGER.info("Starting service") return update(utcnow())