mirror of https://github.com/simbaja/ha_gehome.git
parent
d89ba016ef
commit
598bdbb5e1
|
@ -5,7 +5,7 @@ from homeassistant.helpers.entity import Entity
|
||||||
from gehomesdk.erd import ErdCode, ErdApplianceType
|
from gehomesdk.erd import ErdCode, ErdApplianceType
|
||||||
|
|
||||||
from .base import ApplianceApi
|
from .base import ApplianceApi
|
||||||
from ..entities import GeWacClimate, GeErdSensor, GeErdBinarySensor, GeErdOnOffSwitch
|
from ..entities import GeWacClimate, GeErdSensor, GeErdBinarySensor, GeErdSwitch, ErdOnOffBoolConverter
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class WacApi(ApplianceApi):
|
||||||
GeErdSensor(self, ErdCode.AC_AMBIENT_TEMPERATURE),
|
GeErdSensor(self, ErdCode.AC_AMBIENT_TEMPERATURE),
|
||||||
GeErdSensor(self, ErdCode.AC_FAN_SETTING, icon_override="mdi:fan"),
|
GeErdSensor(self, ErdCode.AC_FAN_SETTING, icon_override="mdi:fan"),
|
||||||
GeErdSensor(self, ErdCode.AC_OPERATION_MODE),
|
GeErdSensor(self, ErdCode.AC_OPERATION_MODE),
|
||||||
GeErdOnOffSwitch(self, ErdCode.AC_POWER_STATUS, icon_on_override="mdi:power-on", icon_off_override="mdi:power-off"),
|
GeErdSwitch(self, ErdCode.AC_POWER_STATUS, bool_converter=ErdOnOffBoolConverter(), icon_on_override="mdi:power-on", icon_off_override="mdi:power-off"),
|
||||||
GeErdBinarySensor(self, ErdCode.AC_FILTER_STATUS, device_class_override="problem"),
|
GeErdBinarySensor(self, ErdCode.AC_FILTER_STATUS, device_class_override="problem"),
|
||||||
GeErdSensor(self, ErdCode.WAC_DEMAND_RESPONSE_STATE),
|
GeErdSensor(self, ErdCode.WAC_DEMAND_RESPONSE_STATE),
|
||||||
GeErdSensor(self, ErdCode.WAC_DEMAND_RESPONSE_POWER),
|
GeErdSensor(self, ErdCode.WAC_DEMAND_RESPONSE_POWER),
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
from .options_converter import OptionsConverter
|
from .options_converter import OptionsConverter
|
||||||
|
from .bool_converter import BoolConverter, ErdOnOffBoolConverter
|
||||||
from .ge_entity import GeEntity
|
from .ge_entity import GeEntity
|
||||||
from .ge_erd_entity import GeErdEntity
|
from .ge_erd_entity import GeErdEntity
|
||||||
from .ge_erd_binary_sensor import GeErdBinarySensor
|
from .ge_erd_binary_sensor import GeErdBinarySensor
|
||||||
from .ge_erd_property_binary_sensor import GeErdPropertyBinarySensor
|
from .ge_erd_property_binary_sensor import GeErdPropertyBinarySensor
|
||||||
from .ge_erd_sensor import GeErdSensor
|
from .ge_erd_sensor import GeErdSensor
|
||||||
from .ge_erd_property_sensor import GeErdPropertySensor
|
from .ge_erd_property_sensor import GeErdPropertySensor
|
||||||
from .ge_erd_switch import GeErdSwitch, GeErdOnOffSwitch
|
from .ge_erd_switch import GeErdSwitch
|
||||||
from .ge_water_heater import GeWaterHeater
|
from .ge_water_heater import GeWaterHeater
|
||||||
from .ge_erd_select import GeErdSelect
|
from .ge_erd_select import GeErdSelect
|
||||||
from .ge_climate import GeClimate
|
from .ge_climate import GeClimate
|
|
@ -0,0 +1,19 @@
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from gehomesdk import ErdOnOff
|
||||||
|
|
||||||
|
class BoolConverter:
|
||||||
|
def boolify(self, value: Any) -> bool:
|
||||||
|
return bool(value)
|
||||||
|
def true_value(self) -> Any:
|
||||||
|
return True
|
||||||
|
def false_value(self) -> Any:
|
||||||
|
return False
|
||||||
|
|
||||||
|
class ErdOnOffBoolConverter(BoolConverter):
|
||||||
|
def boolify(self, value: ErdOnOff) -> bool:
|
||||||
|
return value.boolify()
|
||||||
|
def true_value(self) -> Any:
|
||||||
|
return ErdOnOff.ON
|
||||||
|
def false_value(self) -> Any:
|
||||||
|
return ErdOnOff.OFF
|
|
@ -1,8 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.switch import is_on
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from gehomesdk.erd.values import ErdOnOff
|
from gehomesdk import ErdCodeType
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
|
|
||||||
|
from ...devices import ApplianceApi
|
||||||
from .ge_erd_binary_sensor import GeErdBinarySensor
|
from .ge_erd_binary_sensor import GeErdBinarySensor
|
||||||
|
from .bool_converter import BoolConverter
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -10,36 +13,21 @@ class GeErdSwitch(GeErdBinarySensor, SwitchEntity):
|
||||||
"""Switches for boolean ERD codes."""
|
"""Switches for boolean ERD codes."""
|
||||||
device_class = "switch"
|
device_class = "switch"
|
||||||
|
|
||||||
@property
|
def __init__(self, api: ApplianceApi, erd_code: ErdCodeType, bool_converter: BoolConverter = BoolConverter(), erd_override: str = None, icon_on_override: str = None, icon_off_override: str = None, device_class_override: str = None):
|
||||||
def is_on(self) -> bool:
|
super().__init__(api, erd_code, erd_override, icon_on_override, icon_off_override, device_class_override)
|
||||||
"""Return True if switch is on."""
|
self._converter = bool_converter
|
||||||
return bool(self.appliance.get_erd_value(self.erd_code))
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
|
||||||
"""Turn the switch on."""
|
|
||||||
_LOGGER.debug(f"Turning on {self.unique_id}")
|
|
||||||
await self.appliance.async_set_erd_value(self.erd_code, True)
|
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
|
||||||
"""Turn the switch off."""
|
|
||||||
_LOGGER.debug(f"Turning on {self.unique_id}")
|
|
||||||
await self.appliance.async_set_erd_value(self.erd_code, False)
|
|
||||||
|
|
||||||
class GeErdOnOffSwitch(GeErdBinarySensor, SwitchEntity):
|
|
||||||
"""Switches for boolean ERD codes."""
|
|
||||||
device_class = "switch"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return True if switch is on."""
|
"""Return True if switch is on."""
|
||||||
return self.appliance.get_erd_value(self.erd_code) == ErdOnOff.ON
|
return self._converter.boolify(self.appliance.get_erd_value(self.erd_code))
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
_LOGGER.debug(f"Turning on {self.unique_id}")
|
_LOGGER.debug(f"Turning on {self.unique_id}")
|
||||||
await self.appliance.async_set_erd_value(self.erd_code, ErdOnOff.ON)
|
await self.appliance.async_set_erd_value(self.erd_code, self._converter.true_value())
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the switch off."""
|
"""Turn the switch off."""
|
||||||
_LOGGER.debug(f"Turning on {self.unique_id}")
|
_LOGGER.debug(f"Turning on {self.unique_id}")
|
||||||
await self.appliance.async_set_erd_value(self.erd_code, ErdOnOff.OFF)
|
await self.appliance.async_set_erd_value(self.erd_code, self._converter.false_value())
|
||||||
|
|
Loading…
Reference in New Issue