10
10
from aiohttp import ClientSession
11
11
from chip .clusters import Objects as Clusters
12
12
13
- from matter_server .common .errors import ERROR_MAP , MatterError , NodeNotExists
13
+ from matter_server .common .errors import ERROR_MAP , NodeNotExists
14
14
15
15
from ..common .helpers .util import (
16
- convert_hex_string ,
16
+ convert_ip_address ,
17
17
convert_mac_address ,
18
- create_attribute_path_from_attribute ,
19
18
dataclass_from_dict ,
20
19
dataclass_to_dict ,
21
20
)
51
50
52
51
SUB_WILDCARD : Final = "*"
53
52
54
- # pylint: disable=too-many-public-methods
53
+ # pylint: disable=too-many-public-methods,too-many-locals,too-many-branches
55
54
56
55
57
56
class MatterClient :
@@ -216,17 +215,6 @@ async def get_matter_fabrics(self, node_id: int) -> list[MatterFabricData]:
216
215
"""
217
216
218
217
node = self .get_node (node_id )
219
- if node .available :
220
- # try to refresh the OperationalCredentials.Fabric attribute
221
- # so we have the most accurate information
222
- attr_path = create_attribute_path_from_attribute (
223
- 0 , Clusters .OperationalCredentials .Attributes .Fabrics
224
- )
225
- try :
226
- await self .refresh_attribute (node_id , attr_path )
227
- except MatterError as err :
228
- self .logger .exception (err )
229
-
230
218
fabrics : list [
231
219
Clusters .OperationalCredentials .Structs .FabricDescriptorStruct
232
220
] = node .get_attribute_value (
@@ -270,13 +258,12 @@ async def ping_node(self, node_id: int) -> NodePingResult:
270
258
async def node_diagnostics (self , node_id : int ) -> NodeDiagnostics :
271
259
"""Gather diagnostics for the given node."""
272
260
node = self .get_node (node_id )
273
- # ping the node (will also refresh NetworkInterfaces data)
274
- ping_result = await self .ping_node (node_id )
275
261
# grab some details from the first (operational) network interface
276
262
network_type = NetworkType .UNKNOWN
277
263
mac_address = None
278
264
attribute = Clusters .GeneralDiagnostics .Attributes .NetworkInterfaces
279
265
network_interface : Clusters .GeneralDiagnostics .Structs .NetworkInterface
266
+ ip_addresses : list [str ] = []
280
267
for network_interface in node .get_attribute_value (
281
268
0 , cluster = None , attribute = attribute
282
269
):
@@ -302,38 +289,44 @@ async def node_diagnostics(self, node_id: int) -> NodeDiagnostics:
302
289
# unknown interface: ignore
303
290
continue
304
291
mac_address = convert_mac_address (network_interface .hardwareAddress )
292
+ # enumerate ipv4 and ipv6 addresses
293
+ for ipv4_address_hex in network_interface .IPv4Addresses :
294
+ ipv4_address = convert_ip_address (ipv4_address_hex )
295
+ ip_addresses .append (ipv4_address )
296
+ for ipv6_address_hex in network_interface .IPv6Addresses :
297
+ ipv6_address = convert_ip_address (ipv6_address_hex , True )
298
+ ip_addresses .append (ipv6_address )
305
299
break
306
300
# get thread/wifi specific info
307
301
node_type = NodeType .UNKNOWN
308
302
network_name = None
309
303
if network_type == NetworkType .THREAD :
310
- cluster : Clusters .ThreadNetworkDiagnostics = node .get_cluster (
304
+ thread_cluster : Clusters .ThreadNetworkDiagnostics = node .get_cluster (
311
305
0 , Clusters .ThreadNetworkDiagnostics
312
306
)
313
- network_name = convert_hex_string ( cluster .networkName )
307
+ network_name = thread_cluster .networkName
314
308
# parse routing role to (diagnostics) node type
315
309
if (
316
- cluster .routingRole
310
+ thread_cluster .routingRole
317
311
== Clusters .ThreadNetworkDiagnostics .Enums .RoutingRoleEnum .kSleepyEndDevice
318
312
):
319
313
node_type = NodeType .SLEEPY_END_DEVICE
320
- if cluster .routingRole in (
314
+ if thread_cluster .routingRole in (
321
315
Clusters .ThreadNetworkDiagnostics .Enums .RoutingRoleEnum .kLeader ,
322
316
Clusters .ThreadNetworkDiagnostics .Enums .RoutingRoleEnum .kRouter ,
323
317
):
324
318
node_type = NodeType .ROUTING_END_DEVICE
325
319
elif (
326
- cluster .routingRole
320
+ thread_cluster .routingRole
327
321
== Clusters .ThreadNetworkDiagnostics .Enums .RoutingRoleEnum .kEndDevice
328
322
):
329
323
node_type = NodeType .END_DEVICE
330
324
elif network_type == NetworkType .WIFI :
331
- attr_value : bytes = node .get_attribute_value (
332
- 0 ,
333
- cluster = None ,
334
- attribute = Clusters .WiFiNetworkDiagnostics .Attributes .Bssid ,
325
+ wifi_cluster : Clusters .WiFiNetworkDiagnostics = node .get_cluster (
326
+ 0 , Clusters .WiFiNetworkDiagnostics
335
327
)
336
- network_name = convert_hex_string (attr_value )
328
+ if wifi_cluster and wifi_cluster .bssid :
329
+ network_name = wifi_cluster .bssid
337
330
node_type = NodeType .END_DEVICE
338
331
# override node type if node is a bridge
339
332
if node .node_data .is_bridge :
@@ -345,9 +338,9 @@ async def node_diagnostics(self, node_id: int) -> NodeDiagnostics:
345
338
network_type = network_type ,
346
339
node_type = node_type ,
347
340
network_name = network_name ,
348
- ip_adresses = list ( ping_result ) ,
341
+ ip_adresses = ip_addresses ,
349
342
mac_address = mac_address ,
350
- reachable = any ( ping_result . values ()) ,
343
+ available = node . available ,
351
344
active_fabrics = active_fabrics ,
352
345
)
353
346
0 commit comments