2020-12-29 07:38:41 -07:00
|
|
|
from datetime import timedelta
|
2020-12-28 15:46:15 -07:00
|
|
|
from typing import Optional, Dict, Any
|
|
|
|
|
|
|
|
from gekitchen import GeAppliance
|
|
|
|
from ge_kitchen.devices import ApplianceApi
|
|
|
|
|
|
|
|
class GeEntity:
|
|
|
|
"""Base class for all GE Entities"""
|
|
|
|
should_poll = False
|
|
|
|
|
|
|
|
def __init__(self, api: ApplianceApi):
|
|
|
|
self._api = api
|
|
|
|
self.hass = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self) -> str:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
|
|
|
def api(self) -> ApplianceApi:
|
|
|
|
return self._api
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_info(self) -> Optional[Dict[str, Any]]:
|
|
|
|
return self.api.device_info
|
|
|
|
|
|
|
|
@property
|
|
|
|
def serial_number(self):
|
|
|
|
return self.api.serial_number
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
return self.appliance.available
|
|
|
|
|
|
|
|
@property
|
|
|
|
def appliance(self) -> GeAppliance:
|
|
|
|
return self.api.appliance
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> Optional[str]:
|
|
|
|
raise NotImplementedError
|
2020-12-29 07:38:41 -07:00
|
|
|
|
2020-12-29 09:13:41 -07:00
|
|
|
@property
|
|
|
|
def icon(self) -> Optional[str]:
|
|
|
|
return self._get_icon()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self) -> Optional[str]:
|
|
|
|
return self._get_device_class()
|
|
|
|
|
2020-12-29 08:03:37 -07:00
|
|
|
def _stringify(self, value: any, **kwargs) -> Optional[str]:
|
2020-12-29 07:38:41 -07:00
|
|
|
if isinstance(timedelta):
|
|
|
|
return str(value)[:-3] if value else ""
|
|
|
|
if value is None:
|
|
|
|
return None
|
|
|
|
return self.appliance.stringify_erd_value(value, kwargs)
|
|
|
|
|
2020-12-29 08:03:37 -07:00
|
|
|
def _boolify(self, value: any) -> Optional[bool]:
|
2020-12-29 07:38:41 -07:00
|
|
|
return self.appliance.boolify_erd_value(value)
|
2020-12-29 09:13:41 -07:00
|
|
|
|
|
|
|
def _get_icon(self) -> Optional[str]:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def _get_device_class(self) -> Optional[str]:
|
|
|
|
return None
|