- added oven light selections

This commit is contained in:
Jack Simbach 2021-12-11 18:41:07 -05:00
parent d0e46ed607
commit 034d0df558
3 changed files with 76 additions and 1 deletions

View File

@ -9,7 +9,8 @@ from gehomesdk import (
ErdApplianceType, ErdApplianceType,
OvenConfiguration, OvenConfiguration,
ErdCooktopConfig, ErdCooktopConfig,
CooktopStatus CooktopStatus,
ErdOvenLightLevelAvailability
) )
from .base import ApplianceApi from .base import ApplianceApi
@ -20,6 +21,7 @@ from ..entities import (
GeErdPropertySensor, GeErdPropertySensor,
GeErdPropertyBinarySensor, GeErdPropertyBinarySensor,
GeOven, GeOven,
GeOvenLightLevelSelect,
UPPER_OVEN, UPPER_OVEN,
LOWER_OVEN LOWER_OVEN
) )
@ -41,6 +43,9 @@ class OvenApi(ApplianceApi):
has_upper_raw_temperature = self.has_erd_code(ErdCode.UPPER_OVEN_RAW_TEMPERATURE) has_upper_raw_temperature = self.has_erd_code(ErdCode.UPPER_OVEN_RAW_TEMPERATURE)
has_lower_raw_temperature = self.has_erd_code(ErdCode.LOWER_OVEN_RAW_TEMPERATURE) has_lower_raw_temperature = self.has_erd_code(ErdCode.LOWER_OVEN_RAW_TEMPERATURE)
upper_light_availability: ErdOvenLightLevelAvailability = self.try_get_erd_value(ErdCode.UPPER_OVEN_LIGHT_AVAILABILITY)
lower_light_availability: ErdOvenLightLevelAvailability = self.try_get_erd_value(ErdCode.LOWER_OVEN_LIGHT_AVAILABILITY)
_LOGGER.debug(f"Oven Config: {oven_config}") _LOGGER.debug(f"Oven Config: {oven_config}")
_LOGGER.debug(f"Cooktop Config: {cooktop_config}") _LOGGER.debug(f"Cooktop Config: {cooktop_config}")
oven_entities = [] oven_entities = []
@ -69,6 +74,8 @@ class OvenApi(ApplianceApi):
oven_entities.append(GeErdSensor(self, ErdCode.UPPER_OVEN_RAW_TEMPERATURE)) oven_entities.append(GeErdSensor(self, ErdCode.UPPER_OVEN_RAW_TEMPERATURE))
if has_lower_raw_temperature: if has_lower_raw_temperature:
oven_entities.append(GeErdSensor(self, ErdCode.LOWER_OVEN_RAW_TEMPERATURE)) oven_entities.append(GeErdSensor(self, ErdCode.LOWER_OVEN_RAW_TEMPERATURE))
if lower_light_availability is None or lower_light_availability.is_available:
oven_entities.append(GeOvenLightLevelSelect(self, ErdCode.LOWER_OVEN_LIGHT))
else: else:
oven_entities.extend([ oven_entities.extend([
GeErdSensor(self, ErdCode.UPPER_OVEN_COOK_MODE, self._single_name(ErdCode.UPPER_OVEN_COOK_MODE)), GeErdSensor(self, ErdCode.UPPER_OVEN_COOK_MODE, self._single_name(ErdCode.UPPER_OVEN_COOK_MODE)),
@ -81,6 +88,8 @@ class OvenApi(ApplianceApi):
]) ])
if has_upper_raw_temperature: if has_upper_raw_temperature:
oven_entities.append(GeErdSensor(self, ErdCode.UPPER_OVEN_RAW_TEMPERATURE, self._single_name(ErdCode.UPPER_OVEN_RAW_TEMPERATURE))) oven_entities.append(GeErdSensor(self, ErdCode.UPPER_OVEN_RAW_TEMPERATURE, self._single_name(ErdCode.UPPER_OVEN_RAW_TEMPERATURE)))
if upper_light_availability is None or upper_light_availability.is_available:
oven_entities.append(GeOvenLightLevelSelect(self, ErdCode.UPPER_OVEN_LIGHT, self._single_name(ErdCode.UPPER_OVEN_LIGHT)))
if cooktop_config == ErdCooktopConfig.PRESENT: if cooktop_config == ErdCooktopConfig.PRESENT:

View File

@ -1,2 +1,3 @@
from .ge_oven import GeOven from .ge_oven import GeOven
from .ge_oven_light_level_select import GeOvenLightLevelSelect
from .const import UPPER_OVEN, LOWER_OVEN from .const import UPPER_OVEN, LOWER_OVEN

View File

@ -0,0 +1,65 @@
import logging
from typing import List, Any, Optional
from gehomesdk import ErdCodeType, ErdOvenLightLevelAvailability, ErdOvenLightLevel, ErdCode
from ...devices import ApplianceApi
from ..common import GeErdSelect, OptionsConverter
_LOGGER = logging.getLogger(__name__)
class OvenLightLevelOptionsConverter(OptionsConverter):
def __init__(self, availability: ErdOvenLightLevelAvailability):
super().__init__()
self.availability = availability
self.excluded_levels = [ErdOvenLightLevel.NOT_AVAILABLE]
if not availability or not availability.has_dimmed:
self.excluded_levels.append(ErdOvenLightLevel.DIM)
@property
def options(self) -> List[str]:
return [i.stringify() for i in ErdOvenLightLevel if i not in self.excluded_levels]
def from_option_string(self, value: str) -> Any:
try:
return ErdOvenLightLevel[value.upper()]
except:
_LOGGER.warn(f"Could not set Oven light level to {value.upper()}")
return ErdOvenLightLevel.OFF
def to_option_string(self, value: ErdOvenLightLevel) -> Optional[str]:
try:
if value is not None:
return value.stringify()
except:
pass
return ErdOvenLightLevel.OFF.stringify()
class GeOvenLightLevelSelect(GeErdSelect):
def __init__(self, api: ApplianceApi, erd_code: ErdCodeType):
self._availability: ErdOvenLightLevelAvailability = api.try_get_erd_value(ErdCode.LOWER_OVEN_LIGHT_AVAILABILITY)
#check to see if we have a status
value: ErdOvenLightLevel = api.try_get_erd_value(erd_code)
self._has_status = value is not None and value != ErdOvenLightLevel.NOT_AVAILABLE
self._assumed_state = ErdOvenLightLevel.OFF
super().__init__(api, erd_code, OvenLightLevelOptionsConverter(self._availability))
def assumed_state(self) -> bool:
return not self._has_status
@property
def current_option(self):
if self.assumed_state:
return self._assumed_state
return self._converter.to_option_string(self.appliance.get_erd_value(self.erd_code))
async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
_LOGGER.debug(f"Setting select from {self.current_option} to {option}")
new_state = self._converter.from_option_string(option)
await self.appliance.async_set_erd_value(self.erd_code, new_state)
self._assumed_state = new_state