mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-05-28 18:43:40 +00:00
fix(sensors): use consistent rounding for trend duration calculations
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:
parent
faa3b2b71a
commit
2a08515ba0
1 changed files with 3 additions and 3 deletions
|
|
@ -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"]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue