refactor from_dict()
This commit is contained in:
parent
fec387cf6c
commit
952d725639
13
juice.py
13
juice.py
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user