Skip to content

Commit 1049301

Browse files
authored
Better names (#10)
* Better names * Add fabric ID to unique ID * isort
1 parent 17051a6 commit 1049301

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

custom_components/matter_experimental/adapter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ async def setup_node(self, node: MatterNode) -> None:
143143
if device.device_type is device_types.RootNode:
144144
continue
145145

146-
name = device.device_type.__doc__[:-1]
146+
name = f"{device.device_type.__doc__[:-1]} {node.node_id}"
147+
break
147148

148149
dr.async_get(self.hass).async_get_or_create(
149150
name=name,

custom_components/matter_experimental/entity.py

+23-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import async_timeout
88
from homeassistant.core import callback
9-
from homeassistant.helpers import entity
9+
from homeassistant.helpers import device_registry, entity
1010

1111
from matter_server.client.model.device import MatterDevice
1212

@@ -22,23 +22,7 @@ class MatterEntity(entity.Entity):
2222
def __init__(self, device: MatterDevice, mapping: DeviceMapping) -> None:
2323
self._device = device
2424
self._device_mapping = mapping
25-
self._attr_unique_id = f"{device.node.unique_id}-{device.endpoint_id}-{device.device_type.device_type}"
26-
27-
device_type_name = device.device_type.__doc__[:-1]
28-
name = device.node.name
29-
if name:
30-
name += f" {device_type_name}"
31-
else:
32-
name = f"{device_type_name} {device.node.node_id}"
33-
34-
# If this device has multiple of this device type, add their endpoint.
35-
if (
36-
sum(dev.device_type is device.device_type for dev in device.node.devices)
37-
> 1
38-
):
39-
name += f" ({device.endpoint_id})"
40-
41-
self._attr_name = name
25+
self._attr_unique_id = f"{device.node.matter.client.server_info.compressedFabricId}-{device.node.unique_id}-{device.endpoint_id}-{device.device_type.device_type}"
4226

4327
@property
4428
def device_info(self) -> entity.DeviceInfo | None:
@@ -49,6 +33,27 @@ async def async_added_to_hass(self) -> None:
4933
"""Handle being added to Home Assistant."""
5034
await super().async_added_to_hass()
5135

36+
device_name = (
37+
device_registry.async_get(self.hass)
38+
.async_get(self.registry_entry.device_id)
39+
.name
40+
)
41+
42+
device_type_name = self._device.device_type.__doc__[:-1]
43+
name = f"{device_name} {device_type_name}"
44+
45+
# If this device has multiple of this device type, add their endpoint.
46+
if (
47+
sum(
48+
dev.device_type is self._device.device_type
49+
for dev in self._device.node.devices
50+
)
51+
> 1
52+
):
53+
name += f" ({self._device.endpoint_id})"
54+
55+
self._attr_name = name
56+
5257
if not self._device_mapping.subscribe_attributes:
5358
self._update_from_device()
5459
return

0 commit comments

Comments
 (0)