- initial support for water softeners

This commit is contained in:
Jack Simbach 2021-12-11 00:36:30 -05:00
parent 65b6efc826
commit 468a8496db
6 changed files with 109 additions and 1 deletions

View File

@ -5,6 +5,7 @@
- Changed the sensors to use native value/uom
- Changed the temperatures to always be natively fahrenheit (API appears to always use this system)
- Initial support for Water Softeners (@npentell)
## 0.5.0

View File

@ -3,6 +3,8 @@ from typing import Type
from gehomesdk.erd import ErdApplianceType
from custom_components.ge_home.devices.water_softener import WaterSoftenerApi
from .base import ApplianceApi
from .oven import OvenApi
from .fridge import FridgeApi
@ -37,6 +39,8 @@ def get_appliance_api_type(appliance_type: ErdApplianceType) -> Type:
return WasherDryerApi
if appliance_type == ErdApplianceType.POE_WATER_FILTER:
return WaterFilterApi
if appliance_type == ErdApplianceType.WATER_SOFTENER:
return WaterSoftenerApi
if appliance_type == ErdApplianceType.ADVANTIUM:
return AdvantiumApi
if appliance_type == ErdApplianceType.AIR_CONDITIONER:

View File

@ -0,0 +1,36 @@
import logging
from typing import List
from homeassistant.helpers.entity import Entity
from gehomesdk import ErdCode, ErdApplianceType
from .base import ApplianceApi
from ..entities import (
GeErdSensor,
GeErdBinarySensor,
GeErdShutoffPositionSelect,
)
_LOGGER = logging.getLogger(__name__)
class WaterSoftenerApi(ApplianceApi):
"""API class for water softener objects"""
APPLIANCE_TYPE = ErdApplianceType.WATER_SOFTENER
def get_all_entities(self) -> List[Entity]:
base_entities = super().get_all_entities()
ws_entities = [
GeErdBinarySensor(self, ErdCode.WH_FILTER_MANUAL_MODE, icon_on_override="mdi:human", icon_off_override="mdi:robot"),
GeErdSensor(self, ErdCode.WH_FILTER_FLOW_RATE),
GeErdBinarySensor(self, ErdCode.WH_FILTER_FLOW_ALERT, device_class_override="moisture"),
GeErdSensor(self, ErdCode.WH_FILTER_DAY_USAGE),
GeErdSensor(self, ErdCode.WH_SOFTENER_ERROR_CODE, icon_override="mdi:alert-circle"),
GeErdSensor(self, ErdCode.WH_SOFTENER_LOW_SALT, icon_override="mdi:grain"),
GeErdSensor(self, ErdCode.WH_SOFTENER_SHUTOFF_VALVE_STATE, icon_override="mdi:state-machine"),
GeErdShutoffPositionSelect(self, ErdCode.WH_SOFTENER_SHUTOFF_VALVE_CONTROL),
]
entities = base_entities + ws_entities
return entities

View File

@ -5,4 +5,5 @@ from .oven import *
from .water_filter import *
from .advantium import *
from .ac import *
from .hood import *
from .hood import *
from .water_softener import *

View File

@ -0,0 +1 @@
from .shutoff_position import GeErdShutoffPositionSelect

View File

@ -0,0 +1,65 @@
import logging
from typing import List, Any, Optional
from gehomesdk import ErdCodeType, ErdWaterSoftenerShutoffValveState, ErdCode
from ...devices import ApplianceApi
from ..common import GeErdSelect, OptionsConverter
_LOGGER = logging.getLogger(__name__)
class FilterPositionOptionsConverter(OptionsConverter):
@property
def options(self) -> List[str]:
return [i.name.title()
for i in ErdWaterSoftenerShutoffValveState
if i not in [ErdWaterSoftenerShutoffValveState.UNKNOWN, ErdWaterSoftenerShutoffValveState.TRANSITION]]
def from_option_string(self, value: str) -> Any:
try:
return ErdWaterSoftenerShutoffValveState[value.upper()]
except:
_LOGGER.warn(f"Could not set filter position to {value.upper()}")
return ErdWaterSoftenerShutoffValveState.UNKNOWN
def to_option_string(self, value: Any) -> Optional[str]:
try:
if value is not None:
return value.name.title()
except:
pass
return ErdWaterSoftenerShutoffValveState.UNKNOWN.name.title()
class GeErdShutoffPositionSelect(GeErdSelect):
def __init__(self, api: ApplianceApi, erd_code: ErdCodeType):
super().__init__(api, erd_code, FilterPositionOptionsConverter(), icon_override="mdi:valve")
@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: ErdWaterSoftenerShutoffValveState = self.appliance.get_erd_value(ErdCode.WH_SOFTENER_SHUTOFF_VALVE_STATE)
if mode in [ErdWaterSoftenerShutoffValveState.TRANSITION, ErdWaterSoftenerShutoffValveState.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: ErdWaterSoftenerShutoffValveState = self.appliance.get_erd_value(ErdCode.WH_SOFTENER_SHUTOFF_VALVE_STATE)
if mode in [ErdWaterSoftenerShutoffValveState.TRANSITION, ErdWaterSoftenerShutoffValveState.UNKNOWN]:
return mode.name.title()
return self._converter.options
async def async_select_option(self, option: str) -> None:
value = self._converter.from_option_string(option)
if value in [ErdWaterSoftenerShutoffValveState.UNKNOWN, ErdWaterSoftenerShutoffValveState.TRANSITION]:
_LOGGER.debug("Cannot set position to transition/unknown")
return
if self.appliance.get_erd_value(ErdCode.WH_SOFTENER_SHUTOFF_VALVE_STATE) == ErdWaterSoftenerShutoffValveState.TRANSITION:
_LOGGER.debug("Cannot set position if in transition")
return
return await super().async_select_option(option)