Skip to content

Commit debc1f7

Browse files
authored
Add zigbee information to ZHA device information (#33612)
* add zigbee signature to zha device info * add typing * use props and sort clusters * review comment
1 parent 05192b7 commit debc1f7

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

homeassistant/components/zha/core/channels/__init__.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Channels module for Zigbee Home Automation."""
22
import asyncio
33
import logging
4-
from typing import Any, Dict, List, Optional, Union
4+
from typing import Any, Dict, List, Optional, Tuple, Union
55

66
from homeassistant.core import callback
77
from homeassistant.helpers.dispatcher import async_dispatcher_send
@@ -92,6 +92,14 @@ def unique_id(self):
9292
"""Return the unique id for this channel."""
9393
return self._unique_id
9494

95+
@property
96+
def zigbee_signature(self) -> Dict[int, Dict[str, Any]]:
97+
"""Get the zigbee signatures for the pools in channels."""
98+
return {
99+
signature[0]: signature[1]
100+
for signature in [pool.zigbee_signature for pool in self.pools]
101+
}
102+
95103
@classmethod
96104
def new(cls, zha_device: zha_typing.ZhaDeviceType) -> "Channels":
97105
"""Create new instance."""
@@ -231,6 +239,27 @@ def unique_id(self):
231239
"""Return the unique id for this channel."""
232240
return self._unique_id
233241

242+
@property
243+
def zigbee_signature(self) -> Tuple[int, Dict[str, Any]]:
244+
"""Get the zigbee signature for the endpoint this pool represents."""
245+
return (
246+
self.endpoint.endpoint_id,
247+
{
248+
const.ATTR_PROFILE_ID: self.endpoint.profile_id,
249+
const.ATTR_DEVICE_TYPE: f"0x{self.endpoint.device_type:04x}"
250+
if self.endpoint.device_type is not None
251+
else "",
252+
const.ATTR_IN_CLUSTERS: [
253+
f"0x{cluster_id:04x}"
254+
for cluster_id in sorted(self.endpoint.in_clusters)
255+
],
256+
const.ATTR_OUT_CLUSTERS: [
257+
f"0x{cluster_id:04x}"
258+
for cluster_id in sorted(self.endpoint.out_clusters)
259+
],
260+
},
261+
)
262+
234263
@classmethod
235264
def new(cls, channels: Channels, ep_id: int) -> "ChannelPool":
236265
"""Create new channels for an endpoint."""

homeassistant/components/zha/core/const.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
ATTR_COMMAND_TYPE = "command_type"
2323
ATTR_DEVICE_IEEE = "device_ieee"
2424
ATTR_DEVICE_TYPE = "device_type"
25+
ATTR_ENDPOINTS = "endpoints"
2526
ATTR_ENDPOINT_ID = "endpoint_id"
2627
ATTR_IEEE = "ieee"
28+
ATTR_IN_CLUSTERS = "in_clusters"
2729
ATTR_LAST_SEEN = "last_seen"
2830
ATTR_LEVEL = "level"
2931
ATTR_LQI = "lqi"
@@ -32,8 +34,11 @@
3234
ATTR_MEMBERS = "members"
3335
ATTR_MODEL = "model"
3436
ATTR_NAME = "name"
37+
ATTR_NODE_DESCRIPTOR = "node_descriptor"
3538
ATTR_NWK = "nwk"
39+
ATTR_OUT_CLUSTERS = "out_clusters"
3640
ATTR_POWER_SOURCE = "power_source"
41+
ATTR_PROFILE_ID = "profile_id"
3742
ATTR_QUIRK_APPLIED = "quirk_applied"
3843
ATTR_QUIRK_CLASS = "quirk_class"
3944
ATTR_RSSI = "rssi"

homeassistant/components/zha/core/device.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import random
77
import time
8+
from typing import Any, Dict
89

910
from zigpy import types
1011
import zigpy.exceptions
@@ -31,18 +32,21 @@
3132
ATTR_COMMAND_TYPE,
3233
ATTR_DEVICE_TYPE,
3334
ATTR_ENDPOINT_ID,
35+
ATTR_ENDPOINTS,
3436
ATTR_IEEE,
3537
ATTR_LAST_SEEN,
3638
ATTR_LQI,
3739
ATTR_MANUFACTURER,
3840
ATTR_MANUFACTURER_CODE,
3941
ATTR_MODEL,
4042
ATTR_NAME,
43+
ATTR_NODE_DESCRIPTOR,
4144
ATTR_NWK,
4245
ATTR_POWER_SOURCE,
4346
ATTR_QUIRK_APPLIED,
4447
ATTR_QUIRK_CLASS,
4548
ATTR_RSSI,
49+
ATTR_SIGNATURE,
4650
ATTR_VALUE,
4751
CLUSTER_COMMAND_SERVER,
4852
CLUSTER_COMMANDS_CLIENT,
@@ -267,6 +271,14 @@ def available(self):
267271
"""Return True if sensor is available."""
268272
return self._available
269273

274+
@property
275+
def zigbee_signature(self) -> Dict[str, Any]:
276+
"""Get zigbee signature for this device."""
277+
return {
278+
ATTR_NODE_DESCRIPTOR: str(self._zigpy_device.node_desc),
279+
ATTR_ENDPOINTS: self._channels.zigbee_signature,
280+
}
281+
270282
def set_available(self, available):
271283
"""Set availability from restore and prevent signals."""
272284
self._available = available
@@ -366,6 +378,7 @@ def device_info(self):
366378
ATTR_LAST_SEEN: update_time,
367379
ATTR_AVAILABLE: self.available,
368380
ATTR_DEVICE_TYPE: self.device_type,
381+
ATTR_SIGNATURE: self.zigbee_signature,
369382
}
370383

371384
async def async_configure(self):

0 commit comments

Comments
 (0)