1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-29 13:30:26 -07:00
wideq/wideq/util.py
Aaron Godfrey a019edea79 Refactored lookup_enum and lookup_reference methods to be reusable.
Also added a few additional washer states.
2019-07-11 11:37:29 -07:00

32 lines
877 B
Python

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