本文整理汇总了Python中homeassistant.helpers.discovery.load_platform方法的典型用法代码示例。如果您正苦于以下问题:Python discovery.load_platform方法的具体用法?Python discovery.load_platform怎么用?Python discovery.load_platform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.helpers.discovery
的用法示例。
在下文中一共展示了discovery.load_platform方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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
示例2: setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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
示例3: setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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
示例4: async_setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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
示例5: setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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
示例6: _async_block_added
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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)
示例7: async_setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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
示例8: setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import load_platform [as 别名]
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())