hass.tibber_prices/tests
Julian Pawlowski 0a4af0de2f feat(sensor): convert timing sensors to hour-based display with minute attributes
Convert best_price and peak_price timing sensors to display in hours (UI-friendly)
while retaining minute values in attributes (automation-friendly). This improves
readability in dashboards by using Home Assistant's automatic duration formatting
"1 h 35 min" instead of decimal "1.58 h".

BREAKING CHANGE: State unit changed from minutes to hours for 6 timing sensors.

Affected sensors:
  * best_price_period_duration, best_price_remaining_minutes, best_price_next_in_minutes
  * peak_price_period_duration, peak_price_remaining_minutes, peak_price_next_in_minutes

Migration guide for users:
  - If your automations use {{ state_attr(..., 'remaining_time') }} or similar:
    No action needed - attribute values remain in minutes
  - If your automations use {{ states('sensor.best_price_remaining_minutes') }} directly:
    Update to use the minute attribute instead: {{ state_attr('sensor.best_price_remaining_minutes', 'remaining_minutes') }}
  - If your dashboards display the state value:
    Values now show as "1 h 35 min" instead of "95" - this is the intended improvement
  - If your templates do math with the state: multiply by 60 to convert hours back to minutes
    Before: remaining * 60
    After: remaining_minutes (use attribute directly)

Implementation details:
- Timing sensors now use device_class=DURATION, unit=HOURS, precision=2
- State values converted from minutes to hours via _minutes_to_hours()
- New minute-precision attributes added for automation compatibility:
  * period_duration_minutes (for checking if period is long enough)
  * remaining_minutes (for countdown-based automation logic)
  * next_in_minutes (for time-to-event automation triggers)
- Translation improvements across all 5 languages (en, de, nb, nl, sv):
  * Descriptions now clarify state in hours vs attributes in minutes
  * Long descriptions explain dual-format architecture
  * Usage tips updated to reference minute attributes for automations
  * All translation files synchronized (fixed order, removed duplicates)
- Type safety: Added type assertions (cast) for timing calculator results to
  satisfy Pyright type checking (handles both float and datetime return types)

Home Assistant now automatically formats these durations as "1 h 35 min" for improved
UX, matching the behavior of battery.remaining_time and other duration sensors.

Rationale for breaking change:
The previous minute-based state was unintuitive for users ("95 minutes" doesn't
immediately convey "1.5 hours") and didn't match Home Assistant's standard duration
formatting. The new hour-based state with minute attributes provides:
- Better UX: Automatic "1 h 35 min" formatting in UI
- Full automation compatibility: Minute attributes for all calculation needs
- Consistency: Matches HA's duration sensor pattern (battery, timer, etc.)

Impact: Timing sensors now display in human-readable hours with full backward
compatibility via minute attributes. Users relying on direct state access must
migrate to minute attributes (simple change, documented above).
2025-12-26 16:03:00 +00:00
..
services refactor(currency)!: rename major/minor to base/subunit currency terminology 2025-12-11 08:26:30 +00:00
__init__.py test: add pytest framework and midnight-crossing tests 2025-11-21 23:47:01 +00:00
test_avg_none_fallback.py test(sensors): add comprehensive test coverage for mean/median display 2025-12-18 15:14:22 +00:00
test_best_price_e2e.py refactor(currency)!: rename major/minor to base/subunit currency terminology 2025-12-11 08:26:30 +00:00
test_config_validators.py refactor(config): use negative values for Best Price min_distance 2025-11-22 04:44:57 +00:00
test_coordinator_shutdown.py refactor(currency)!: rename major/minor to base/subunit currency terminology 2025-12-11 08:26:30 +00:00
test_interval_pool_memory_leak.py refactor(interval_pool): improve reliability and test coverage 2025-12-23 10:10:35 +00:00
test_interval_pool_optimization.py refactor(scripts): reorganize and standardize development scripts 2025-11-26 13:11:52 +00:00
test_level_filtering.py fix(period_handlers): normalize flex and min_distance to absolute values 2025-11-22 13:01:01 +00:00
test_lifecycle_state.py fix(sensors): ensure connection/tomorrow_data/lifecycle consistency 2025-11-22 04:45:57 +00:00
test_mean_median_display.py test(sensors): add comprehensive test coverage for mean/median display 2025-12-18 15:14:22 +00:00
test_midnight_handler.py feat(coordinator): add atomic midnight turnover coordination 2025-11-22 04:45:41 +00:00
test_midnight_periods.py fix(periods): Periods are now correctly recalculated after tomorrow prices became available. 2025-12-09 16:57:57 +00:00
test_midnight_turnover.py fix(tests): remove unused mock_config_entry and update price_avg to base currency in percentage calculations 2025-12-13 14:07:16 +00:00
test_minmax_none_fallback.py fix(calculations): handle negative electricity prices correctly 2025-11-22 04:45:23 +00:00
test_next_api_poll.py test(timers): comprehensive timer architecture validation 2025-11-22 04:46:30 +00:00
test_peak_price_e2e.py refactor(currency)!: rename major/minor to base/subunit currency terminology 2025-12-11 08:26:30 +00:00
test_percentage_calculations.py fix(tests): remove unused mock_config_entry and update price_avg to base currency in percentage calculations 2025-12-13 14:07:16 +00:00
test_period_calculation.py test(period): document period calculation testing strategy 2025-11-22 04:47:09 +00:00
test_price_calculations.py refactor: migrate from multi-home to single-home-per-coordinator architecture 2025-11-24 16:24:37 +00:00
test_rating_threshold_validation.py fix(rating): improve gap tolerance to find dominant large blocks 2025-12-22 13:28:25 +00:00
test_resource_cleanup.py test: fix async mocking and add noqa comments for private access 2025-11-25 20:44:39 +00:00
test_sensor_consistency.py refactor: migrate from multi-home to single-home-per-coordinator architecture 2025-11-24 16:24:37 +00:00
test_sensor_timer_assignment.py feat(sensor): convert timing sensors to hour-based display with minute attributes 2025-12-26 16:03:00 +00:00
test_time_service.py test(time): add boundary tolerance and DST handling tests 2025-11-22 04:46:53 +00:00
test_timer_scheduling.py test(timers): comprehensive timer architecture validation 2025-11-22 04:46:30 +00:00
test_tomorrow_data_refresh.py refactor: migrate from multi-home to single-home-per-coordinator architecture 2025-11-24 16:24:37 +00:00
test_user_data_validation.py refactor(coordinator): replace DataFetcher with PriceDataManager 2025-12-23 14:13:43 +00:00