def async_device_initialized(self, device, join): """Handle device joined and basic information discovered (async).""" import zigpy.profiles import homeassistant.components.zha.const as zha_const zha_const.populate_data() for endpoint_id, endpoint in device.endpoints.items(): if endpoint_id == 0: # ZDO continue discovered_info = yield from _discover_endpoint_info(endpoint) component = None profile_clusters = ([], []) device_key = "{}-{}".format(device.ieee, endpoint_id) node_config = self._config[DOMAIN][CONF_DEVICE_CONFIG].get( device_key, {}) if endpoint.profile_id in zigpy.profiles.PROFILES: profile = zigpy.profiles.PROFILES[endpoint.profile_id] if zha_const.DEVICE_CLASS.get(endpoint.profile_id, {}).get(endpoint.device_type, None): profile_clusters = profile.CLUSTERS[endpoint.device_type] profile_info = zha_const.DEVICE_CLASS[endpoint.profile_id] component = profile_info[endpoint.device_type] if ha_const.CONF_TYPE in node_config: component = node_config[ha_const.CONF_TYPE] profile_clusters = zha_const.COMPONENT_CLUSTERS[component] if component: in_clusters = [endpoint.in_clusters[c] for c in profile_clusters[0] if c in endpoint.in_clusters] out_clusters = [endpoint.out_clusters[c] for c in profile_clusters[1] if c in endpoint.out_clusters] discovery_info = { 'application_listener': self, 'endpoint': endpoint, 'in_clusters': {c.cluster_id: c for c in in_clusters}, 'out_clusters': {c.cluster_id: c for c in out_clusters}, 'new_join': join, 'unique_id': device_key, } discovery_info.update(discovered_info) self._hass.data[DISCOVERY_KEY][device_key] = discovery_info yield from discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': device_key}, self._config, ) for cluster_id, cluster in endpoint.in_clusters.items(): cluster_type = type(cluster) if cluster_id in profile_clusters[0]: continue if cluster_type not in zha_const.SINGLE_CLUSTER_DEVICE_CLASS: continue component = zha_const.SINGLE_CLUSTER_DEVICE_CLASS[cluster_type] cluster_key = "{}-{}".format(device_key, cluster_id) discovery_info = { 'application_listener': self, 'endpoint': endpoint, 'in_clusters': {cluster.cluster_id: cluster}, 'out_clusters': {}, 'new_join': join, 'unique_id': cluster_key, 'entity_suffix': '_{}'.format(cluster_id), } discovery_info.update(discovered_info) self._hass.data[DISCOVERY_KEY][cluster_key] = discovery_info yield from discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': cluster_key}, self._config, )
async def async_device_initialized(self, device, join): """Handle device joined and basic information discovered (async).""" import zigpy.profiles import homeassistant.components.zha.const as zha_const zha_const.populate_data() for endpoint_id, endpoint in device.endpoints.items(): if endpoint_id == 0: # ZDO continue discovered_info = await _discover_endpoint_info(endpoint) component = None profile_clusters = ([], []) device_key = "{}-{}".format(device.ieee, endpoint_id) node_config = self._config[DOMAIN][CONF_DEVICE_CONFIG].get( device_key, {}) if endpoint.profile_id in zigpy.profiles.PROFILES: profile = zigpy.profiles.PROFILES[endpoint.profile_id] if zha_const.DEVICE_CLASS.get(endpoint.profile_id, {}).get(endpoint.device_type, None): profile_clusters = profile.CLUSTERS[endpoint.device_type] profile_info = zha_const.DEVICE_CLASS[endpoint.profile_id] component = profile_info[endpoint.device_type] if ha_const.CONF_TYPE in node_config: component = node_config[ha_const.CONF_TYPE] profile_clusters = zha_const.COMPONENT_CLUSTERS[component] if component: in_clusters = [ endpoint.in_clusters[c] for c in profile_clusters[0] if c in endpoint.in_clusters ] out_clusters = [ endpoint.out_clusters[c] for c in profile_clusters[1] if c in endpoint.out_clusters ] discovery_info = { 'application_listener': self, 'endpoint': endpoint, 'in_clusters': {c.cluster_id: c for c in in_clusters}, 'out_clusters': {c.cluster_id: c for c in out_clusters}, 'new_join': join, 'unique_id': device_key, } discovery_info.update(discovered_info) self._hass.data[DISCOVERY_KEY][device_key] = discovery_info await discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': device_key}, self._config, ) for cluster in endpoint.in_clusters.values(): await self._attempt_single_cluster_device( endpoint, cluster, profile_clusters[0], device_key, zha_const.SINGLE_INPUT_CLUSTER_DEVICE_CLASS, 'in_clusters', discovered_info, join, ) for cluster in endpoint.out_clusters.values(): await self._attempt_single_cluster_device( endpoint, cluster, profile_clusters[1], device_key, zha_const.SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS, 'out_clusters', discovered_info, join, )
def async_device_initialized(self, device, join): """Handle device joined and basic information discovered (async).""" import bellows.zigbee.profiles import homeassistant.components.zha.const as zha_const zha_const.populate_data() for endpoint_id, endpoint in device.endpoints.items(): if endpoint_id == 0: # ZDO continue discovered_info = yield from _discover_endpoint_info(endpoint) component = None profile_clusters = ([], []) device_key = '%s-%s' % (str(device.ieee), endpoint_id) node_config = self._config[DOMAIN][CONF_DEVICE_CONFIG].get( device_key, {}) if endpoint.profile_id in bellows.zigbee.profiles.PROFILES: profile = bellows.zigbee.profiles.PROFILES[endpoint.profile_id] if zha_const.DEVICE_CLASS.get(endpoint.profile_id, {}).get(endpoint.device_type, None): profile_clusters = profile.CLUSTERS[endpoint.device_type] profile_info = zha_const.DEVICE_CLASS[endpoint.profile_id] component = profile_info[endpoint.device_type] if ha_const.CONF_TYPE in node_config: component = node_config[ha_const.CONF_TYPE] profile_clusters = zha_const.COMPONENT_CLUSTERS[component] if component: in_clusters = [ endpoint.in_clusters[c] for c in profile_clusters[0] if c in endpoint.in_clusters ] out_clusters = [ endpoint.out_clusters[c] for c in profile_clusters[1] if c in endpoint.out_clusters ] discovery_info = { 'endpoint': endpoint, 'in_clusters': {c.cluster_id: c for c in in_clusters}, 'out_clusters': {c.cluster_id: c for c in out_clusters}, 'new_join': join, } discovery_info.update(discovered_info) self._hass.data[DISCOVERY_KEY][device_key] = discovery_info yield from discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': device_key}, self._config, ) for cluster_id, cluster in endpoint.in_clusters.items(): cluster_type = type(cluster) if cluster_id in profile_clusters[0]: continue if cluster_type not in zha_const.SINGLE_CLUSTER_DEVICE_CLASS: continue component = zha_const.SINGLE_CLUSTER_DEVICE_CLASS[cluster_type] discovery_info = { 'endpoint': endpoint, 'in_clusters': { cluster.cluster_id: cluster }, 'out_clusters': {}, 'new_join': join, } discovery_info.update(discovered_info) cluster_key = '%s-%s' % (device_key, cluster_id) self._hass.data[DISCOVERY_KEY][cluster_key] = discovery_info yield from discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': cluster_key}, self._config, )
async def async_device_initialized(self, device, join): """Handle device joined and basic information discovered (async).""" import zigpy.profiles import homeassistant.components.zha.const as zha_const zha_const.populate_data() device_manufacturer = device_model = None for endpoint_id, endpoint in device.endpoints.items(): if endpoint_id == 0: # ZDO continue if endpoint.manufacturer is not None: device_manufacturer = endpoint.manufacturer if endpoint.model is not None: device_model = endpoint.model component = None profile_clusters = ([], []) device_key = "{}-{}".format(device.ieee, endpoint_id) node_config = self._config[DOMAIN][CONF_DEVICE_CONFIG].get( device_key, {}) if endpoint.profile_id in zigpy.profiles.PROFILES: profile = zigpy.profiles.PROFILES[endpoint.profile_id] if zha_const.DEVICE_CLASS.get(endpoint.profile_id, {}).get(endpoint.device_type, None): profile_clusters = profile.CLUSTERS[endpoint.device_type] profile_info = zha_const.DEVICE_CLASS[endpoint.profile_id] component = profile_info[endpoint.device_type] if ha_const.CONF_TYPE in node_config: component = node_config[ha_const.CONF_TYPE] profile_clusters = zha_const.COMPONENT_CLUSTERS[component] if component: in_clusters = [endpoint.in_clusters[c] for c in profile_clusters[0] if c in endpoint.in_clusters] out_clusters = [endpoint.out_clusters[c] for c in profile_clusters[1] if c in endpoint.out_clusters] discovery_info = { 'application_listener': self, 'endpoint': endpoint, 'in_clusters': {c.cluster_id: c for c in in_clusters}, 'out_clusters': {c.cluster_id: c for c in out_clusters}, 'manufacturer': endpoint.manufacturer, 'model': endpoint.model, 'new_join': join, 'unique_id': device_key, } self._hass.data[DISCOVERY_KEY][device_key] = discovery_info await discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': device_key}, self._config, ) for cluster in endpoint.in_clusters.values(): await self._attempt_single_cluster_device( endpoint, cluster, profile_clusters[0], device_key, zha_const.SINGLE_INPUT_CLUSTER_DEVICE_CLASS, 'in_clusters', join, ) for cluster in endpoint.out_clusters.values(): await self._attempt_single_cluster_device( endpoint, cluster, profile_clusters[1], device_key, zha_const.SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS, 'out_clusters', join, ) endpoint_entity = ZhaDeviceEntity( device, device_manufacturer, device_model, self, ) await self._component.async_add_entities([endpoint_entity])
def async_device_initialized(self, device, join): """Handle device joined and basic information discovered (async).""" import bellows.zigbee.profiles import homeassistant.components.zha.const as zha_const zha_const.populate_data() for endpoint_id, endpoint in device.endpoints.items(): if endpoint_id == 0: # ZDO continue discovered_info = yield from _discover_endpoint_info(endpoint) component = None used_clusters = [] device_key = '%s-%s' % (str(device.ieee), endpoint_id) node_config = self._config[DOMAIN][CONF_DEVICE_CONFIG].get( device_key, {}) if endpoint.profile_id in bellows.zigbee.profiles.PROFILES: profile = bellows.zigbee.profiles.PROFILES[endpoint.profile_id] if zha_const.DEVICE_CLASS.get(endpoint.profile_id, {}).get(endpoint.device_type, None): used_clusters = profile.CLUSTERS[endpoint.device_type] profile_info = zha_const.DEVICE_CLASS[endpoint.profile_id] component = profile_info[endpoint.device_type] if ha_const.CONF_TYPE in node_config: component = node_config[ha_const.CONF_TYPE] used_clusters = zha_const.COMPONENT_CLUSTERS[component] if component: clusters = [endpoint.clusters[c] for c in used_clusters if c in endpoint.clusters] discovery_info = { 'endpoint': endpoint, 'clusters': clusters, 'new_join': join, } discovery_info.update(discovered_info) self._hass.data[DISCOVERY_KEY][device_key] = discovery_info yield from discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': device_key}, self._config, ) for cluster_id, cluster in endpoint.clusters.items(): cluster_type = type(cluster) if cluster_id in used_clusters: continue if cluster_type not in zha_const.SINGLE_CLUSTER_DEVICE_CLASS: continue component = zha_const.SINGLE_CLUSTER_DEVICE_CLASS[cluster_type] discovery_info = { 'endpoint': endpoint, 'clusters': [cluster], 'new_join': join, } discovery_info.update(discovered_info) cluster_key = '%s-%s' % (device_key, cluster_id) self._hass.data[DISCOVERY_KEY][cluster_key] = discovery_info yield from discovery.async_load_platform( self._hass, component, DOMAIN, {'discovery_key': cluster_key}, self._config, )