hass.tibber_prices/custom_components/tibber_prices/api
Julian Pawlowski 87f0022baa fix(api): handle None values in API responses to prevent AttributeError
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
2025-12-13 14:02:30 +00:00
..
__init__.py fix(imports): update imports after utils package reorganization 2025-11-18 20:07:28 +00:00
client.py feat(coordinator): implement repairs system for proactive user notifications 2025-12-07 20:51:43 +00:00
exceptions.py refactor: resolve circular imports and enhance documentation 2025-11-18 17:32:36 +00:00
helpers.py fix(api): handle None values in API responses to prevent AttributeError 2025-12-13 14:02:30 +00:00
queries.py feat(interval-pool): add intelligent interval caching and memory optimization 2025-11-25 20:44:39 +00:00