Add Controller state sensor to screenlogic (#133827)

This commit is contained in:
Kevin Worrel 2025-01-07 10:02:34 -08:00 committed by GitHub
parent 0dd9845501
commit 42532e9695
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View File

@ -9,7 +9,7 @@ from screenlogicpy.const.data import ATTR, DEVICE, GROUP, VALUE
from screenlogicpy.const.msg import CODE
from screenlogicpy.device_const.chemistry import DOSE_STATE
from screenlogicpy.device_const.pump import PUMP_TYPE
from screenlogicpy.device_const.system import EQUIPMENT_FLAG
from screenlogicpy.device_const.system import CONTROLLER_STATE, EQUIPMENT_FLAG
from homeassistant.components.sensor import (
DOMAIN as SENSOR_DOMAIN,
@ -41,7 +41,7 @@ class ScreenLogicSensorDescription(
):
"""Describes a ScreenLogic sensor."""
value_mod: Callable[[int | str], int | str] | None = None
value_mod: Callable[[int | str], int | str | None] | None = None
@dataclasses.dataclass(frozen=True, kw_only=True)
@ -60,6 +60,18 @@ SUPPORTED_CORE_SENSORS = [
state_class=SensorStateClass.MEASUREMENT,
translation_key="air_temperature",
),
ScreenLogicPushSensorDescription(
subscription_code=CODE.STATUS_CHANGED,
data_root=(DEVICE.CONTROLLER, GROUP.SENSOR),
key=VALUE.STATE,
device_class=SensorDeviceClass.ENUM,
options=["ready", "sync", "service"],
value_mod=lambda val: (
CONTROLLER_STATE(val).name.lower() if val in [1, 2, 3] else None
),
entity_category=EntityCategory.DIAGNOSTIC,
translation_key="controller_state",
),
]
SUPPORTED_PUMP_SENSORS = [
@ -344,7 +356,7 @@ class ScreenLogicSensor(ScreenLogicEntity, SensorEntity):
)
@property
def native_value(self) -> str | int | float:
def native_value(self) -> str | int | float | None:
"""State of the sensor."""
val = self.entity_data[ATTR.VALUE]
value_mod = self.entity_description.value_mod

View File

@ -184,6 +184,14 @@
"air_temperature": {
"name": "Air temperature"
},
"controller_state": {
"name": "Controller state",
"state": {
"ready": "Ready",
"sync": "Sync",
"service": "Service"
}
},
"chem_now": {
"name": "{chem} now"
},