From 3b7ec8ed2ccdb0e7a1f8d874a82b5e06508d701f Mon Sep 17 00:00:00 2001 From: Caius-Bonus <123886836+Caius-Bonus@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:53:10 +0100 Subject: [PATCH] Use EnumSensor instead of custom formatter() in ZHA Sensor entities (#109218) use EnumSensor for SonofPresenceSensorIlluminationStatus and AqaraPetFeederLastFeedingSource --- homeassistant/components/zha/sensor.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index f4689460f93..15985922ccd 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -1190,17 +1190,14 @@ class AqaraFeedingSource(types.enum8): @MULTI_MATCH(cluster_handler_names="opple_cluster", models={"aqara.feeder.acn001"}) # pylint: disable-next=hass-invalid-inheritance # needs fixing -class AqaraPetFeederLastFeedingSource(Sensor): +class AqaraPetFeederLastFeedingSource(EnumSensor): """Sensor that displays the last feeding source of pet feeder.""" _attribute_name = "last_feeding_source" _unique_id_suffix = "last_feeding_source" _attr_translation_key: str = "last_feeding_source" _attr_icon = "mdi:devices" - - def formatter(self, value: int) -> int | float | None: - """Numeric pass-through formatter.""" - return AqaraFeedingSource(value).name + _enum = AqaraFeedingSource @MULTI_MATCH(cluster_handler_names="opple_cluster", models={"aqara.feeder.acn001"}) @@ -1262,17 +1259,14 @@ class SonoffIlluminationStates(types.enum8): @MULTI_MATCH(cluster_handler_names="sonoff_manufacturer", models={"SNZB-06P"}) # pylint: disable-next=hass-invalid-inheritance # needs fixing -class SonoffPresenceSenorIlluminationStatus(Sensor): +class SonoffPresenceSenorIlluminationStatus(EnumSensor): """Sensor that displays the illumination status the last time peresence was detected.""" _attribute_name = "last_illumination_state" _unique_id_suffix = "last_illumination" _attr_translation_key: str = "last_illumination_state" _attr_icon: str = "mdi:theme-light-dark" - - def formatter(self, value: int) -> int | float | None: - """Numeric pass-through formatter.""" - return SonoffIlluminationStates(value).name + _enum = SonoffIlluminationStates @CONFIG_DIAGNOSTIC_MATCH(cluster_handler_names=CLUSTER_HANDLER_THERMOSTAT)