2020-12-28 15:46:15 -07:00
|
|
|
import logging
|
|
|
|
from typing import List
|
|
|
|
|
2020-12-29 10:02:56 -07:00
|
|
|
from homeassistant.const import DEVICE_CLASS_POWER_FACTOR
|
2020-12-28 15:46:15 -07:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2021-05-20 09:15:49 -06:00
|
|
|
from gehomesdk import (
|
2020-12-28 22:29:00 -07:00
|
|
|
ErdCode,
|
|
|
|
ErdApplianceType,
|
|
|
|
OvenConfiguration,
|
|
|
|
ErdCooktopConfig,
|
|
|
|
CooktopStatus
|
|
|
|
)
|
2020-12-28 15:46:15 -07:00
|
|
|
|
|
|
|
from .base import ApplianceApi
|
2020-12-28 22:29:00 -07:00
|
|
|
from ..entities import (
|
|
|
|
GeErdSensor,
|
|
|
|
GeErdBinarySensor,
|
2020-12-29 16:29:43 -07:00
|
|
|
GeErdPropertySensor,
|
2020-12-28 22:29:00 -07:00
|
|
|
GeErdPropertyBinarySensor,
|
|
|
|
GeOven,
|
|
|
|
UPPER_OVEN,
|
|
|
|
LOWER_OVEN
|
|
|
|
)
|
2020-12-28 15:46:15 -07:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
class OvenApi(ApplianceApi):
|
|
|
|
"""API class for oven objects"""
|
|
|
|
APPLIANCE_TYPE = ErdApplianceType.OVEN
|
|
|
|
|
|
|
|
def get_all_entities(self) -> List[Entity]:
|
|
|
|
base_entities = super().get_all_entities()
|
|
|
|
oven_config: OvenConfiguration = self.appliance.get_erd_value(ErdCode.OVEN_CONFIGURATION)
|
2021-07-20 12:08:59 -06:00
|
|
|
|
|
|
|
cooktop_config = ErdCooktopConfig.NONE
|
|
|
|
if self.has_erd_code(ErdCode.COOKTOP_CONFIG):
|
|
|
|
cooktop_config: ErdCooktopConfig = self.appliance.get_erd_value(ErdCode.COOKTOP_CONFIG)
|
2020-12-28 22:29:00 -07:00
|
|
|
|
2020-12-28 15:46:15 -07:00
|
|
|
_LOGGER.debug(f"Oven Config: {oven_config}")
|
2020-12-28 22:29:00 -07:00
|
|
|
_LOGGER.debug(f"Cooktop Config: {cooktop_config}")
|
2020-12-28 15:46:15 -07:00
|
|
|
oven_entities = []
|
2020-12-28 22:29:00 -07:00
|
|
|
cooktop_entities = []
|
2020-12-28 15:46:15 -07:00
|
|
|
|
|
|
|
if oven_config.has_lower_oven:
|
|
|
|
oven_entities.extend([
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_COOK_MODE),
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_COOK_TIME_REMAINING),
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_KITCHEN_TIMER),
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_USER_TEMP_OFFSET),
|
2020-12-28 22:29:00 -07:00
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_RAW_TEMPERATURE),
|
2020-12-28 15:46:15 -07:00
|
|
|
GeErdBinarySensor(self, ErdCode.UPPER_OVEN_REMOTE_ENABLED),
|
|
|
|
|
|
|
|
GeErdSensor(self, ErdCode.LOWER_OVEN_COOK_MODE),
|
|
|
|
GeErdSensor(self, ErdCode.LOWER_OVEN_COOK_TIME_REMAINING),
|
2020-12-28 22:29:00 -07:00
|
|
|
GeErdSensor(self, ErdCode.LOWER_OVEN_KITCHEN_TIMER),
|
2020-12-28 15:46:15 -07:00
|
|
|
GeErdSensor(self, ErdCode.LOWER_OVEN_USER_TEMP_OFFSET),
|
2020-12-28 22:29:00 -07:00
|
|
|
GeErdSensor(self, ErdCode.LOWER_OVEN_RAW_TEMPERATURE),
|
2020-12-28 15:46:15 -07:00
|
|
|
GeErdBinarySensor(self, ErdCode.LOWER_OVEN_REMOTE_ENABLED),
|
2020-12-28 22:29:00 -07:00
|
|
|
|
|
|
|
GeOven(self, LOWER_OVEN, True),
|
|
|
|
GeOven(self, UPPER_OVEN, True),
|
2020-12-28 15:46:15 -07:00
|
|
|
])
|
|
|
|
else:
|
|
|
|
oven_entities.extend([
|
2020-12-29 16:29:43 -07:00
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_COOK_MODE, self._single_name(ErdCode.UPPER_OVEN_COOK_MODE)),
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_COOK_TIME_REMAINING, self._single_name(ErdCode.UPPER_OVEN_COOK_TIME_REMAINING)),
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_KITCHEN_TIMER, self._single_name(ErdCode.UPPER_OVEN_KITCHEN_TIMER)),
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_USER_TEMP_OFFSET, self._single_name(ErdCode.UPPER_OVEN_USER_TEMP_OFFSET)),
|
|
|
|
GeErdSensor(self, ErdCode.UPPER_OVEN_RAW_TEMPERATURE, self._single_name(ErdCode.UPPER_OVEN_RAW_TEMPERATURE)),
|
|
|
|
GeErdBinarySensor(self, ErdCode.UPPER_OVEN_REMOTE_ENABLED, self._single_name(ErdCode.UPPER_OVEN_REMOTE_ENABLED)),
|
2020-12-28 22:29:00 -07:00
|
|
|
GeOven(self, UPPER_OVEN, False)
|
2020-12-28 15:46:15 -07:00
|
|
|
])
|
2020-12-28 22:29:00 -07:00
|
|
|
|
|
|
|
if cooktop_config == ErdCooktopConfig.PRESENT:
|
|
|
|
cooktop_status: CooktopStatus = self.appliance.get_erd_value(ErdCode.COOKTOP_STATUS)
|
|
|
|
cooktop_entities.append(GeErdBinarySensor(self, ErdCode.COOKTOP_STATUS))
|
|
|
|
|
|
|
|
for (k, v) in cooktop_status.burners.items():
|
|
|
|
if v.exists:
|
2020-12-29 16:29:43 -07:00
|
|
|
prop = self._camel_to_snake(k)
|
|
|
|
cooktop_entities.append(GeErdPropertyBinarySensor(self, ErdCode.COOKTOP_STATUS, prop+".on"))
|
|
|
|
cooktop_entities.append(GeErdPropertyBinarySensor(self, ErdCode.COOKTOP_STATUS, prop+".synchronized"))
|
2020-12-28 22:29:00 -07:00
|
|
|
if not v.on_off_only:
|
2020-12-29 16:29:43 -07:00
|
|
|
cooktop_entities.append(GeErdPropertySensor(self, ErdCode.COOKTOP_STATUS, prop+".power_pct", icon_override="mdi:fire", device_class_override=DEVICE_CLASS_POWER_FACTOR))
|
2020-12-28 22:29:00 -07:00
|
|
|
|
|
|
|
return base_entities + oven_entities + cooktop_entities
|
|
|
|
|
2020-12-29 16:29:43 -07:00
|
|
|
def _single_name(self, erd_code: ErdCode):
|
2020-12-28 22:29:00 -07:00
|
|
|
return erd_code.name.replace(UPPER_OVEN+"_","").replace("_", " ").title()
|
2020-12-29 16:29:43 -07:00
|
|
|
|
|
|
|
def _camel_to_snake(self, s):
|
|
|
|
return ''.join(['_'+c.lower() if c.isupper() else c for c in s]).lstrip('_')
|