From 2a08515ba0aa6a7a467393a4d7cd5573556b3df9 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 10 Apr 2026 09:13:32 +0000 Subject: [PATCH] fix(sensors): use consistent rounding for trend duration calculations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced int(time.minutes_until()) with time.minutes_until_rounded() in trend calculator (3 locations). The int() call truncated values (14.7 → 14) while timing sensors used standard rounding (14.7 → 15). All duration sensors now use the same rounding method (math.floor(seconds/60 + 0.5)), matching HA's timestamp rendering behavior. Impact: Trend countdown values may differ by ±1 minute compared to previous behavior. Consistency across all duration sensors improved. --- custom_components/tibber_prices/sensor/calculators/trend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/tibber_prices/sensor/calculators/trend.py b/custom_components/tibber_prices/sensor/calculators/trend.py index 60e5958..a01703d 100644 --- a/custom_components/tibber_prices/sensor/calculators/trend.py +++ b/custom_components/tibber_prices/sensor/calculators/trend.py @@ -606,13 +606,13 @@ class TibberPricesTrendCalculator(TibberPricesBaseCalculator): if trend_start_time: time = self.coordinator.time # Duration is negative of minutes_until (time in the past) - trend_duration_minutes = -int(time.minutes_until(trend_start_time)) + trend_duration_minutes = -time.minutes_until_rounded(trend_start_time) # Calculate minutes until change minutes_until_change = None if next_change_time: time = self.coordinator.time - minutes_until_change = int(time.minutes_until(next_change_time)) + minutes_until_change = time.minutes_until_rounded(next_change_time) result = { "current_trend_state": current_trend_state, @@ -891,7 +891,7 @@ class TibberPricesTrendCalculator(TibberPricesBaseCalculator): change_time = time.get_interval_time(change_interval) if change_time: change_price = float(change_interval["total"]) - minutes_until = int(time.minutes_until(change_time)) + minutes_until = time.minutes_until_rounded(change_time) factor = get_display_unit_factor(self.config_entry) vf = first_change["vol_factor"]