File tree Expand file tree Collapse file tree 6 files changed +34
-14
lines changed Expand file tree Collapse file tree 6 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ target/
63
63
64
64
# virtualenv
65
65
.venv /
66
+ .venv * /
66
67
venv /
67
68
ENV /
68
69
Original file line number Diff line number Diff line change @@ -54,7 +54,6 @@ def backup_json():
54
54
"internal" : {
55
55
"creation_time" : "2021-02-16T22:29:28+00:00" ,
56
56
"zstack" : {"version" : 3.3 },
57
- "children" : ["000b57fffe38b212" ],
58
57
},
59
58
60
59
"version" : 1 ,
@@ -73,7 +72,12 @@ def backup_json():
73
72
"sequence_number" : 1 ,
74
73
},
75
74
"devices" : [
76
- {"ieee_address" : "000b57fffe36b9a0" , "nwk_address" : "f319" }, # No key
75
+ {
76
+ # No key
77
+ "ieee_address" : "000b57fffe36b9a0" ,
78
+ "nwk_address" : "f319" ,
79
+ "is_child" : True ,
80
+ },
77
81
{
78
82
"ieee_address" : "000b57fffe38b212" ,
79
83
"link_key" : {
@@ -82,6 +86,7 @@ def backup_json():
82
86
"tx_counter" : 456 ,
83
87
},
84
88
"nwk_address" : "9672" ,
89
+ "is_child" : True ,
85
90
},
86
91
{
87
92
"ieee_address" : "aabbccddeeff0011" ,
@@ -91,6 +96,7 @@ def backup_json():
91
96
"tx_counter" : 445566 ,
92
97
},
93
98
"nwk_address" : "abcd" ,
99
+ "is_child" : False ,
94
100
},
95
101
],
96
102
}
Original file line number Diff line number Diff line change @@ -387,7 +387,25 @@ async def write_network_info(
387
387
)
388
388
389
389
for key in network_info .key_table or []:
390
- devices [key .partner_ieee ] = devices [key .partner_ieee ].replace (
390
+ device = devices .get (key .partner_ieee )
391
+
392
+ if device is None :
393
+ nwk = None
394
+
395
+ # The key table doesn't save a device's NWK address so we pick one
396
+ for test_nwk in range (0x0001 , 0xFFFE + 1 ):
397
+ if all (n .nwk != test_nwk for n in network_info .neighbor_table ):
398
+ nwk = test_nwk
399
+ break
400
+
401
+ assert nwk is not None
402
+
403
+ device = security .StoredDevice (
404
+ nwk = nwk ,
405
+ ieee = key .partner_ieee ,
406
+ )
407
+
408
+ devices [key .partner_ieee ] = device .replace (
391
409
aps_link_key = key .key ,
392
410
tx_counter = key .tx_counter ,
393
411
rx_counter = key .rx_counter ,
Original file line number Diff line number Diff line change 36
36
"type" : "object" ,
37
37
"properties" : {
38
38
"tclk_seed" : {"type" : "string" , "pattern" : "[a-fA-F0-9]{32}" },
39
- "children" : {
40
- "type" : "array" ,
41
- "items" : {"type" : "string" , "pattern" : "[a-fA-F0-9]{16}" },
42
- },
43
39
},
44
40
}
45
41
},
74
70
"properties" : {
75
71
"nwk_address" : {"type" : "string" , "pattern" : "[a-fA-F0-9]{4}" },
76
72
"ieee_address" : {"type" : "string" , "pattern" : "[a-fA-F0-9]{16}" },
73
+ "is_child" : {"type" : "boolean" },
77
74
"link_key" : {
78
75
"type" : "object" ,
79
76
"properties" : {
Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ async def backup_network(znp: ZNP) -> t.JSONType:
28
28
obj = {
29
29
"nwk_address" : device .nwk .serialize ()[::- 1 ].hex (),
30
30
"ieee_address" : device .ieee .serialize ()[::- 1 ].hex (),
31
+ "is_child" : any (
32
+ device .ieee == nbr .ieee for nbr in znp .network_info .neighbor_table
33
+ ),
31
34
}
32
35
33
36
if device .aps_link_key :
@@ -53,10 +56,6 @@ async def backup_network(znp: ZNP) -> t.JSONType:
53
56
"zstack" : {
54
57
"version" : znp .version ,
55
58
},
56
- "children" : [
57
- neighbor .ieee .serialize ()[::- 1 ].hex ()
58
- for neighbor in znp .network_info .neighbor_table
59
- ],
60
59
},
61
60
},
62
61
"coordinator_ieee" : znp .node_info .ieee .serialize ()[::- 1 ].hex (),
Original file line number Diff line number Diff line change @@ -51,15 +51,14 @@ def json_backup_to_zigpy_state(
51
51
network_info .key_table = []
52
52
network_info .neighbor_table = []
53
53
54
- children = backup ["stack_specific" ].get ("zstack" , {}).get ("children" )
55
-
56
54
for obj in backup ["devices" ]:
57
55
node = zigpy .state .NodeInfo ()
58
56
node .nwk , _ = t .NWK .deserialize (bytes .fromhex (obj ["nwk_address" ])[::- 1 ])
59
57
node .ieee , _ = t .EUI64 .deserialize (bytes .fromhex (obj ["ieee_address" ])[::- 1 ])
60
58
node .logical_type = None
61
59
62
- if children is None or obj ["ieee_address" ] in children :
60
+ # The `is_child` key is optional. If it is missing, preserve the old behavior
61
+ if obj ["is_child" ] if "is_child" in obj else ("link_key" not in obj ):
63
62
network_info .neighbor_table .append (node )
64
63
65
64
if "link_key" in obj :
You can’t perform that action at this time.
0 commit comments