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.
|
Initializes self with data from JSON dict.
|
||||||
"""
|
"""
|
||||||
self.id = data['id']
|
for key, value in data.items():
|
||||||
self.description = data['description']
|
setattr(self, key, value)
|
||||||
self.location = data['location']
|
|
||||||
self.ip_address = data['ip_address']
|
|
||||||
self.sub_devices = {}
|
|
||||||
for sub_dev_type, sub_devs in data['sub_devices'].items():
|
for sub_dev_type, sub_devs in data['sub_devices'].items():
|
||||||
if sub_dev_type == 'RelayOutlet':
|
if sub_dev_type == 'RelayOutlet':
|
||||||
self.sub_devices[sub_dev_type] = []
|
self.sub_devices[sub_dev_type] = []
|
||||||
|
@ -90,10 +87,8 @@ class RelayOutlet:
|
||||||
"""
|
"""
|
||||||
Initializes self with data from JSON dict.
|
Initializes self with data from JSON dict.
|
||||||
"""
|
"""
|
||||||
self.id = data['id']
|
for key, value in data.items():
|
||||||
self.description = data['description']
|
setattr(self, key, value)
|
||||||
self.gpio = data['gpio']
|
|
||||||
self.state = data['state']
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user