From 735bb62d199fb59c3b65106ddc05eebb0bfc13bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Seux?= Date: Fri, 5 Jul 2024 09:22:43 +0200 Subject: [PATCH] Improve integral sensor behavior Using new max_sub_interval we can control how often integral are updated in case the source sensor is constant. --- custom_components/aquarea/sensor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/aquarea/sensor.py b/custom_components/aquarea/sensor.py index 87189aa..7d4ef1c 100644 --- a/custom_components/aquarea/sensor.py +++ b/custom_components/aquarea/sensor.py @@ -4,6 +4,7 @@ from typing import Any, Optional from dataclasses import dataclass from collections.abc import Callable +from datetime import timedelta from homeassistant.components import mqtt from homeassistant.components.sensor import ( @@ -193,7 +194,8 @@ async def async_setup_entry( unique_id=f"{sensor._attr_unique_id}_integration", unit_prefix="k", unit_time=UnitOfTime.HOURS, - max_sub_interval=None, + # update integral at least once every 5 minutes, even if source does not change + max_sub_interval=timedelta(minutes=5), device_info=sensor.device_info, )) async_add_entities(integration_sensors)