當前位置: 首頁>>代碼示例>>Python>>正文


Python discovery.load_platform方法代碼示例

本文整理匯總了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 
開發者ID:markperdue,項目名稱:pyvesync,代碼行數:25,代碼來源:__init__.py

示例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 
開發者ID:gerard33,項目名稱:home-assistant-archive,代碼行數:24,代碼來源:__init__.py

示例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 
開發者ID:sampsyo,項目名稱:hass-smartthinq,代碼行數:26,代碼來源:__init__.py

示例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 
開發者ID:peterbuga,項目名稱:HASS-sonoff-ewelink,代碼行數:25,代碼來源:__init__.py

示例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 
開發者ID:Teagan42,項目名稱:HomeAssistantConfig,代碼行數:29,代碼來源:my_sleepiq.py

示例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) 
開發者ID:StyraHem,項目名稱:ShellyForHASS,代碼行數:39,代碼來源:__init__.py

示例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 
開發者ID:charleyzhu,項目名稱:HomeAssistant_Components,代碼行數:51,代碼來源:dlna.py

示例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()) 
開發者ID:cyberjunky,項目名稱:home-assistant-custom-components,代碼行數:62,代碼來源:__init__.py


注:本文中的homeassistant.helpers.discovery.load_platform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。