Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a default device name based on device type #6

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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