Skip to content

Commit 63b80d9

Browse files
committed
Remove unused POINTTAPI persistent cache
1 parent bc4d3f9 commit 63b80d9

3 files changed

Lines changed: 1 addition & 141 deletions

File tree

custom_components/bosch/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ async def async_init(self) -> bool:
371371
self.hass, self.config_entry, self.gateway
372372
)
373373
self._data.coordinator = coordinator
374-
await coordinator.async_load_persistent_cache()
375374
device_registry = dr.async_get(self.hass)
376375
device_registry.async_get_or_create(
377376
config_entry_id=self.config_entry.entry_id,

custom_components/bosch/pointtapi_coordinator.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from homeassistant.config_entries import ConfigEntry
1717
from homeassistant.core import HomeAssistant
1818
from homeassistant.exceptions import ConfigEntryAuthFailed
19-
from homeassistant.helpers.storage import Store
2019
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
2120

2221
from .pointtapi_client import PoinTTAPIClient
@@ -56,9 +55,6 @@
5655
# Configuration, diagnostics, energy and device inventories change less often
5756
# than temperatures and operating modes.
5857
SLOW_RESOURCE_REFRESH_INTERVAL = 5 * 60
59-
PERSISTENT_CACHE_VERSION = 1
60-
PERSISTENT_CACHE_MAX_AGE = 7 * 24 * 3600
61-
PERSISTENT_CACHE_SAVE_DELAY = 60
6258
SLOW_RESOURCE_PREFIXES = (
6359
"/gateway",
6460
"/energy",
@@ -67,28 +63,6 @@
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-
)
9266
FAST_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-
12087
async 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 = (

unittests/test_pointtapi_coordinator.py

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for pointtapi_coordinator.py."""
22
from __future__ import annotations
33

4+
import time
45
from unittest.mock import AsyncMock, patch
56

67
import pytest
@@ -425,13 +426,9 @@ async def mock_get(path):
425426
# ── Bulk steady state (discovery-then-bulk, fallback, rediscovery) ──────────
426427

427428

428-
import time
429-
430429
from custom_components.bosch.pointtapi_coordinator import (
431430
HISTORY_HOURLY_PATH,
432431
HISTORY_HOURLY_REFRESH_INTERVAL,
433-
PERSISTENT_CACHE_MAX_AGE,
434-
PERSISTENT_CACHE_SAVE_DELAY,
435432
SLOW_RESOURCE_REFRESH_INTERVAL,
436433
REDISCOVERY_INTERVAL,
437434
PoinTTAPIDataUpdateCoordinator,
@@ -471,66 +468,6 @@ async def mock_get(path):
471468

472469

473470
class TestBulkSteadyState:
474-
@pytest.mark.asyncio
475-
async def test_persistent_cache_loads_only_fresh_slow_resources(self):
476-
coord = _bare_coordinator(AsyncMock())
477-
store = AsyncMock()
478-
store.async_load.return_value = {
479-
"saved_at": time.time(),
480-
"data": {
481-
"/gateway/versionFirmware": {"value": "1.2.3"},
482-
"/gateway/identificationKey": {"value": "secret"},
483-
"/system/appliance/status": {"value": "ready"},
484-
"/zones/zn1/status": {"value": "idle"},
485-
},
486-
}
487-
coord._persistent_store = store
488-
489-
snapshot = await coord.async_load_persistent_cache()
490-
491-
assert snapshot is not None
492-
assert "/gateway/versionFirmware" in coord._slow_data
493-
assert "/gateway/identificationKey" not in coord._slow_data
494-
assert "/system/appliance/status" in coord._slow_data
495-
assert "/zones/zn1/status" not in coord._slow_data
496-
497-
@pytest.mark.asyncio
498-
async def test_expired_persistent_cache_is_ignored(self):
499-
coord = _bare_coordinator(AsyncMock())
500-
store = AsyncMock()
501-
store.async_load.return_value = {
502-
"saved_at": time.time() - PERSISTENT_CACHE_MAX_AGE - 1,
503-
"data": {"/gateway/versionFirmware": {"value": "old"}},
504-
}
505-
coord._persistent_store = store
506-
507-
assert await coord.async_load_persistent_cache() is None
508-
assert coord._slow_data == {}
509-
510-
@pytest.mark.asyncio
511-
async def test_persistent_cache_save_is_delayed_and_allowlisted(self):
512-
coord = _bare_coordinator(AsyncMock())
513-
store = AsyncMock()
514-
coord._persistent_store = store
515-
516-
await coord._async_save_persistent_cache(
517-
{
518-
"/gateway/versionFirmware": {"value": "1.2.3"},
519-
"/gateway/identificationKey": {"value": "secret"},
520-
"/system/appliance/status": {"value": "ready"},
521-
HISTORY_HOURLY_PATH: {"value": []},
522-
}
523-
)
524-
525-
store.async_delay_save.assert_called_once()
526-
data_func, delay = store.async_delay_save.call_args.args
527-
saved = data_func()
528-
assert delay == PERSISTENT_CACHE_SAVE_DELAY
529-
assert "/gateway/versionFirmware" in saved["data"]
530-
assert "/gateway/identificationKey" not in saved["data"]
531-
assert HISTORY_HOURLY_PATH not in saved["data"]
532-
assert "/system/appliance/status" in saved["data"]
533-
534471
def test_bulk_failure_logging_is_throttled(self):
535472
coord = _bare_coordinator(AsyncMock())
536473
coord._bulk_warned_at = 100.0

0 commit comments

Comments
 (0)