mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-30 05:13:40 +00:00
Fixed issue #60 where Tibber API temporarily returning incomplete data (None values during maintenance) caused AttributeError crashes. Root cause: `.get(key, default)` returns None when key exists with None value, causing chained `.get()` calls to crash (None.get() → AttributeError). Changes: - api/helpers.py: Use `or {}` pattern in flatten_price_info() to handle None values (priceInfo, priceInfoRange, today, tomorrow) - entity.py: Use `or {}` pattern in _get_fallback_device_info() for address dict - coordinator/data_fetching.py: Add _validate_user_data() method (67 lines) to reject incomplete API responses before caching - coordinator/data_fetching.py: Modify _get_currency_for_home() to raise exceptions instead of silent EUR fallback - coordinator/data_fetching.py: Add home_id parameter to constructor - coordinator/core.py: Pass home_id to TibberPricesDataFetcher - tests/test_user_data_validation.py: Add 12 test cases for validation logic Architecture improvement: Instead of defensive coding with fallbacks, implement validation to reject incomplete data upfront. This prevents caching temporary API errors and ensures currency is always known (critical for price calculations). Impact: Integration now handles API maintenance periods gracefully without crashes. No silent EUR fallbacks - raises exceptions if currency unavailable, ensuring data integrity. Users see clear errors instead of wrong calculations. Fixes #60 |
||
|---|---|---|
| .. | ||
| services | ||
| __init__.py | ||
| test_avg_none_fallback.py | ||
| test_best_price_e2e.py | ||
| test_cache_age.py | ||
| test_cache_validity.py | ||
| test_cache_validity_after_midnight.py | ||
| test_config_validators.py | ||
| test_coordinator_shutdown.py | ||
| test_interval_pool_memory_leak.py | ||
| test_interval_pool_optimization.py | ||
| test_level_filtering.py | ||
| test_lifecycle_state.py | ||
| test_midnight_handler.py | ||
| test_midnight_periods.py | ||
| test_midnight_turnover.py | ||
| test_minmax_none_fallback.py | ||
| test_next_api_poll.py | ||
| test_peak_price_e2e.py | ||
| test_percentage_calculations.py | ||
| test_period_calculation.py | ||
| test_price_calculations.py | ||
| test_rating_threshold_validation.py | ||
| test_resource_cleanup.py | ||
| test_sensor_consistency.py | ||
| test_sensor_timer_assignment.py | ||
| test_time_service.py | ||
| test_timer_scheduling.py | ||
| test_tomorrow_data_refresh.py | ||
| test_user_data_validation.py | ||