Skip to content

Commit

Permalink
Improve Thread network diagnostics parsing (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners committed Jun 3, 2024
1 parent a8acb7a commit cb5ee76
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,28 +357,28 @@ async def node_diagnostics(self, node_id: int) -> NodeDiagnostics:
thread_cluster: Clusters.ThreadNetworkDiagnostics = node.get_cluster(
0, Clusters.ThreadNetworkDiagnostics
)
if isinstance(thread_cluster.networkName, bytes):
network_name = thread_cluster.networkName.decode(
"utf-8", errors="replace"
)
elif thread_cluster.networkName != NullValue:
network_name = thread_cluster.networkName
# parse routing role to (diagnostics) node type
if (
thread_cluster.routingRole
== Clusters.ThreadNetworkDiagnostics.Enums.RoutingRoleEnum.kSleepyEndDevice
):
node_type = NodeType.SLEEPY_END_DEVICE
if thread_cluster.routingRole in (
Clusters.ThreadNetworkDiagnostics.Enums.RoutingRoleEnum.kLeader,
Clusters.ThreadNetworkDiagnostics.Enums.RoutingRoleEnum.kRouter,
):
node_type = NodeType.ROUTING_END_DEVICE
elif (
thread_cluster.routingRole
== Clusters.ThreadNetworkDiagnostics.Enums.RoutingRoleEnum.kEndDevice
):
node_type = NodeType.END_DEVICE
if thread_cluster:
if isinstance(thread_cluster.networkName, bytes):
network_name = thread_cluster.networkName.decode(
"utf-8", errors="replace"
)
elif thread_cluster.networkName != NullValue:
network_name = thread_cluster.networkName

# parse routing role to (diagnostics) node type
RoutingRole = Clusters.ThreadNetworkDiagnostics.Enums.RoutingRoleEnum # noqa: N806
if thread_cluster.routingRole == RoutingRole.kSleepyEndDevice:
node_type = NodeType.SLEEPY_END_DEVICE
elif thread_cluster.routingRole in (
RoutingRole.kLeader,
RoutingRole.kRouter,
):
node_type = NodeType.ROUTING_END_DEVICE
elif thread_cluster.routingRole in (
RoutingRole.kEndDevice,
RoutingRole.kReed,
):
node_type = NodeType.END_DEVICE
elif network_type == NetworkType.WIFI:
node_type = NodeType.END_DEVICE
# use lastNetworkID from NetworkCommissioning cluster as fallback to get the network name
Expand Down

0 comments on commit cb5ee76

Please sign in to comment.