Add Cell State sensor to Vallox (#58358)

pull/58036/head^2
Andre Richter 2021-10-25 01:30:09 +02:00 committed by GitHub
parent 5a20d9fce3
commit 2fe758edd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -37,3 +37,10 @@ VALLOX_PROFILE_TO_STR_REPORTABLE = {
STR_TO_VALLOX_PROFILE_SETTABLE = {
value: key for (key, value) in VALLOX_PROFILE_TO_STR_SETTABLE.items()
}
VALLOX_CELL_STATE_TO_STR = {
0: "Heat Recovery",
1: "Cool Recovery",
2: "Bypass",
3: "Defrosting",
}

View File

@ -25,7 +25,13 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateTyp
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import ValloxDataUpdateCoordinator
from .const import DOMAIN, METRIC_KEY_MODE, MODE_ON, VALLOX_PROFILE_TO_STR_REPORTABLE
from .const import (
DOMAIN,
METRIC_KEY_MODE,
MODE_ON,
VALLOX_CELL_STATE_TO_STR,
VALLOX_PROFILE_TO_STR_REPORTABLE,
)
_LOGGER = logging.getLogger(__name__)
@ -106,6 +112,21 @@ class ValloxFilterRemainingSensor(ValloxSensor):
return (now + days_remaining_delta).isoformat()
class ValloxCellStateSensor(ValloxSensor):
"""Child class for cell state reporting."""
@property
def native_value(self) -> StateType:
"""Return the value reported by the sensor."""
super_native_value = super().native_value
if not isinstance(super_native_value, (int, float)):
_LOGGER.debug("Value has unexpected type: %s", type(super_native_value))
return None
return VALLOX_CELL_STATE_TO_STR.get(int(super_native_value))
@dataclass
class ValloxSensorEntityDescription(SensorEntityDescription):
"""Describes Vallox sensor entity."""
@ -137,6 +158,13 @@ SENSORS: tuple[ValloxSensorEntityDescription, ...] = (
device_class=DEVICE_CLASS_TIMESTAMP,
sensor_type=ValloxFilterRemainingSensor,
),
ValloxSensorEntityDescription(
key="cell_state",
name="Cell State",
icon="mdi:swap-horizontal-bold",
metric_key="A_CYC_CELL_STATE",
sensor_type=ValloxCellStateSensor,
),
ValloxSensorEntityDescription(
key="extract_air",
name="Extract Air",