async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the Zigbee Home Automation lights.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return endpoint = discovery_info['endpoint'] try: discovery_info['color_capabilities'] \ = await endpoint.light_color['color_capabilities'] except AttributeError as e: _LOGGER.debug("No color cluster: %s", e.args) except KeyError as e: _LOGGER.debug("Request for color_capabilities failed: %s", e.args) except Exception as e: _LOGGER.debug("Request for color_capabilities other error: %s", e.args) entity = Light(**discovery_info) if hass.states.get(entity.entity_id): _LOGGER.debug("entity exist,remove it: %s", dir(hass.states.get(entity.entity_id))) hass.states.async_remove(entity.entity_id) async_add_devices([entity]) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity) endpoint._device._application.listener_event('device_updated', endpoint._device)
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): from zigpy.zcl.clusters.security import IasZone """Set up the Zigbee Home Automation binary sensors.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) # _LOGGER.debug("disocery info: %s", discovery_info) if discovery_info is None: return in_clusters = discovery_info['in_clusters'] endpoint = discovery_info['endpoint'] device_class = None """ create ias cluster if it not already exists""" if IasZone.cluster_id not in in_clusters: cluster = endpoint.add_input_cluster(IasZone.cluster_id) in_clusters[IasZone.cluster_id] = cluster endpoint.in_clusters[IasZone.cluster_id] = cluster else: cluster = in_clusters[IasZone.cluster_id] await cluster.bind() if discovery_info['new_join']: try: ieee = cluster.endpoint.device.application.ieee await cluster.write_attributes({'cie_addr': ieee}) _LOGGER.debug("write cie done") except: _LOGGER.debug("bind/write cie failed") try: _LOGGER.debug("try zone read") zone_type = await cluster['zone_type'] _LOGGER.debug("done zone read") device_class = CLASS_MAPPING.get(zone_type, None) except Exception: # pylint: disable=broad-except pass entity = await _make_sensor(device_class, discovery_info) if hass.states.get(entity.entity_id): _LOGGER.debug("entity exist,remove it: %s", entity.entity_id) hass.states.async_remove(entity.entity_id) async_add_devices([entity], update_before_add=False) _LOGGER.debug("set Entity object: %s-%s ", type(entity), entity.unique_id) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity) endpoint._device._application.listener_event('device_updated', endpoint._device) _LOGGER.debug("Return binary_sensor init-cluster %s", endpoint.in_clusters)
async def async_setup_platform( hass, config, async_add_devices, discovery_info=None): from zigpy.zcl.clusters.security import IasZone """Set up Zigbee Home Automation sensors.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return endpoint = discovery_info['endpoint'] in_clusters = discovery_info['in_clusters'] application = discovery_info['application'] """ create ias cluster if it not already exists""" if IasZone.cluster_id not in in_clusters: cluster = endpoint.add_input_cluster(IasZone.cluster_id) in_clusters[IasZone.cluster_id] = cluster endpoint.in_clusters[IasZone.cluster_id] = cluster else: cluster = in_clusters[IasZone.cluster_id] if discovery_info['new_join']: try: await cluster.bind() ieee = cluster.endpoint.device.application.ieee await cluster.write_attributes({'cie_addr': ieee}) _LOGGER.debug("write cie done") except: _LOGGER.debug("bind/write cie failed") entity = await make_sensor(discovery_info) if discovery_info['new_join']: for CH in entity.sub_listener.values(): await CH.join_prepare() _LOGGER.debug("Create sensor.zha: %s", entity.entity_id) e_registry = await hass.helpers.entity_registry.async_get_registry() reg_dev_id = e_registry.async_get_or_create( DOMAIN, PLATFORM, entity.uid, suggested_object_id=entity.entity_id, device_id=str(entity.device._ieee) ) if entity.entity_id != reg_dev_id.entity_id and 'unknown' in reg_dev_id.entity_id: _LOGGER.debug("entity different name,change it: %s", reg_dev_id) e_registry.async_update_entity(reg_dev_id.entity_id, new_entity_id=entity.entity_id) if reg_dev_id.entity_id in application._entity_list: _LOGGER.debug("entity exist,remove it: %s", reg_dev_id) await application._entity_list.get(reg_dev_id.entity_id).async_remove() async_add_devices([entity]) endpoint._device._application.listener_event( 'device_updated', endpoint._device) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity)
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the Zigbee Home Automation lights.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return endpoint = discovery_info['endpoint'] in_clusters = discovery_info['in_clusters'] # try: # discovery_info['color_capabilities'] \ # = await endpoint.light_color['color_capabilities'] # except AttributeError as e: # _LOGGER.debug("No color cluster: %s", e.args) # except KeyError as e: # _LOGGER.debug("Request for color_capabilities failed: %s", e.args) # except Exception as e: # _LOGGER.debug("Request for color_capabilities other error: %s", e.args) # entity = Light(**discovery_info) if hasattr(endpoint, 'light_color'): caps = await zha_new.safe_read(endpoint.light_color, ['color_capabilities']) try: discovery_info['color_capabilities'] = caps.get( 'color_capabilities') except AttributeError: discovery_info['color_capabilities'] = CAPABILITIES_COLOR_XY try: result = await zha_new.safe_read(endpoint.light_color, ['color_temperature']) if result.get( 'color_temperature') is not UNSUPPORTED_ATTRIBUTE: discovery_info[ 'color_capabilities'] |= CAPABILITIES_COLOR_TEMP except AttributeError: pass entity = Light(**discovery_info) if hass.states.get(entity.entity_id): _LOGGER.debug("entity exist,remove it: %s", dir(hass.states.get(entity.entity_id))) hass.states.async_remove(entity.entity_id) async_add_devices([entity]) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity) await auto_set_attribute_report(endpoint, in_clusters) endpoint._device._application.listener_event('device_updated', endpoint._device)
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the Zigbee Home Automation lights.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return endpoint = discovery_info['endpoint'] try: discovery_info['color_capabilities'] \ = yield from endpoint.light_color['color_capabilities'] except (AttributeError, KeyError): pass async_add_devices([Light(**discovery_info)], update_before_add=True)
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up Zigbee Home Automation sensors.""" _LOGGER.debug("Enter sensor.zha: %s", discovery_info) discovery_info = zha_new.get_discovery_info(hass, discovery_info) endpoint = discovery_info['endpoint'] _LOGGER.debug("Enter sensor.zha: %s", discovery_info) if discovery_info is None: return sensor = yield from make_sensor(discovery_info) _LOGGER.debug("Create sensor.zha: %s", sensor.entity_id) async_add_devices([sensor]) endpoint._device._application.listener_event('device_updated', endpoint._device)
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the Zigbee Home Automation binary sensors.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) _LOGGER.debug("disocery info: %s", discovery_info) if discovery_info is None: return from bellows.zigbee.zcl.clusters.security import IasZone import bellows.zigbee.endpoint in_clusters = discovery_info['in_clusters'] endpoint = discovery_info['endpoint'] device_class = None """ create ias cluster if it not already exists""" if IasZone.cluster_id not in in_clusters: cluster = endpoint.add_input_cluster(IasZone.cluster_id) in_clusters[IasZone.cluster_id] = cluster endpoint.in_clusters[IasZone.cluster_id] = cluster else: cluster = in_clusters[IasZone.cluster_id] if discovery_info['new_join']: try: yield from cluster.bind() ieee = cluster.endpoint.device.application.ieee yield from cluster.write_attributes({'cie_addr': ieee}) _LOGGER.debug("write cie done") except: _LOGGER.debug("bind/write cie failed") try: _LOGGER.debug("try zone read") zone_type = yield from cluster['zone_type'] _LOGGER.debug("done zone read") device_class = CLASS_MAPPING.get(zone_type, None) except Exception: # pylint: disable=broad-except device_class = 'none' sensor = yield from _make_sensor(device_class, discovery_info) async_add_devices([sensor]) endpoint._device._application.listener_event('device_updated', endpoint._device) _LOGGER.debug("Return from binary_sensor init-cluster %s", endpoint.in_clusters)
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up Zigbee Home Automation switches.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return entity = Switch(**discovery_info) if hass.states.get(entity.entity_id): _LOGGER.debug("entity exist,remove it: %s", entity.entity_id) hass.states.async_remove(entity.entity_id) async_add_devices([entity]) endpoint = discovery_info['endpoint'] in_clusters = discovery_info['in_clusters'] await auto_set_attribute_report(endpoint, in_clusters) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity)
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up Zigbee Home Automation switches.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return application = discovery_info['application'] endpoint = discovery_info['endpoint'] in_clusters = discovery_info['in_clusters'] join = discovery_info['new_join'] entity = Switch(**discovery_info) if discovery_info['new_join']: for CH in entity.sub_listener.values(): await CH.join_prepare() e_registry = await hass.helpers.entity_registry.async_get_registry() reg_dev_id = e_registry.async_get_or_create( DOMAIN, PLATFORM, entity.uid, suggested_object_id=entity.entity_id, device_id=str(entity.device._ieee)) if entity.entity_id != reg_dev_id.entity_id and 'unknown' in reg_dev_id.entity_id: _LOGGER.debug("entity different name,change it: %s", reg_dev_id) e_registry.async_update_entity(reg_dev_id.entity_id, new_entity_id=entity.entity_id) if reg_dev_id.entity_id in application._entity_list: _LOGGER.debug("entity exist,remove it: %s", reg_dev_id) await application._entity_list.get(reg_dev_id.entity_id).async_remove() async_add_devices([entity]) if join: await auto_set_attribute_report(endpoint, in_clusters) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity)
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): from zigpy.zcl.clusters.security import IasZone """Set up Zigbee Home Automation sensors.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return endpoint = discovery_info['endpoint'] in_clusters = discovery_info['in_clusters'] """ create ias cluster if it not already exists""" if IasZone.cluster_id not in in_clusters: cluster = endpoint.add_input_cluster(IasZone.cluster_id) in_clusters[IasZone.cluster_id] = cluster endpoint.in_clusters[IasZone.cluster_id] = cluster else: cluster = in_clusters[IasZone.cluster_id] if discovery_info['new_join']: try: await cluster.bind() ieee = cluster.endpoint.device.application.ieee await cluster.write_attributes({'cie_addr': ieee}) _LOGGER.debug("write cie done") except: _LOGGER.debug("bind/write cie failed") entity = await make_sensor(discovery_info) _LOGGER.debug("Create sensor.zha: %s", entity.entity_id) if hass.states.get(entity.entity_id): _LOGGER.debug("entity exist,remove it: %s", entity.entity_id) hass.states.async_remove(entity.entity_id) async_add_devices([entity], update_before_add=False) endpoint._device._application.listener_event( 'device_updated', endpoint._device) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity)
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the Zigbee Home Automation binary sensors.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return in_clusters = discovery_info['in_clusters'] endpoint = discovery_info['endpoint'] application = discovery_info['application'] device_class = None # groups = None if discovery_info['new_join']: # if 0x1000 in endpoint.in_clusters: # try: # groups = await helpers.cluster_commisioning_groups( # endpoint.in_clusters[0x1000]) # except Exception as e: # _LOGGER.debug( # "catched exception in commissioning group_id %s", e) """ create ias cluster if it not already exists""" if IasZone.cluster_id not in in_clusters: cluster = endpoint.add_input_cluster(IasZone.cluster_id) in_clusters[IasZone.cluster_id] = cluster endpoint.in_clusters[IasZone.cluster_id] = cluster else: cluster = in_clusters[IasZone.cluster_id] await cluster.bind() try: ieee = cluster.endpoint.device.application.ieee result = await cluster.write_attributes({'cie_addr': ieee}) _LOGGER.debug("write cie:%s", result) except Exception: _LOGGER.debug("bind/write cie failed") else: if not result: try: await cluster.enroll_response(0, 0) except Exception: _LOGGER.debug("send enroll_command failed") try: _LOGGER.debug("try zone read") zone_type = await cluster['zone_type'] _LOGGER.debug("done zone read") device_class = CLASS_MAPPING.get(zone_type, None) except Exception: # pylint: disable=broad-except _LOGGER.debug("zone read failed") # discovery_info['groups'] = groups entity = await _make_sensor(device_class, discovery_info) # initialize/discover clusters if discovery_info['new_join']: for CH in entity.sub_listener.values(): await CH.join_prepare() e_registry = await hass.helpers.entity_registry.async_get_registry() reg_dev_id = e_registry.async_get_or_create( DOMAIN, PLATFORM, entity.uid, suggested_object_id=entity.entity_id, device_id=str(entity.device._ieee)) if entity.entity_id != reg_dev_id.entity_id and 'unknown' in reg_dev_id.entity_id: _LOGGER.debug("entity different name,change it: %s", reg_dev_id) e_registry.async_update_entity(reg_dev_id.entity_id, new_entity_id=entity.entity_id) if reg_dev_id.entity_id in application._entity_list: _LOGGER.debug("entity exist,remove it: %s", reg_dev_id) await application._entity_list.get(reg_dev_id.entity_id).async_remove() async_add_devices([entity]) _LOGGER.debug("set Entity object: %s-%s ", type(entity), entity.unique_id) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity) endpoint._device._application.listener_event('device_updated', endpoint._device) _LOGGER.debug("Return binary_sensor init-cluster %s", endpoint.in_clusters)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Zigbee Home Automation lights.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) if discovery_info is None: return application = discovery_info['application'] endpoint = discovery_info['endpoint'] in_clusters = discovery_info['in_clusters'] join = discovery_info['new_join'] component = hass.data[DOMAIN] # try: # discovery_info['color_capabilities'] \ # = await endpoint.light_color['color_capabilities'] # except AttributeError as e: # _LOGGER.debug("No color cluster: %s", e.args) # except KeyError as e: # _LOGGER.debug("Request for color_capabilities failed: %s", e.args) # except Exception as e: # _LOGGER.debug("Request for color_capabilities other error: %s", e.args) # entity = Light(**discovery_info) async def async_handle_step_up_ct_service(service): _LOGGER.debug('handle step up for %s: %s', service.data) component.async_register_entity_service( SERVICE_COLORTEMP_STEP_UP, SERVICE_SCHEMAS[SERVICE_COLORTEMP_STEP], 'async_handle_step_up_ct_service') component.async_register_entity_service( SERVICE_COLORTEMP_STEP_DOWN, SERVICE_SCHEMAS[SERVICE_COLORTEMP_STEP], 'async_handle_step_down_ct_service') if hasattr(discovery_info, 'multicast'): entity = MLight(**discovery_info) else: entity = Light(**discovery_info) if discovery_info['new_join']: for CH in entity.sub_listener.values(): await CH.join_prepare() e_registry = await hass.helpers.entity_registry.async_get_registry() reg_dev_id = e_registry.async_get_or_create( DOMAIN, PLATFORM, entity.uid, suggested_object_id=entity.entity_id, device_id=str(entity.device._ieee)) if entity.entity_id != reg_dev_id.entity_id and 'unknown' in reg_dev_id.entity_id: _LOGGER.debug("entity has different name,change it: %s", reg_dev_id) e_registry.async_update_entity(reg_dev_id.entity_id, new_entity_id=entity.entity_id) if reg_dev_id.entity_id in application._entity_list: _LOGGER.debug("entity exist,remove it: %s", reg_dev_id) await application._entity_list.get(reg_dev_id.entity_id).async_remove() async_add_entities([entity]) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity) if join: await auto_set_attribute_report(endpoint, in_clusters) endpoint._device._application.listener_event('device_updated', endpoint._device)
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the Zigbee Home Automation binary sensors.""" discovery_info = zha_new.get_discovery_info(hass, discovery_info) # _LOGGER.debug("disocery info: %s", discovery_info) if discovery_info is None: return in_clusters = discovery_info['in_clusters'] endpoint = discovery_info['endpoint'] device_class = None groups = list() if discovery_info['new_join']: if 0x1000 in endpoint.in_clusters: try: groups = await helpers.cluster_commisioning_groups( endpoint.in_clusters[0x1000], timeout=10) except Exception as e: _LOGGER.debug("catched exception in commissioning group_id %s", e) """ create ias cluster if it not already exists""" if IasZone.cluster_id not in in_clusters: cluster = endpoint.add_input_cluster(IasZone.cluster_id) in_clusters[IasZone.cluster_id] = cluster endpoint.in_clusters[IasZone.cluster_id] = cluster else: cluster = in_clusters[IasZone.cluster_id] await cluster.bind() try: ieee = cluster.endpoint.device.application.ieee result = await cluster.write_attributes({'cie_addr': ieee}) _LOGGER.debug("write cie:%s", result) except: _LOGGER.debug("bind/write cie failed") else: if not result: try: await cluster.enroll_response(0, 0) except: _LOGGER.debug("send enroll_command failed" ) # not sure if this is possible try: _LOGGER.debug("try zone read") zone_type = await cluster['zone_type'] _LOGGER.debug("done zone read") device_class = CLASS_MAPPING.get(zone_type, None) except Exception: # pylint: disable=broad-except _LOGGER.debug("zone read failed") discovery_info['groups'] = groups entity = await _make_sensor(device_class, discovery_info) if hass.states.get(entity.entity_id): _LOGGER.debug("entity exist,remove it: %s", entity.entity_id) hass.states.async_remove(entity.entity_id) async_add_devices([entity], update_before_add=False) _LOGGER.debug("set Entity object: %s-%s ", type(entity), entity.unique_id) entity_store = zha_new.get_entity_store(hass) if endpoint.device._ieee not in entity_store: entity_store[endpoint.device._ieee] = [] entity_store[endpoint.device._ieee].append(entity) endpoint._device._application.listener_event('device_updated', endpoint._device) _LOGGER.debug("Return binary_sensor init-cluster %s", endpoint.in_clusters)