Skip to content

Commit 7585379

Browse files
committed
database: handle observing secondary device key
Handle observing the secondary device key without raising an exception. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 025f90c commit 7585379

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/infuse_iot/database.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,19 @@ def observe_device(
9797
self.gateway = infuse_id
9898
if infuse_id not in self.devices:
9999
self.devices[infuse_id] = self.DeviceState(infuse_id)
100+
dev = self.devices[infuse_id]
100101
if network_id is not None:
101-
self.devices[infuse_id].network_id = network_id
102+
dev.network_id = network_id
102103
if device_key_id is not None:
103-
if (
104-
self.devices[infuse_id].device_key_id is not None
105-
and self.devices[infuse_id].device_key_id != device_key_id
106-
):
104+
if device_key_id == dev.secondary_device_key_id:
105+
pass
106+
elif dev.device_key_id is not None and dev.device_key_id != device_key_id:
107107
raise DeviceKeyChangedError(f"Device key for {infuse_id:016x} has changed")
108-
self.devices[infuse_id].device_key_id = device_key_id
108+
else:
109+
dev.device_key_id = device_key_id
109110
if bt_addr is not None:
110111
self.bt_addr[bt_addr] = infuse_id
111-
self.devices[infuse_id].bt_addr = bt_addr
112+
dev.bt_addr = bt_addr
112113

113114
def observe_secondary_remote_public_key(self, infuse_id: int, secondary_pub_key: bytes):
114115
if not self.is_local_root(secondary_pub_key):

0 commit comments

Comments
 (0)