zigpy / open-coordinator-backup

Open Zigbee coordinator backup format
MIT License
56 stars 7 forks source link

Create an `is_child` key #6

Closed puddly closed 2 years ago

puddly commented 2 years ago

It's not possible to currently tell if a device with an APS link key is a child or just a descendant. In Z-Stack, is_child would map to AddrMgrUserType.Assoc. The presence of link_key would indicate AddrMgrUserType.Security.

The current behavior is kept if the key is missing: assume is_child == True if no APS link key is present in the device entry, and is_child == False if there is an APS link key entry.

castorw commented 2 years ago

@puddly What does this key actually present? Does this indicate whether the peer device is a direct child of coordinator or something else? If so, I may have a bit different implementation in zigbee herdsman.

puddly commented 2 years ago

Does this indicate whether the peer device is a direct child of coordinator

Yes. What approach did you end up taking with herdsman?

castorw commented 2 years ago

Well I didn't detect the pattern as you did, but I may be wrong. If the entry is & Assoc then its just a device without APS link keys negotiated, bcz those are present in address manager table as well. When the entries as & Assoc & Security they are configured with APS link keys as well. Please correct me if I am wrong.

puddly commented 2 years ago

Here are the address manager entries of a fresh network with five devices (one router and four end devices):

# ZB3 outlet (only other router on the network)
AddrMgrEntry(type=<AddrMgrUserType.Security|Assoc: 3>, nwkAddr=0x71BA, extAddr=d0:cf:5e:ff:fe:ce:3a:f2)

# ZB3 dimmer (child of coordinator)
AddrMgrEntry(type=<AddrMgrUserType.Security|Assoc: 3>, nwkAddr=0xBE28, extAddr=00:0b:57:ff:fe:2b:cf:1f)

# ZB3 dimmer (child of outlet)
AddrMgrEntry(type=<AddrMgrUserType.Security: 2>, nwkAddr=0x24FD, extAddr=00:0b:57:ff:fe:2b:d4:57)

# Aqara temp sensor (child of coordinator)
AddrMgrEntry(type=<AddrMgrUserType.Assoc: 1>, nwkAddr=0xB4C2, extAddr=00:15:8d:00:01:f2:3a:88)

# Aqara temp sensor, (child of ZB3 outlet)
(no addrmgr entry)

To me, it seems like Assoc corresponds to whether a device is a child of the coordinator or not. Security corresponds to whether or not it has a link key shared with the coordinator. Right now we have no way to distinguish ZB3 dimmer (child of coordinator) from ZB3 dimmer (child of outlet), since they both generate the same backup JSON.

puddly commented 2 years ago

Any thoughts on this? The change is backwards-compatible so you can ignore the key if you don't find it useful.

castorw commented 2 years ago

Oh, allright. Yeah, I am totally okay with it. I am going to create a reminder for myself to implement this within zigbee-herdsman. Feel free to merge.