mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-31 22:40:15 -07:00
Look up value descriptions
This commit is contained in:
parent
445ea623fc
commit
844d1c1bdb
12
example.py
12
example.py
@ -22,6 +22,8 @@ def example_command(client, args):
|
|||||||
|
|
||||||
elif args[0] == 'mon':
|
elif args[0] == 'mon':
|
||||||
device_id = args[1]
|
device_id = args[1]
|
||||||
|
device = client.get_device(device_id)
|
||||||
|
model = client.model_info(device)
|
||||||
|
|
||||||
with wideq.Monitor(client.session, device_id) as mon:
|
with wideq.Monitor(client.session, device_id) as mon:
|
||||||
try:
|
try:
|
||||||
@ -30,9 +32,13 @@ def example_command(client, args):
|
|||||||
print('Polling...')
|
print('Polling...')
|
||||||
res = mon.poll()
|
res = mon.poll()
|
||||||
if res:
|
if res:
|
||||||
print(res)
|
for key, value in res.items():
|
||||||
print('setting: {}°C'.format(res['TempCfg']))
|
if key == 'Operation':
|
||||||
print('current: {}°C'.format(res['TempCur']))
|
options = model.enum('Operation')
|
||||||
|
print('- {}: {}'.format(key, options[value]))
|
||||||
|
else:
|
||||||
|
print('- {}: {}'.format(key, value))
|
||||||
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
33
wideq.py
33
wideq.py
@ -384,6 +384,17 @@ class Client(object):
|
|||||||
self._devices = self.session.get_devices()
|
self._devices = self.session.get_devices()
|
||||||
return (DeviceInfo(d) for d in self._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
|
@classmethod
|
||||||
def load(cls, state):
|
def load(cls, state):
|
||||||
"""Load a client from serialized state.
|
"""Load a client from serialized state.
|
||||||
@ -496,3 +507,25 @@ class ModelInfo(object):
|
|||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = 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']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user