diff --git a/matter_server/client/client.py b/matter_server/client/client.py index df71cebf..fed12e11 100644 --- a/matter_server/client/client.py +++ b/matter_server/client/client.py @@ -10,6 +10,7 @@ from aiohttp import ClientSession from chip.clusters import Objects as Clusters +from chip.clusters.Types import NullValue from matter_server.common.errors import ERROR_MAP, NodeNotExists @@ -258,6 +259,7 @@ async def ping_node(self, node_id: int) -> NodePingResult: async def node_diagnostics(self, node_id: int) -> NodeDiagnostics: """Gather diagnostics for the given node.""" + # pylint: disable=too-many-statements node = self.get_node(node_id) # grab some details from the first (operational) network interface network_type = NetworkType.UNKNOWN @@ -307,7 +309,7 @@ async def node_diagnostics(self, node_id: int) -> NodeDiagnostics: ) if isinstance(thread_cluster.networkName, bytes): network_name = thread_cluster.networkName.decode("utf-8") - else: + elif thread_cluster.networkName != NullValue: network_name = thread_cluster.networkName # parse routing role to (diagnostics) node type if ( @@ -339,8 +341,27 @@ async def node_diagnostics(self, node_id: int) -> NodeDiagnostics: ): if isinstance(last_network_id, bytes): network_name = last_network_id.decode("utf-8") - else: + elif last_network_id != NullValue: network_name = last_network_id + # last resort to get the (wifi) networkname; + # enumerate networks on the NetworkCommissioning cluster + networks: list[Clusters.NetworkCommissioning.Structs.NetworkInfoStruct] + if not network_name and ( + networks := node.get_attribute_value( + 0, + cluster=None, + attribute=Clusters.NetworkCommissioning.Attributes.Networks, + ) + ): + for network in networks: + if not network.connected: + continue + if isinstance(network.networkID, bytes): + network_name = network.networkID.decode("utf-8") + break + if network.networkID != NullValue: + network_name = network.networkID + break # override node type if node is a bridge if node.node_data.is_bridge: node_type = NodeType.BRIDGE