|
1 | 1 | """Matter Client implementation."""
|
| 2 | + |
2 | 3 | from __future__ import annotations
|
3 | 4 |
|
4 | 5 | import asyncio
|
|
9 | 10 |
|
10 | 11 | from aiohttp import ClientSession
|
11 | 12 | from chip.clusters import Objects as Clusters
|
| 13 | +from chip.clusters.Types import NullValue |
12 | 14 |
|
13 | 15 | from matter_server.common.errors import ERROR_MAP, NodeNotExists
|
14 | 16 |
|
@@ -257,6 +259,7 @@ async def ping_node(self, node_id: int) -> NodePingResult:
|
257 | 259 |
|
258 | 260 | async def node_diagnostics(self, node_id: int) -> NodeDiagnostics:
|
259 | 261 | """Gather diagnostics for the given node."""
|
| 262 | + # pylint: disable=too-many-statements |
260 | 263 | node = self.get_node(node_id)
|
261 | 264 | # grab some details from the first (operational) network interface
|
262 | 265 | network_type = NetworkType.UNKNOWN
|
@@ -306,7 +309,7 @@ async def node_diagnostics(self, node_id: int) -> NodeDiagnostics:
|
306 | 309 | )
|
307 | 310 | if isinstance(thread_cluster.networkName, bytes):
|
308 | 311 | network_name = thread_cluster.networkName.decode("utf-8")
|
309 |
| - else: |
| 312 | + elif thread_cluster.networkName != NullValue: |
310 | 313 | network_name = thread_cluster.networkName
|
311 | 314 | # parse routing role to (diagnostics) node type
|
312 | 315 | if (
|
@@ -336,10 +339,28 @@ async def node_diagnostics(self, node_id: int) -> NodeDiagnostics:
|
336 | 339 | attribute=Clusters.NetworkCommissioning.Attributes.LastNetworkID,
|
337 | 340 | )
|
338 | 341 | ):
|
| 342 | + node.get_cluster(0, Clusters.NetworkCommissioning) |
339 | 343 | if isinstance(last_network_id, bytes):
|
340 | 344 | network_name = last_network_id.decode("utf-8")
|
341 |
| - else: |
| 345 | + elif last_network_id != NullValue: |
342 | 346 | network_name = last_network_id
|
| 347 | + # last resort to get the (wifi) networkname; |
| 348 | + # enumerate networks on the NetworkCommissioning cluster |
| 349 | + networks: list[Clusters.NetworkCommissioning.Structs.NetworkInfoStruct] |
| 350 | + if not network_name and ( |
| 351 | + networks := node.get_attribute_value( |
| 352 | + 0, |
| 353 | + cluster=None, |
| 354 | + attribute=Clusters.NetworkCommissioning.Attributes.Networks, |
| 355 | + ) |
| 356 | + ): |
| 357 | + for network in networks: |
| 358 | + if isinstance(network.networkID, bytes): |
| 359 | + network_name = network.networkID.decode("utf-8") |
| 360 | + break |
| 361 | + if network.networkID != NullValue: |
| 362 | + network_name = network.networkID |
| 363 | + break |
343 | 364 | # override node type if node is a bridge
|
344 | 365 | if node.node_data.is_bridge:
|
345 | 366 | node_type = NodeType.BRIDGE
|
|
0 commit comments