|
17 | 17 | from homeassistant.loader import async_get_integration |
18 | 18 |
|
19 | 19 | from custom_components.powercalc.const import API_URL, BUILT_IN_LIBRARY_DIR, DOMAIN |
20 | | -from custom_components.powercalc.helpers import async_cache |
| 20 | +from custom_components.powercalc.helpers import async_cache, clear_async_cache |
21 | 21 | from custom_components.powercalc.power_profile.error import LibraryLoadingError, ProfileDownloadError |
22 | 22 | from custom_components.powercalc.power_profile.loader.protocol import Loader |
23 | 23 | from custom_components.powercalc.power_profile.power_profile import DeviceType, DiscoveryBy |
@@ -66,6 +66,7 @@ async def initialize(self) -> None: |
66 | 66 | integration = await async_get_integration(self.hass, DOMAIN) |
67 | 67 | powercalc_version = AwesomeVersion(str(integration.version)) |
68 | 68 |
|
| 69 | + self._clear_caches() |
69 | 70 | self.library_contents = await self.load_library_json() |
70 | 71 | self.profile_hashes = await self.hass.async_add_executor_job(self._load_profile_hashes) |
71 | 72 |
|
@@ -123,6 +124,15 @@ async def initialize(self) -> None: |
123 | 124 | self.manufacturer_models[manufacturer_name] = kept_models |
124 | 125 | self.model_lookup[manufacturer_name] = lookup |
125 | 126 |
|
| 127 | + def _clear_caches(self) -> None: |
| 128 | + """Clear cached lookups backed by mutable library state.""" |
| 129 | + clear_async_cache(self.get_manufacturer_listing) |
| 130 | + clear_async_cache(self.find_manufacturers) |
| 131 | + clear_async_cache(self.get_model_listing) |
| 132 | + clear_async_cache(self.find_model) |
| 133 | + clear_async_cache(self.find_model_migration) |
| 134 | + clear_async_cache(self.load_model) |
| 135 | + |
126 | 136 | async def load_library_json(self) -> dict[str, Any]: |
127 | 137 | """Load library.json file""" |
128 | 138 |
|
|
0 commit comments