mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-15 23:00:18 -07:00
Refactored lookup_enum and lookup_reference methods to be reusable.
Also added a few additional washer states.
This commit is contained in:
parent
89967d0d76
commit
a019edea79
@ -372,6 +372,7 @@ class ModelInfo(object):
|
||||
reference = self.value(key).reference
|
||||
if value in reference:
|
||||
return reference[value]['_comment']
|
||||
return None
|
||||
|
||||
@property
|
||||
def binary_monitor_data(self):
|
||||
|
@ -2,6 +2,7 @@ import enum
|
||||
from typing import Optional
|
||||
|
||||
from .client import Device, _UNKNOWN
|
||||
from .util import lookup_enum, lookup_reference
|
||||
|
||||
|
||||
class DryerState(enum.Enum):
|
||||
@ -123,38 +124,30 @@ class DryerStatus(object):
|
||||
else:
|
||||
return 'ON'
|
||||
|
||||
def _lookup_enum(self, attr: str) -> str:
|
||||
"""Looks up an enum value for the provided attr.
|
||||
|
||||
:param attr: The attribute to lookup in the enum.
|
||||
:returns: The enum value.
|
||||
"""
|
||||
return self.dryer.model.enum_name(attr, self.data[attr])
|
||||
|
||||
@property
|
||||
def state(self) -> DryerState:
|
||||
"""Get the state of the dryer."""
|
||||
return DryerState(self._lookup_enum('State'))
|
||||
return DryerState(lookup_enum('State', self.data, self.dryer))
|
||||
|
||||
@property
|
||||
def previous_state(self) -> DryerState:
|
||||
"""Get the previous state of the dryer."""
|
||||
return DryerState(self._lookup_enum('PreState'))
|
||||
return DryerState(lookup_enum('PreState', self.data, self.dryer))
|
||||
|
||||
@property
|
||||
def dry_level(self) -> DryLevel:
|
||||
"""Get the dry level."""
|
||||
return DryLevel(self._lookup_enum('DryLevel'))
|
||||
return DryLevel(lookup_enum('DryLevel', self.data, self.dryer))
|
||||
|
||||
@property
|
||||
def temperature_control(self) -> TempControl:
|
||||
"""Get the temperature control setting."""
|
||||
return TempControl(self._lookup_enum('TempControl'))
|
||||
return TempControl(lookup_enum('TempControl', self.data, self.dryer))
|
||||
|
||||
@property
|
||||
def time_dry(self) -> TimeDry:
|
||||
"""Get the time dry setting."""
|
||||
return TimeDry(self._lookup_enum('TimeDry'))
|
||||
return TimeDry(lookup_enum('TimeDry', self.data, self.dryer))
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
@ -174,28 +167,17 @@ class DryerStatus(object):
|
||||
int(self.data['Initial_Time_H']) * 60 +
|
||||
int(self.data['Initial_Time_M']))
|
||||
|
||||
def _lookup_reference(self, attr: str) -> str:
|
||||
"""Look up a reference value for the provided attribute.
|
||||
|
||||
:param attr: The attribute to find the value for.
|
||||
:returns: The looked up value.
|
||||
"""
|
||||
value = self.dryer.model.reference_name(attr, self.data[attr])
|
||||
if value is None:
|
||||
return 'Off'
|
||||
return value
|
||||
|
||||
@property
|
||||
def course(self) -> str:
|
||||
"""Get the current course."""
|
||||
return self._lookup_reference('Course')
|
||||
return lookup_reference('Course', self.data, self.dryer)
|
||||
|
||||
@property
|
||||
def smart_course(self) -> str:
|
||||
"""Get the current smart course."""
|
||||
return self._lookup_reference('SmartCourse')
|
||||
return lookup_reference('SmartCourse', self.data, self.dryer)
|
||||
|
||||
@property
|
||||
def error(self) -> str:
|
||||
"""Get the current error."""
|
||||
return self._lookup_reference('Error')
|
||||
return lookup_reference('Error', self.data, self.dryer)
|
||||
|
31
wideq/util.py
Normal file
31
wideq/util.py
Normal file
@ -0,0 +1,31 @@
|
||||
from typing import TypeVar
|
||||
|
||||
from .client import Device
|
||||
|
||||
|
||||
T = TypeVar('T', bound=Device)
|
||||
|
||||
|
||||
def lookup_enum(attr: str, data: dict, device: T):
|
||||
"""Looks up an enum value for the provided attr.
|
||||
|
||||
:param attr: The attribute to lookup in the enum.
|
||||
:param data: The JSON data from the API.
|
||||
:param device: A sub-class instance of a Device.
|
||||
:returns: The enum value.
|
||||
"""
|
||||
return device.model.enum_name(attr, data[attr])
|
||||
|
||||
|
||||
def lookup_reference(attr: str, data: dict, device: T) -> str:
|
||||
"""Look up a reference value for the provided attribute.
|
||||
|
||||
:param attr: The attribute to find the value for.
|
||||
:param data: The JSON data from the API.
|
||||
:param device: A sub-class instance of a Device.
|
||||
:returns: The looked up value.
|
||||
"""
|
||||
value = device.model.reference_name(attr, data[attr])
|
||||
if value is None:
|
||||
return 'Off'
|
||||
return value
|
@ -2,17 +2,23 @@ import enum
|
||||
from typing import Optional
|
||||
|
||||
from .client import Device
|
||||
from .util import lookup_enum, lookup_reference
|
||||
|
||||
|
||||
class WasherState(enum.Enum):
|
||||
"""The state of the washer device."""
|
||||
|
||||
ADD_DRAIN = '@WM_STATE_ADD_DRAIN_W'
|
||||
COMPLETE = '@WM_STATE_COMPLETE_W'
|
||||
DETECTING = '@WM_STATE_DETECTING_W'
|
||||
DETERGENT_AMOUNT = '@WM_STATE_DETERGENT_AMOUNT_W'
|
||||
DRYING = '@WM_STATE_DRYING_W'
|
||||
END = '@WM_STATE_END_W'
|
||||
ERROR_AUTO_OFF = '@WM_STATE_ERROR_AUTO_OFF_W'
|
||||
FRESH_CARE = '@WM_STATE_FRESHCARE_W'
|
||||
FROZEN_PREVENT_INITIAL = '@WM_STATE_FROZEN_PREVENT_INITIAL_W'
|
||||
FROZEN_PREVENT_PAUSE = '@WM_STATE_FROZEN_PREVENT_PAUSE_W'
|
||||
FROZEN_PREVENT_RUNNING = '@WM_STATE_FROZEN_PREVENT_RUNNING_W'
|
||||
INITIAL = '@WM_STATE_INITIAL_W'
|
||||
OFF = '@WM_STATE_POWER_OFF_W'
|
||||
PAUSE = '@WM_STATE_PAUSE_W'
|
||||
@ -24,6 +30,7 @@ class WasherState(enum.Enum):
|
||||
SMART_DIAGNOSIS = '@WM_STATE_SMART_DIAG_W'
|
||||
SMART_DIAGNOSIS_DATA = '@WM_STATE_SMART_DIAGDATA_W'
|
||||
SPINNING = '@WM_STATE_SPINNING_W'
|
||||
TCL_ALARM_NORMAL = 'TCL_ALARM_NORMAL'
|
||||
TUBCLEAN_COUNT_ALARM = '@WM_STATE_TUBCLEAN_COUNT_ALRAM_W'
|
||||
|
||||
|
||||
@ -60,23 +67,15 @@ class WasherStatus(object):
|
||||
self.washer = washer
|
||||
self.data = data
|
||||
|
||||
def _lookup_enum(self, attr: str) -> str:
|
||||
"""Looks up an enum value for the provided attr.
|
||||
|
||||
:param attr: The attribute to lookup in the enum.
|
||||
:returns: The enum value.
|
||||
"""
|
||||
return self.washer.model.enum_name(attr, self.data[attr])
|
||||
|
||||
@property
|
||||
def state(self) -> WasherState:
|
||||
"""Get the state of the washer."""
|
||||
return WasherState(self._lookup_enum('State'))
|
||||
return WasherState(lookup_enum('State', self.data, self.washer))
|
||||
|
||||
@property
|
||||
def previous_state(self) -> WasherState:
|
||||
"""Get the previous state of the washer."""
|
||||
return WasherState(self._lookup_enum('PreState'))
|
||||
return WasherState(lookup_enum('PreState', self.data, self.washer))
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
@ -110,14 +109,14 @@ class WasherStatus(object):
|
||||
@property
|
||||
def course(self) -> str:
|
||||
"""Get the current course."""
|
||||
return self._lookup_reference('APCourse')
|
||||
return lookup_reference('APCourse', self.data, self.washer)
|
||||
|
||||
@property
|
||||
def smart_course(self) -> str:
|
||||
"""Get the current smart course."""
|
||||
return self._lookup_reference('SmartCourse')
|
||||
return lookup_reference('SmartCourse', self.data, self.washer)
|
||||
|
||||
@property
|
||||
def error(self) -> str:
|
||||
"""Get the current error."""
|
||||
return self._lookup_reference('Error')
|
||||
return lookup_reference('Error', self.data, self.washer)
|
||||
|
Loading…
x
Reference in New Issue
Block a user