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

Fix networkname retrieval for some wifi devices #535

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Changes from 2 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
24 changes: 22 additions & 2 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Matter Client implementation."""

from __future__ import annotations

import asyncio
Expand All @@ -9,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 @@ -257,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 @@ -306,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 @@ -338,8 +341,25 @@ 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 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
Loading