Skip to content

Commit

Permalink
Fix networkname retrieval for some wifi devices (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Feb 7, 2024
1 parent d122be4 commit 86d68cc
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86d68cc

Please sign in to comment.