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