mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-17 15:50:10 -07:00
Make a new Client base class
For generic device-related utilities. Eventually, non-AC devices should inherit from this too.
This commit is contained in:
parent
d3cee73759
commit
0b3730f5f2
65
wideq.py
65
wideq.py
@ -681,6 +681,42 @@ class ModelInfo(object):
|
|||||||
return options[value]
|
return options[value]
|
||||||
|
|
||||||
|
|
||||||
|
class Device(object):
|
||||||
|
"""A higher-level interface to a specific device.
|
||||||
|
|
||||||
|
Unlike `DeviceInfo`, which just stores data *about* a device,
|
||||||
|
`Device` objects refer to their client and can perform operations
|
||||||
|
regarding the device.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, client, device):
|
||||||
|
"""Create a wrapper for a `DeviceInfo` object associated with a
|
||||||
|
`Client`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.client = client
|
||||||
|
self.device = device
|
||||||
|
self.model = client.model_info(device)
|
||||||
|
|
||||||
|
def _set_control(self, key, value):
|
||||||
|
"""Set a device's control for `key` to `value`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.client.session.set_device_controls(
|
||||||
|
self.device.id,
|
||||||
|
{key: value},
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_config(self, key):
|
||||||
|
"""Look up a device's configuration for a given value.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.client.session.get_device_config(
|
||||||
|
self.device.id,
|
||||||
|
key,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ACMode(enum.Enum):
|
class ACMode(enum.Enum):
|
||||||
"""The operation mode for an AC/HVAC device."""
|
"""The operation mode for an AC/HVAC device."""
|
||||||
|
|
||||||
@ -704,20 +740,11 @@ class ACOp(enum.Enum):
|
|||||||
ALL_ON = "@AC_MAIN_OPERATION_ALL_ON_W"
|
ALL_ON = "@AC_MAIN_OPERATION_ALL_ON_W"
|
||||||
|
|
||||||
|
|
||||||
class ACDevice(object):
|
class ACDevice(Device):
|
||||||
"""Higher-level operations on an AC/HVAC device, such as a heat
|
"""Higher-level operations on an AC/HVAC device, such as a heat
|
||||||
pump.
|
pump.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, client, device):
|
|
||||||
"""Create a wrapper for a `DeviceInfo` object associated with a
|
|
||||||
`Client`.
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.client = client
|
|
||||||
self.device = device
|
|
||||||
self.model = client.model_info(device)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def f2c(self):
|
def f2c(self):
|
||||||
"""Get a dictionary mapping Fahrenheit to Celsius temperatures for
|
"""Get a dictionary mapping Fahrenheit to Celsius temperatures for
|
||||||
@ -751,24 +778,6 @@ class ACDevice(object):
|
|||||||
out[c_num] = f
|
out[c_num] = f
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def _set_control(self, key, value):
|
|
||||||
"""Set a device's control for `key` to `value`.
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.client.session.set_device_controls(
|
|
||||||
self.device.id,
|
|
||||||
{key: value},
|
|
||||||
)
|
|
||||||
|
|
||||||
def _get_config(self, key):
|
|
||||||
"""Look up a device's configuration for a given value.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return self.client.session.get_device_config(
|
|
||||||
self.device.id,
|
|
||||||
key,
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_celsius(self, c):
|
def set_celsius(self, c):
|
||||||
"""Set the device's target temperature in Celsius degrees.
|
"""Set the device's target temperature in Celsius degrees.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user