1616from homeassistant .config_entries import ConfigEntry
1717from homeassistant .core import HomeAssistant
1818from homeassistant .exceptions import ConfigEntryAuthFailed
19- from homeassistant .helpers .storage import Store
2019from homeassistant .helpers .update_coordinator import DataUpdateCoordinator , UpdateFailed
2120
2221from .pointtapi_client import PoinTTAPIClient
5655# Configuration, diagnostics, energy and device inventories change less often
5756# than temperatures and operating modes.
5857SLOW_RESOURCE_REFRESH_INTERVAL = 5 * 60
59- PERSISTENT_CACHE_VERSION = 1
60- PERSISTENT_CACHE_MAX_AGE = 7 * 24 * 3600
61- PERSISTENT_CACHE_SAVE_DELAY = 60
6258SLOW_RESOURCE_PREFIXES = (
6359 "/gateway" ,
6460 "/energy" ,
6763 "/programs" ,
6864 "/system/appliance" ,
6965)
70- PERSISTENT_CACHE_PREFIXES = (
71- "/solarCircuits" ,
72- "/system/appliance" ,
73- )
74- PERSISTENT_GATEWAY_PATHS = frozenset (
75- {
76- "/gateway/brand" ,
77- "/gateway/displayType" ,
78- "/gateway/hmip/versionApplication" ,
79- "/gateway/hmip/versionOS" ,
80- "/gateway/productID" ,
81- "/gateway/productType" ,
82- "/gateway/update/lastCheck" ,
83- "/gateway/update/lastUpdate" ,
84- "/gateway/versionFirmware" ,
85- "/gateway/versionFirmwareBuild" ,
86- "/gateway/versionHardware" ,
87- "/gateway/wifi/versionFirmware" ,
88- "/gateway/wifi/versionFirmwareBuild" ,
89- "/gateway/zigbee/versionFirmware" ,
90- }
91- )
9266FAST_DEVICE_RESOURCE_MARKERS = (
9367 "/devices/list" ,
9468 "/etrv/" ,
@@ -110,13 +84,6 @@ def _is_slow_resource(path: str) -> bool:
11084 return path == "/notifications" or path .startswith (SLOW_RESOURCE_PREFIXES )
11185
11286
113- def _is_persistent_cache_resource (path : str ) -> bool :
114- """Return whether a resource is explicitly safe to persist."""
115- return path in PERSISTENT_GATEWAY_PATHS or path .startswith (
116- PERSISTENT_CACHE_PREFIXES
117- )
118-
119-
12087async def _fetch_history_hourly_all (client : PoinTTAPIClient ) -> dict [str , Any ] | None :
12188 """Walk /energy/historyHourly pagination forward to collect every entry.
12289
@@ -310,48 +277,6 @@ def __init__(
310277 self ._fast_bulk_paths : list [str ] = []
311278 self ._slow_data : dict [str , Any ] = {}
312279 self ._last_slow_fetch : float = 0.0
313- self ._persistent_store = Store (
314- hass , PERSISTENT_CACHE_VERSION , f"bosch.pointtapi.{ entry .entry_id } "
315- )
316-
317- async def async_load_persistent_cache (self ) -> dict [str , Any ] | None :
318- """Load the last non-secret resource snapshot for immediate startup state."""
319- try :
320- stored = await self ._persistent_store .async_load ()
321- except Exception as err :
322- _LOGGER .debug ("POINTTAPI persistent cache unavailable: %s" , err )
323- return None
324- if not isinstance (stored , dict ):
325- return None
326- saved_at = stored .get ("saved_at" )
327- snapshot = stored .get ("data" )
328- if (
329- not isinstance (saved_at , (int , float ))
330- or time .time () - saved_at > PERSISTENT_CACHE_MAX_AGE
331- or not isinstance (snapshot , dict )
332- ):
333- return None
334- self ._slow_data = {
335- path : value
336- for path , value in snapshot .items ()
337- if isinstance (path , str ) and _is_persistent_cache_resource (path )
338- }
339- return self ._slow_data
340-
341- async def _async_save_persistent_cache (self , data : dict [str , Any ]) -> None :
342- """Schedule persistence of explicitly allowlisted resource data."""
343- snapshot = {
344- path : value
345- for path , value in data .items ()
346- if _is_persistent_cache_resource (path )
347- }
348- try :
349- self ._persistent_store .async_delay_save (
350- lambda : {"saved_at" : time .time (), "data" : snapshot },
351- PERSISTENT_CACHE_SAVE_DELAY ,
352- )
353- except Exception as err :
354- _LOGGER .debug ("POINTTAPI persistent cache write failed: %s" , err )
355280
356281 @property
357282 def client (self ) -> PoinTTAPIClient :
@@ -397,7 +322,6 @@ async def _fetch(self) -> dict[str, Any]:
397322 if isinstance (history , dict ):
398323 self ._history_hourly_data = history
399324 self ._last_history_hourly_fetch = now
400- await self ._async_save_persistent_cache (data )
401325 return data
402326
403327 slow_due = (
0 commit comments