refactor from_dict()

This commit is contained in:
iou1name 2019-06-08 03:12:03 -04:00
parent fec387cf6c
commit 952d725639

View File

@ -60,11 +60,8 @@ class RelayDevice:
"""
Initializes self with data from JSON dict.
"""
self.id = data['id']
self.description = data['description']
self.location = data['location']
self.ip_address = data['ip_address']
self.sub_devices = {}
for key, value in data.items():
setattr(self, key, value)
for sub_dev_type, sub_devs in data['sub_devices'].items():
if sub_dev_type == 'RelayOutlet':
self.sub_devices[sub_dev_type] = []
@ -90,10 +87,8 @@ class RelayOutlet:
"""
Initializes self with data from JSON dict.
"""
self.id = data['id']
self.description = data['description']
self.gpio = data['gpio']
self.state = data['state']
for key, value in data.items():
setattr(self, key, value)
return self