From d624c6340960f3882ec878f6d230ebb31fc5f621 Mon Sep 17 00:00:00 2001 From: Jakub Cermak Date: Mon, 29 Dec 2025 23:03:24 +0000 Subject: [PATCH 1/2] Fixing state_class for ecowitt rain sensors --- homeassistant/components/ecowitt/sensor.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/ecowitt/sensor.py b/homeassistant/components/ecowitt/sensor.py index 5044dd4415555e..945308f53e6fd9 100644 --- a/homeassistant/components/ecowitt/sensor.py +++ b/homeassistant/components/ecowitt/sensor.py @@ -257,6 +257,23 @@ ), } +RAIN_TOTAL_INCREASING_SENSOR_KEYS: Final = ( + "totalrainin", + "eventrainin", + "hourlyrainin", + "dailyrainin", + "weeklyrainin", + "monthlyrainin", + "yearlyrainin", + "totalrainmm", + "eventrainmm", + "hourlyrainmm", + "dailyrainmm", + "weeklyrainmm", + "monthlyrainmm", + "yearlyrainmm", +) + async def async_setup_entry( hass: HomeAssistant, @@ -286,10 +303,7 @@ def _new_sensor(sensor: EcoWittSensor) -> None: ) # Only total rain needs state class for long-term statistics - if sensor.key in ( - "totalrainin", - "totalrainmm", - ): + if sensor.key in RAIN_TOTAL_INCREASING_SENSOR_KEYS: description = dataclasses.replace( description, state_class=SensorStateClass.TOTAL_INCREASING, From 84de5ba35592324f01056b3743292f62db12548b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8Cerm=C3=A1k?= Date: Tue, 30 Dec 2025 00:51:35 +0100 Subject: [PATCH 2/2] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- homeassistant/components/ecowitt/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/ecowitt/sensor.py b/homeassistant/components/ecowitt/sensor.py index 945308f53e6fd9..9579520748de24 100644 --- a/homeassistant/components/ecowitt/sensor.py +++ b/homeassistant/components/ecowitt/sensor.py @@ -302,7 +302,7 @@ def _new_sensor(sensor: EcoWittSensor) -> None: name=sensor.name, ) - # Only total rain needs state class for long-term statistics + # Rain sensors with cumulative values need state class for long-term statistics if sensor.key in RAIN_TOTAL_INCREASING_SENSOR_KEYS: description = dataclasses.replace( description,