mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-16 07:10:09 -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
|
reference = self.value(key).reference
|
||||||
if value in reference:
|
if value in reference:
|
||||||
return reference[value]['_comment']
|
return reference[value]['_comment']
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def binary_monitor_data(self):
|
def binary_monitor_data(self):
|
||||||
|
@ -2,6 +2,7 @@ import enum
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from .client import Device, _UNKNOWN
|
from .client import Device, _UNKNOWN
|
||||||
|
from .util import lookup_enum, lookup_reference
|
||||||
|
|
||||||
|
|
||||||
class DryerState(enum.Enum):
|
class DryerState(enum.Enum):
|
||||||
@ -123,38 +124,30 @@ class DryerStatus(object):
|
|||||||
else:
|
else:
|
||||||
return 'ON'
|
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
|
@property
|
||||||
def state(self) -> DryerState:
|
def state(self) -> DryerState:
|
||||||
"""Get the state of the dryer."""
|
"""Get the state of the dryer."""
|
||||||
return DryerState(self._lookup_enum('State'))
|
return DryerState(lookup_enum('State', self.data, self.dryer))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def previous_state(self) -> DryerState:
|
def previous_state(self) -> DryerState:
|
||||||
"""Get the previous state of the dryer."""
|
"""Get the previous state of the dryer."""
|
||||||
return DryerState(self._lookup_enum('PreState'))
|
return DryerState(lookup_enum('PreState', self.data, self.dryer))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dry_level(self) -> DryLevel:
|
def dry_level(self) -> DryLevel:
|
||||||
"""Get the dry level."""
|
"""Get the dry level."""
|
||||||
return DryLevel(self._lookup_enum('DryLevel'))
|
return DryLevel(lookup_enum('DryLevel', self.data, self.dryer))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_control(self) -> TempControl:
|
def temperature_control(self) -> TempControl:
|
||||||
"""Get the temperature control setting."""
|
"""Get the temperature control setting."""
|
||||||
return TempControl(self._lookup_enum('TempControl'))
|
return TempControl(lookup_enum('TempControl', self.data, self.dryer))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def time_dry(self) -> TimeDry:
|
def time_dry(self) -> TimeDry:
|
||||||
"""Get the time dry setting."""
|
"""Get the time dry setting."""
|
||||||
return TimeDry(self._lookup_enum('TimeDry'))
|
return TimeDry(lookup_enum('TimeDry', self.data, self.dryer))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
@ -174,28 +167,17 @@ class DryerStatus(object):
|
|||||||
int(self.data['Initial_Time_H']) * 60 +
|
int(self.data['Initial_Time_H']) * 60 +
|
||||||
int(self.data['Initial_Time_M']))
|
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
|
@property
|
||||||
def course(self) -> str:
|
def course(self) -> str:
|
||||||
"""Get the current course."""
|
"""Get the current course."""
|
||||||
return self._lookup_reference('Course')
|
return lookup_reference('Course', self.data, self.dryer)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def smart_course(self) -> str:
|
def smart_course(self) -> str:
|
||||||
"""Get the current smart course."""
|
"""Get the current smart course."""
|
||||||
return self._lookup_reference('SmartCourse')
|
return lookup_reference('SmartCourse', self.data, self.dryer)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def error(self) -> str:
|
def error(self) -> str:
|
||||||
"""Get the current error."""
|
"""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 typing import Optional
|
||||||
|
|
||||||
from .client import Device
|
from .client import Device
|
||||||
|
from .util import lookup_enum, lookup_reference
|
||||||
|
|
||||||
|
|
||||||
class WasherState(enum.Enum):
|
class WasherState(enum.Enum):
|
||||||
"""The state of the washer device."""
|
"""The state of the washer device."""
|
||||||
|
|
||||||
ADD_DRAIN = '@WM_STATE_ADD_DRAIN_W'
|
ADD_DRAIN = '@WM_STATE_ADD_DRAIN_W'
|
||||||
|
COMPLETE = '@WM_STATE_COMPLETE_W'
|
||||||
DETECTING = '@WM_STATE_DETECTING_W'
|
DETECTING = '@WM_STATE_DETECTING_W'
|
||||||
|
DETERGENT_AMOUNT = '@WM_STATE_DETERGENT_AMOUNT_W'
|
||||||
DRYING = '@WM_STATE_DRYING_W'
|
DRYING = '@WM_STATE_DRYING_W'
|
||||||
END = '@WM_STATE_END_W'
|
END = '@WM_STATE_END_W'
|
||||||
ERROR_AUTO_OFF = '@WM_STATE_ERROR_AUTO_OFF_W'
|
ERROR_AUTO_OFF = '@WM_STATE_ERROR_AUTO_OFF_W'
|
||||||
FRESH_CARE = '@WM_STATE_FRESHCARE_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'
|
INITIAL = '@WM_STATE_INITIAL_W'
|
||||||
OFF = '@WM_STATE_POWER_OFF_W'
|
OFF = '@WM_STATE_POWER_OFF_W'
|
||||||
PAUSE = '@WM_STATE_PAUSE_W'
|
PAUSE = '@WM_STATE_PAUSE_W'
|
||||||
@ -24,6 +30,7 @@ class WasherState(enum.Enum):
|
|||||||
SMART_DIAGNOSIS = '@WM_STATE_SMART_DIAG_W'
|
SMART_DIAGNOSIS = '@WM_STATE_SMART_DIAG_W'
|
||||||
SMART_DIAGNOSIS_DATA = '@WM_STATE_SMART_DIAGDATA_W'
|
SMART_DIAGNOSIS_DATA = '@WM_STATE_SMART_DIAGDATA_W'
|
||||||
SPINNING = '@WM_STATE_SPINNING_W'
|
SPINNING = '@WM_STATE_SPINNING_W'
|
||||||
|
TCL_ALARM_NORMAL = 'TCL_ALARM_NORMAL'
|
||||||
TUBCLEAN_COUNT_ALARM = '@WM_STATE_TUBCLEAN_COUNT_ALRAM_W'
|
TUBCLEAN_COUNT_ALARM = '@WM_STATE_TUBCLEAN_COUNT_ALRAM_W'
|
||||||
|
|
||||||
|
|
||||||
@ -60,23 +67,15 @@ class WasherStatus(object):
|
|||||||
self.washer = washer
|
self.washer = washer
|
||||||
self.data = data
|
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
|
@property
|
||||||
def state(self) -> WasherState:
|
def state(self) -> WasherState:
|
||||||
"""Get the state of the washer."""
|
"""Get the state of the washer."""
|
||||||
return WasherState(self._lookup_enum('State'))
|
return WasherState(lookup_enum('State', self.data, self.washer))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def previous_state(self) -> WasherState:
|
def previous_state(self) -> WasherState:
|
||||||
"""Get the previous state of the washer."""
|
"""Get the previous state of the washer."""
|
||||||
return WasherState(self._lookup_enum('PreState'))
|
return WasherState(lookup_enum('PreState', self.data, self.washer))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
@ -110,14 +109,14 @@ class WasherStatus(object):
|
|||||||
@property
|
@property
|
||||||
def course(self) -> str:
|
def course(self) -> str:
|
||||||
"""Get the current course."""
|
"""Get the current course."""
|
||||||
return self._lookup_reference('APCourse')
|
return lookup_reference('APCourse', self.data, self.washer)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def smart_course(self) -> str:
|
def smart_course(self) -> str:
|
||||||
"""Get the current smart course."""
|
"""Get the current smart course."""
|
||||||
return self._lookup_reference('SmartCourse')
|
return lookup_reference('SmartCourse', self.data, self.washer)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def error(self) -> str:
|
def error(self) -> str:
|
||||||
"""Get the current error."""
|
"""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