- added additional protections for water filter position setting

This commit is contained in:
Jack Simbach 2021-07-21 13:51:02 -04:00
parent e2bddfc56a
commit 3fa80c8f04
1 changed files with 28 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import logging import logging
from typing import List, Any, Optional from typing import List, Any, Optional
from gehomesdk import ErdCodeType, ErdWaterFilterPosition from gehomesdk import ErdCodeType, ErdWaterFilterPosition, ErdCode, ErdWaterFilterMode
from ...devices import ApplianceApi from ...devices import ApplianceApi
from ..common import GeErdSelect, OptionsConverter from ..common import GeErdSelect, OptionsConverter
@ -29,8 +29,35 @@ class GeErdFilterPositionSelect(GeErdSelect):
def __init__(self, api: ApplianceApi, erd_code: ErdCodeType): def __init__(self, api: ApplianceApi, erd_code: ErdCodeType):
super().__init__(api, erd_code, FilterPositionOptionsConverter()) super().__init__(api, erd_code, FilterPositionOptionsConverter())
@property
def current_option(self):
"""Return the current selected option"""
#if we're transitioning or don't know what the mode is, don't allow changes
mode: ErdWaterFilterMode = self.appliance.get_erd_value(ErdCode.WH_FILTER_MODE)
if mode in [ErdWaterFilterMode.TRANSITION, ErdWaterFilterMode.UNKNOWN]:
return mode.name.title()
return self._converter.to_option_string(self.appliance.get_erd_value(self.erd_code))
@property
def options(self) -> List[str]:
"""Return a list of options"""
#if we're transitioning or don't know what the mode is, don't allow changes
mode: ErdWaterFilterMode = self.appliance.get_erd_value(ErdCode.WH_FILTER_MODE)
if mode in [ErdWaterFilterMode.TRANSITION, ErdWaterFilterMode.UNKNOWN]:
return mode.name.title()
return self._converter.options
async def async_select_option(self, option: str) -> None: async def async_select_option(self, option: str) -> None:
value = self._converter.from_option_string(option) value = self._converter.from_option_string(option)
if value in [ErdWaterFilterPosition.UNKNOWN, ErdWaterFilterPosition.READY]: if value in [ErdWaterFilterPosition.UNKNOWN, ErdWaterFilterPosition.READY]:
_LOGGER.debug("Cannot set position to ready/unknown")
return return
if self.appliance.get_erd_value(self.erd_code) != ErdWaterFilterPosition.READY:
_LOGGER.debug("Cannot set position if not ready")
return
return await super().async_select_option(option) return await super().async_select_option(option)