Skip to content

Commit 66da56c

Browse files
authored
Add a default device name based on device type (#6)
1 parent 0dd0ad1 commit 66da56c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

custom_components/matter_experimental/adapter.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from matter_server.client.adapter import AbstractMatterAdapter
2121
from matter_server.common.json_utils import CHIPJSONDecoder, CHIPJSONEncoder
22+
from matter_server.vendor import device_types
2223
from matter_server.vendor.chip.clusters import Objects as all_clusters
2324

2425
from .const import DOMAIN
@@ -91,6 +92,8 @@ def get_matter_store(hass: HomeAssistant, config_entry: ConfigEntry) -> MatterSt
9192

9293

9394
class MatterAdapter(AbstractMatterAdapter):
95+
"""Connect Matter into Home Assistant."""
96+
9497
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
9598
self.hass = hass
9699
self.config_entry = config_entry
@@ -134,18 +137,22 @@ async def setup_node(self, node: MatterNode) -> None:
134137

135138
basic_info = node.root_device.get_cluster(all_clusters.Basic)
136139

137-
kwargs = {}
138-
if basic_info.nodeLabel:
139-
kwargs["name"] = basic_info.nodeLabel
140+
name = basic_info.nodeLabel
141+
if not name:
142+
for device in node.devices:
143+
if device.device_type is device_types.RootNode:
144+
continue
145+
146+
name = device.device_type.__doc__[:-1]
140147

141148
dr.async_get(self.hass).async_get_or_create(
149+
name=name,
142150
config_entry_id=self.config_entry.entry_id,
143151
identifiers={(DOMAIN, basic_info.uniqueID)},
144152
hw_version=basic_info.hardwareVersionString,
145153
sw_version=basic_info.softwareVersionString,
146154
manufacturer=basic_info.vendorName,
147155
model=basic_info.productName,
148-
**kwargs,
149156
)
150157

151158
for device in node.devices:

0 commit comments

Comments
 (0)