mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
refactor(cache): enhance cache validation to support new structure and invalidate old format
This commit is contained in:
parent
6f93bb8288
commit
412cecc126
1 changed files with 19 additions and 0 deletions
|
|
@ -106,11 +106,30 @@ def is_cache_valid(
|
||||||
- No cached data exists
|
- No cached data exists
|
||||||
- Cached data is from a different calendar day (in local timezone)
|
- Cached data is from a different calendar day (in local timezone)
|
||||||
- Midnight turnover has occurred since cache was saved
|
- Midnight turnover has occurred since cache was saved
|
||||||
|
- Cache structure is outdated (pre-v0.15.0 multi-home format)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if cache_data.price_data is None or cache_data.last_price_update is None:
|
if cache_data.price_data is None or cache_data.last_price_update is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Check for old cache structure (multi-home format from v0.14.0)
|
||||||
|
# Old format: {"homes": {home_id: {...}}}
|
||||||
|
# New format: {"home_id": str, "price_info": [...]}
|
||||||
|
if "homes" in cache_data.price_data:
|
||||||
|
_LOGGER.info(
|
||||||
|
"%s Cache has old multi-home structure (v0.14.0), invalidating to fetch fresh data",
|
||||||
|
log_prefix,
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Check for missing required keys in new structure
|
||||||
|
if "price_info" not in cache_data.price_data:
|
||||||
|
_LOGGER.info(
|
||||||
|
"%s Cache missing 'price_info' key, invalidating to fetch fresh data",
|
||||||
|
log_prefix,
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
current_local_date = time.as_local(time.now()).date()
|
current_local_date = time.as_local(time.now()).date()
|
||||||
last_update_local_date = time.as_local(cache_data.last_price_update).date()
|
last_update_local_date = time.as_local(cache_data.last_price_update).date()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue