def get_endpoint_cluster_attr_data(zha_device: ZHADevice) -> dict: """Return endpoint cluster attribute data.""" cluster_details = {} for ep_id, endpoint in zha_device.device.endpoints.items(): if ep_id == 0: continue endpoint_key = ( f"{PROFILES.get(endpoint.profile_id).DeviceType(endpoint.device_type).name}" if PROFILES.get(endpoint.profile_id) is not None and endpoint.device_type is not None else UNKNOWN ) cluster_details[ep_id] = { ATTR_DEVICE_TYPE: { CONF_NAME: endpoint_key, CONF_ID: endpoint.device_type, }, ATTR_PROFILE_ID: endpoint.profile_id, ATTR_IN_CLUSTERS: { f"0x{cluster_id:04x}": { "endpoint_attribute": cluster.ep_attribute, **get_cluster_attr_data(cluster), } for cluster_id, cluster in endpoint.in_clusters.items() }, ATTR_OUT_CLUSTERS: { f"0x{cluster_id:04x}": { "endpoint_attribute": cluster.ep_attribute, **get_cluster_attr_data(cluster), } for cluster_id, cluster in endpoint.out_clusters.items() }, } return cluster_details
def zha_device_info(self): """Get ZHA device information.""" device_info = {} device_info.update(self.device_info) device_info["entities"] = [{ "entity_id": entity_ref.reference_id, ATTR_NAME: entity_ref.device_info[ATTR_NAME], } for entity_ref in self.gateway.device_registry[self.ieee]] # Return the neighbor information device_info[ATTR_NEIGHBORS] = [{ "device_type": neighbor.neighbor.device_type.name, "rx_on_when_idle": neighbor.neighbor.rx_on_when_idle.name, "relationship": neighbor.neighbor.relationship.name, "extended_pan_id": str(neighbor.neighbor.extended_pan_id), "ieee": str(neighbor.neighbor.ieee), "nwk": str(neighbor.neighbor.nwk), "permit_joining": neighbor.neighbor.permit_joining.name, "depth": str(neighbor.neighbor.depth), "lqi": str(neighbor.neighbor.lqi), } for neighbor in self._zigpy_device.neighbors] # Return endpoint device type Names names = [] for endpoint in (ep for epid, ep in self.device.endpoints.items() if epid): profile = PROFILES.get(endpoint.profile_id) if profile and endpoint.device_type is not None: # DeviceType provides undefined enums names.append( {ATTR_NAME: profile.DeviceType(endpoint.device_type).name}) else: names.append({ ATTR_NAME: f"unknown {endpoint.device_type} device_type " "of 0x{endpoint.profile_id:04x} profile id" }) device_info[ATTR_ENDPOINT_NAMES] = names reg_device = self.gateway.ha_device_registry.async_get(self.device_id) if reg_device is not None: device_info["user_given_name"] = reg_device.name_by_user device_info["device_reg_id"] = reg_device.id device_info["area_id"] = reg_device.area_id return device_info