diff --git a/juice.py b/juice.py index a83a166..30980ed 100644 --- a/juice.py +++ b/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