当前位置: 首页>>代码示例>>Python>>正文


Python const.ATTR_ENTITY_ID属性代码示例

本文整理汇总了Python中homeassistant.const.ATTR_ENTITY_ID属性的典型用法代码示例。如果您正苦于以下问题:Python const.ATTR_ENTITY_ID属性的具体用法?Python const.ATTR_ENTITY_ID怎么用?Python const.ATTR_ENTITY_ID使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在homeassistant.const的用法示例。


在下文中一共展示了const.ATTR_ENTITY_ID属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sync_device

# 需要导入模块: from homeassistant import const [as 别名]
# 或者: from homeassistant.const import ATTR_ENTITY_ID [as 别名]
def sync_device(self):
        remove_listener = self._sync_manager.get('remove_listener')
        if remove_listener:
            remove_listener()
    
        @callback
        def report_device(event):
            # _LOGGER.debug("[skill] %s changed, try to report", event.data[ATTR_ENTITY_ID])
            self._hass.add_job(async_report_device(event))

        async def async_report_device(event):
            """report device state when changed. """
            entity = self._hass.states.get(event.data[ATTR_ENTITY_ID])
            if entity is None:
                return
            for platform, handler in self._hass.data[INTEGRATION][DATA_HAVCS_HANDLER].items():
                if hasattr(handler, 'report_device'):
                    device_ids = handler.vcdm.get_entity_related_device_ids(self._hass, entity.entity_id)
                    for device_id in device_ids:
                        payload = handler.report_device(device_id)
                        _LOGGER.debug("[skill] report device to %s: platform = %s, device_id = %s (entity_id = %s), data = %s", platform, device_id, event.data[ATTR_ENTITY_ID], platform, payload)
                        if payload:
                            url = HAVCS_SERVICE_URL + '/skill/'+platform+'.php?v=report&AppKey=' + self._sync_manager.get('app_key')
                            data = havcs_util.AESCipher(self._sync_manager.get('decrypt_key')).encrypt(json.dumps(payload, ensure_ascii = False).encode('utf8'))
                            try:
                                session = async_get_clientsession(self._hass, verify_ssl=False)
                                with async_timeout.timeout(5, loop=self._hass.loop):
                                    response = await session.post(url, data=data)
                                    _LOGGER.debug("[skill] get report device result from %s: %s", platform, await response.text())
                            except(asyncio.TimeoutError, aiohttp.ClientError):
                                _LOGGER.error("[skill] fail to access %s, report device fail: timeout", url)
                            except:
                                _LOGGER.error("[skill] fail to access %s, report device fail: %s", url, traceback.format_exc())
        
        self._sync_manager['remove_listener'] = self._hass.bus.async_listen(EVENT_STATE_CHANGED, report_device) 
开发者ID:cnk700i,项目名称:havcs,代码行数:37,代码来源:bind.py

示例2: async_setup_entry

# 需要导入模块: from homeassistant import const [as 别名]
# 或者: from homeassistant.const import ATTR_ENTITY_ID [as 别名]
def async_setup_entry(hass, config_entry, async_add_entities):
    """Add the Wiser System Switch entities."""
    data = hass.data[DOMAIN][config_entry.entry_id][DATA]  # Get Handler

    # Add System Switches
    wiser_switches = []
    for switch in WISER_SWITCHES:
        wiser_switches.append(
            WiserSwitch(data, switch["name"], switch["key"], switch["icon"])
        )

    async_add_entities(wiser_switches)

    # Add SmartPlugs (if any)
    if data.wiserhub.getSmartPlugs() is not None:
        wiser_smart_plugs = [
            WiserSmartPlug(data, plug.get("id"), "Wiser {}".format(plug.get("Name")))
            for plug in data.wiserhub.getSmartPlugs()
        ]
        async_add_entities(wiser_smart_plugs)

    @callback
    def set_smartplug_mode(service):
        entity_id = service.data[ATTR_ENTITY_ID]
        smart_plug_mode = service.data[ATTR_PLUG_MODE]

        _LOGGER.debug(
            "Set Smartplub called - entity %s mode %s ", entity_id, smart_plug_mode,
        )

        for smart_plug in wiser_smart_plugs:

            if smart_plug.entity_id == entity_id:
                hass.async_create_task(smart_plug.set_smartplug_mode(smart_plug_mode))
            smart_plug.schedule_update_ha_state(True)
            break

    @callback
    def set_hotwater_mode(service):
        hotwater_mode = service.data[ATTR_HOTWATER_MODE]
        hass.async_create_task(data.set_hotwater_mode(hotwater_mode))

    # Register Services
    hass.services.async_register(
        DOMAIN,
        WISER_SERVICES["SERVICE_SET_SMARTPLUG_MODE"],
        set_smartplug_mode,
        schema=SET_PLUG_MODE_SCHEMA,
    )
    hass.services.async_register(
        DOMAIN,
        WISER_SERVICES["SERVICE_SET_HOTWATER_MODE"],
        set_hotwater_mode,
        schema=SET_HOTWATER_MODE_SCHEMA,
    )
    return True 
开发者ID:asantaga,项目名称:wiserHomeAssistantPlatform,代码行数:58,代码来源:switch.py


注:本文中的homeassistant.const.ATTR_ENTITY_ID属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。