2020-12-29 07:38:41 -07:00
|
|
|
from datetime import timedelta
|
2020-12-28 15:46:15 -07:00
|
|
|
from typing import Optional
|
|
|
|
|
2020-12-29 09:13:41 -07:00
|
|
|
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
|
|
|
from gekitchen import ErdCode, ErdCodeType, ErdCodeClass, ErdMeasurementUnits
|
2020-12-28 15:46:15 -07:00
|
|
|
|
|
|
|
from ge_kitchen.const import DOMAIN
|
|
|
|
from ge_kitchen.devices import ApplianceApi
|
|
|
|
from .ge_entity import GeEntity
|
|
|
|
|
|
|
|
|
|
|
|
class GeErdEntity(GeEntity):
|
|
|
|
"""Parent class for GE entities tied to a specific ERD"""
|
2020-12-29 08:03:37 -07:00
|
|
|
def __init__(self, api: ApplianceApi, erd_code: ErdCodeType, erd_override: str = None, icon_override: str = None, device_class_override: str = None):
|
2020-12-28 15:46:15 -07:00
|
|
|
super().__init__(api)
|
|
|
|
self._erd_code = api.appliance.translate_erd_code(erd_code)
|
|
|
|
self._erd_code_class = api.appliance.get_erd_code_class(self._erd_code)
|
|
|
|
self._erd_override = erd_override
|
2020-12-29 08:03:37 -07:00
|
|
|
self._icon_override = icon_override
|
|
|
|
self._device_class_override = device_class_override
|
2020-12-28 15:46:15 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def erd_code(self) -> ErdCodeType:
|
|
|
|
return self._erd_code
|
|
|
|
|
|
|
|
@property
|
|
|
|
def erd_code_class(self) -> ErdCodeClass:
|
|
|
|
return self._erd_code_class
|
|
|
|
|
|
|
|
@property
|
|
|
|
def erd_string(self) -> str:
|
|
|
|
erd_code = self.erd_code
|
|
|
|
if isinstance(self.erd_code, ErdCode):
|
|
|
|
return erd_code.name
|
|
|
|
return erd_code
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> Optional[str]:
|
|
|
|
erd_string = self.erd_string
|
|
|
|
|
|
|
|
#override the name if specified
|
|
|
|
if self._erd_override != None:
|
|
|
|
erd_string = self._erd_override
|
|
|
|
|
|
|
|
erd_title = " ".join(erd_string.split("_")).title()
|
|
|
|
return f"{self.serial_number} {erd_title}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self) -> Optional[str]:
|
|
|
|
return f"{DOMAIN}_{self.serial_number}_{self.erd_string.lower()}"
|
|
|
|
|
2020-12-29 08:03:37 -07:00
|
|
|
def _stringify(self, value: any, **kwargs) -> Optional[str]:
|
2020-12-29 09:13:41 -07:00
|
|
|
""" Stringify a value """
|
2020-12-28 15:46:15 -07:00
|
|
|
# perform special processing before passing over to the default method
|
|
|
|
if self.erd_code == ErdCode.CLOCK_TIME:
|
|
|
|
return value.strftime("%H:%M:%S") if value else None
|
|
|
|
if self.erd_code_class == ErdCodeClass.RAW_TEMPERATURE:
|
|
|
|
return f"{value}"
|
|
|
|
if self.erd_code_class == ErdCodeClass.NON_ZERO_TEMPERATURE:
|
|
|
|
return f"{value}" if value else ""
|
2020-12-29 07:38:41 -07:00
|
|
|
if self.erd_code_class == ErdCodeClass.TIMER or isinstance(value, timedelta):
|
2020-12-28 15:46:15 -07:00
|
|
|
return str(value)[:-3] if value else ""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2020-12-29 07:38:41 -07:00
|
|
|
return self.appliance.stringify_erd_value(value, kwargs)
|
2020-12-29 09:13:41 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def _temp_measurement_system(self) -> Optional[ErdMeasurementUnits]:
|
|
|
|
try:
|
|
|
|
value = self.appliance.get_erd_value(ErdCode.TEMPERATURE_UNIT)
|
|
|
|
except KeyError:
|
|
|
|
return None
|
|
|
|
return value
|
|
|
|
|
|
|
|
def _get_icon(self):
|
|
|
|
"""Select an appropriate icon."""
|
|
|
|
|
|
|
|
if self._icon_override:
|
|
|
|
return self._icon_override
|
|
|
|
if not isinstance(self.erd_code, ErdCode):
|
|
|
|
return None
|
|
|
|
if self.erd_code_class == ErdCodeClass.CLOCK:
|
|
|
|
return "mdi:clock"
|
2020-12-29 10:02:56 -07:00
|
|
|
if self.erd_code_class == ErdCodeClass.COUNTER:
|
|
|
|
return "mdi:counter"
|
2020-12-29 09:13:41 -07:00
|
|
|
if self.erd_code_class == ErdCodeClass.DOOR:
|
|
|
|
return "mdi:door"
|
|
|
|
if self.erd_code_class == ErdCodeClass.TIMER:
|
|
|
|
return "mdi:timer-outline"
|
|
|
|
if self.erd_code_class == ErdCodeClass.LOCK_CONTROL:
|
|
|
|
return "mdi:lock-outline"
|
|
|
|
if self.erd_code_class == ErdCodeClass.SABBATH_CONTROL:
|
|
|
|
return "mdi:judaism"
|
|
|
|
if self.erd_code_class == ErdCodeClass.COOLING_CONTROL:
|
|
|
|
return "mdi:snowflake"
|
|
|
|
if self.erd_code_class == ErdCodeClass.OVEN_SENSOR:
|
|
|
|
return "mdi:stove"
|
|
|
|
if self.erd_code_class == ErdCodeClass.FRIDGE_SENSOR:
|
|
|
|
return "mdi:fridge-bottom"
|
|
|
|
if self.erd_code_class == ErdCodeClass.FREEZER_SENSOR:
|
|
|
|
return "mdi:fridge-top"
|
|
|
|
if self.erd_code_class == ErdCodeClass.DISPENSER_SENSOR:
|
|
|
|
return "mdi:cup-water"
|
2020-12-29 10:06:10 -07:00
|
|
|
if self.erd_code_class == ErdCodeClass.DISHWASHER_SENSOR:
|
2020-12-29 09:13:41 -07:00
|
|
|
return "mdi:dishwasher"
|
|
|
|
|
|
|
|
return None
|