1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-27 20:40:18 -07:00

Look up value descriptions

This commit is contained in:
Adrian Sampson 2018-01-21 12:39:36 -05:00
parent 445ea623fc
commit 844d1c1bdb
2 changed files with 42 additions and 3 deletions

View File

@ -22,6 +22,8 @@ def example_command(client, args):
elif args[0] == 'mon':
device_id = args[1]
device = client.get_device(device_id)
model = client.model_info(device)
with wideq.Monitor(client.session, device_id) as mon:
try:
@ -30,9 +32,13 @@ def example_command(client, args):
print('Polling...')
res = mon.poll()
if res:
print(res)
print('setting: {}°C'.format(res['TempCfg']))
print('current: {}°C'.format(res['TempCur']))
for key, value in res.items():
if key == 'Operation':
options = model.enum('Operation')
print('- {}: {}'.format(key, options[value]))
else:
print('- {}: {}'.format(key, value))
except KeyboardInterrupt:
pass

View File

@ -384,6 +384,17 @@ class Client(object):
self._devices = self.session.get_devices()
return (DeviceInfo(d) for d in self._devices)
def get_device(self, device_id):
"""Look up a DeviceInfo object by device ID.
Return None if the device does not exist.
"""
for device in self.devices:
if device.id == device_id:
return device
return None
@classmethod
def load(cls, state):
"""Load a client from serialized state.
@ -496,3 +507,25 @@ class ModelInfo(object):
def __init__(self, data):
self.data = data
def enum(self, name):
"""Get the mapping of options for a given enumerated value.
"""
d = self.data['Value'][name]
assert d['type'] == 'Enum'
return d['option']
def range(self, name):
"""Get the minimum, maximum, and step for a numeric range value.
"""
d = self.data['Value'][name]
assert d['type'] == 'Range'
return d['option']['min'], d['option']['max'], d['option']['step']
def default(self, name):
"""Get the default value, if it exists, for a given value.
"""
return self.data['Value'][name]['default']