-
Notifications
You must be signed in to change notification settings - Fork 41
Replace internal network state objects with zigpy.state
#85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #85 +/- ##
==========================================
+ Coverage 98.71% 98.75% +0.04%
==========================================
Files 44 44
Lines 3727 3768 +41
==========================================
+ Hits 3679 3721 +42
+ Misses 48 47 -1
Continue to review full report at Codecov.
|
I was on the fence whether to keep the NWK address of the node for key. Is this device list actually for the devices, like "children" or is this the list of "APS Link keys" for APS encrypted communication? |
It's a list of both, which is ambiguous now that I think about it (i.e one can't distinguish a child with an APS link key from a non-child). I'm currently populating the What about keeping a list of devices like this? @dataclass
class NetworkDevice:
ieee: t.EUI64
nwk: t.NWK | None # I'll have to test how to get Z-Stack to deal with these
key: Key | None
is_child: bool |
does ZNP restoration need children or FFDs too?
I think that would work. Any suggestions how to call the list of these in app state? |
The only devices present in my Z-Stack coordinator backup are:
So it looks like only devices with APS link keys and RFD children. They all require NWK and IEEE addresses.
Since a device can be a "partner" with a key and/or a child, maybe Maybe |
Yeah, i think having two different lists is a better approach |
I've almost got this working with ZNP. async def form_network(self):
"""
Clears the current config and forms a new network with a random network key,
PAN ID, and extended PAN ID.
"""
channel = self.config[conf.CONF_NWK][conf.CONF_NWK_CHANNEL]
channels = self.config[conf.CONF_NWK][conf.CONF_NWK_CHANNELS]
pan_id = self.config[conf.CONF_NWK][conf.CONF_NWK_PAN_ID]
extended_pan_id = self.config[conf.CONF_NWK][conf.CONF_NWK_EXTENDED_PAN_ID]
network_key = self.config[conf.CONF_NWK][conf.CONF_NWK_KEY]
if pan_id is None:
pan_id = random.SystemRandom().randint(0x0000, 0xFFFE + 1)
if extended_pan_id is None:
extended_pan_id = ExtendedPanId(os.urandom(8))
if network_key is None:
network_key = t.KeyData(os.urandom(16))
# Override `channels` with a single channel if one is explicitly set
if channel is not None:
channels = t.Channels.from_channel_list([channel])
network_info = zigpy.state.NetworkInformation(
extended_pan_id=extended_pan_id,
pan_id=pan_id,
nwk_update_id=self.config[conf.CONF_NWK][conf.CONF_NWK_UPDATE_ID],
nwk_manager_id=0x0000,
channel=channel,
channel_mask=channels,
security_level=5,
network_key=zigpy.state.Key(
key=network_key,
tx_counter=0,
rx_counter=0,
seq=0,
partner_ieee=None,
),
tc_link_key=None,
key_table=[],
neighbor_table=[],
stack_specific={"zstack": {"tclk_seed": os.urandom(16).hex()}},
)
node_info = zigpy.state.NodeInfo(
nwk=0x0000,
ieee=None,
logical_type=zdo_t.LogicalType.Coordinator,
)
await self.write_network_info(network_info=network_info, node_info=node_info) Thoughts? |
The main problem with this general approach are radio quirks:
|
I like the idea.
Not really possible to change this. Has to do with the flash page erasing Need to check deconz, IIRC you can update ieee address in deCONZ, but couldn't find anything in official documentation. Zigate -- need to check this one. |
Updated to work with At this point I'm only converting to JSON for presentation, all other operations use the zigpy state objects:
Once a zigpy point release is made, we can:
|
Do you need just zigpy release or pushed to HA too? |
Doesn't really matter, updated versions of both packages will probably go in the same PR to HA core. |
Sorry, I think I misread your comment. Just a zigpy release, so I can specify the minimum version in |
a761d04
to
4b68155
Compare
The only feature
zigpy.state
lacks right now is a way to keep track of device NWK and IEEE addresses, like in https://github.com/zigpy/open-coordinator-backup/blob/main/samples/z2m-sample-1.json#L53-L56.Once that is done, the entire Z-Stack coordinator state can be fully represented by the new
zigpy.state
types. While this is not strictly necessary with #73, I've not yet tested the side effects of restoring a network backup with the child table completely erased.My idea is to have zigpy behave something like this in the future and requiring radio libraries to implement only
load_network_info
andupdate_network_info
: