Fix support for Bridge(d) and composed devices in Matter (#88662)
* Refactor discovery of entities to support composed and bridged devices * Bump library version to 3.1.0 * move discovery schemas to platforms * optimize a tiny bit * simplify even more * fixed bug in light platform * fix color control logic * fix some issues * Update homeassistant/components/matter/discovery.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * fix some tests * fix light test --------- Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
e0601530a0
commit
301144993c
18 changed files with 582 additions and 526 deletions
|
@ -11,8 +11,7 @@ from homeassistant.helpers import device_registry as dr
|
|||
from .const import DOMAIN, ID_TYPE_DEVICE_ID
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from matter_server.client.models.node import MatterNode
|
||||
from matter_server.client.models.node_device import AbstractMatterNodeDevice
|
||||
from matter_server.client.models.node import MatterEndpoint, MatterNode
|
||||
from matter_server.common.models import ServerInfoMessage
|
||||
|
||||
from .adapter import MatterAdapter
|
||||
|
@ -50,15 +49,21 @@ def get_operational_instance_id(
|
|||
|
||||
def get_device_id(
|
||||
server_info: ServerInfoMessage,
|
||||
node_device: AbstractMatterNodeDevice,
|
||||
endpoint: MatterEndpoint,
|
||||
) -> str:
|
||||
"""Return HA device_id for the given MatterNodeDevice."""
|
||||
operational_instance_id = get_operational_instance_id(
|
||||
server_info, node_device.node()
|
||||
)
|
||||
# Append nodedevice(type) to differentiate between a root node
|
||||
# and bridge within Home Assistant devices.
|
||||
return f"{operational_instance_id}-{node_device.__class__.__name__}"
|
||||
"""Return HA device_id for the given MatterEndpoint."""
|
||||
operational_instance_id = get_operational_instance_id(server_info, endpoint.node)
|
||||
# Append endpoint ID if this endpoint is a bridged or composed device
|
||||
if endpoint.is_composed_device:
|
||||
compose_parent = endpoint.node.get_compose_parent(endpoint.endpoint_id)
|
||||
assert compose_parent is not None
|
||||
postfix = str(compose_parent.endpoint_id)
|
||||
elif endpoint.is_bridged_device:
|
||||
postfix = str(endpoint.endpoint_id)
|
||||
else:
|
||||
# this should be compatible with previous versions
|
||||
postfix = "MatterNodeDevice"
|
||||
return f"{operational_instance_id}-{postfix}"
|
||||
|
||||
|
||||
async def get_node_from_device_entry(
|
||||
|
@ -91,8 +96,8 @@ async def get_node_from_device_entry(
|
|||
(
|
||||
node
|
||||
for node in await matter_client.get_nodes()
|
||||
for node_device in node.node_devices
|
||||
if get_device_id(server_info, node_device) == device_id
|
||||
for endpoint in node.endpoints.values()
|
||||
if get_device_id(server_info, endpoint) == device_id
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue