Make DeviceConfiguration loadable from a dict

This commit is contained in:
David Duarte
2022-06-23 14:31:36 +00:00
parent 3d14df909c
commit 0f157d55f7

View File

@@ -260,10 +260,7 @@ class DeviceConfiguration:
self.irk = bytes(16) # This really must be changed for any level of security
self.keystore = None
def load_from_file(self, filename):
with open(filename, 'r') as file:
config = json.load(file)
def load_from_dict(self, config):
# Load simple properties
self.name = config.get('name', self.name)
self.address = Address(config.get('address', self.address))
@@ -287,6 +284,9 @@ class DeviceConfiguration:
if advertising_data:
self.advertising_data = bytes.fromhex(advertising_data)
def load_from_file(self, filename):
with open(filename, 'r') as file:
self.load_from_dict(json.load(file))
# -----------------------------------------------------------------------------
# Decorators used with the following Device class