fix(sensors): use consistent rounding for trend duration calculations
Some checks are pending
Lint / Ruff (push) Waiting to run
Validate / Hassfest validation (push) Waiting to run
Validate / HACS validation (push) Waiting to run

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.
This commit is contained in:
Julian Pawlowski 2026-04-10 09:13:32 +00:00
parent faa3b2b71a
commit 2a08515ba0

View file

@ -606,13 +606,13 @@ class TibberPricesTrendCalculator(TibberPricesBaseCalculator):
if trend_start_time: if trend_start_time:
time = self.coordinator.time time = self.coordinator.time
# Duration is negative of minutes_until (time in the past) # 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 # Calculate minutes until change
minutes_until_change = None minutes_until_change = None
if next_change_time: if next_change_time:
time = self.coordinator.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 = { result = {
"current_trend_state": current_trend_state, "current_trend_state": current_trend_state,
@ -891,7 +891,7 @@ class TibberPricesTrendCalculator(TibberPricesBaseCalculator):
change_time = time.get_interval_time(change_interval) change_time = time.get_interval_time(change_interval)
if change_time: if change_time:
change_price = float(change_interval["total"]) 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) factor = get_display_unit_factor(self.config_entry)
vf = first_change["vol_factor"] vf = first_change["vol_factor"]