Compare commits

...

1 Commits

Author SHA1 Message Date
Franck Nijhof aec5ed51d9 Fix derivative sensor spike after total_increasing reset 2026-06-17 05:36:27 +00:00
2 changed files with 7 additions and 2 deletions
@@ -546,6 +546,11 @@ class DerivativeSensor(RestoreSensor, SensorEntity):
"%s: Dropping sample as source total_increasing sensor decreased",
self.entity_id,
)
self._last_valid_state_time = (
new_state.state,
new_timestamp,
)
self._write_native_value(Decimal(0))
return
# add latest derivative to the window list
+2 -2
View File
@@ -864,8 +864,8 @@ async def test_total_increasing_reset(hass: HomeAssistant) -> None:
"""Test derivative with total_increasing input where it should ignore the reset."""
times = [0, 20, 30, 35, 40, 50, 60]
values = [0, 10, 30, 40, 0, 10, 40]
expected_times = [0, 20, 30, 35, 50, 60]
expected_values = ["0.00", "0.50", "2.00", "2.00", "1.00", "3.00"]
expected_times = [0, 20, 30, 35, 40, 50, 60]
expected_values = ["0.00", "0.50", "2.00", "2.00", "0.00", "1.00", "3.00"]
_config, entity_id = await _setup_sensor(hass, {"unit_time": UnitOfTime.SECONDS})