Skip to content

Commit

Permalink
Add a default device name based on device type (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob authored Jun 14, 2022
1 parent 0dd0ad1 commit 66da56c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/matter_experimental/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from matter_server.client.adapter import AbstractMatterAdapter
from matter_server.common.json_utils import CHIPJSONDecoder, CHIPJSONEncoder
from matter_server.vendor import device_types
from matter_server.vendor.chip.clusters import Objects as all_clusters

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


class MatterAdapter(AbstractMatterAdapter):
"""Connect Matter into Home Assistant."""

def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
self.hass = hass
self.config_entry = config_entry
Expand Down Expand Up @@ -134,18 +137,22 @@ async def setup_node(self, node: MatterNode) -> None:

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

kwargs = {}
if basic_info.nodeLabel:
kwargs["name"] = basic_info.nodeLabel
name = basic_info.nodeLabel
if not name:
for device in node.devices:
if device.device_type is device_types.RootNode:
continue

name = device.device_type.__doc__[:-1]

dr.async_get(self.hass).async_get_or_create(
name=name,
config_entry_id=self.config_entry.entry_id,
identifiers={(DOMAIN, basic_info.uniqueID)},
hw_version=basic_info.hardwareVersionString,
sw_version=basic_info.softwareVersionString,
manufacturer=basic_info.vendorName,
model=basic_info.productName,
**kwargs,
)

for device in node.devices:
Expand Down

0 comments on commit 66da56c

Please sign in to comment.