aiohomematic 2025.8.7__py3-none-any.whl → 2025.8.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aiohomematic might be problematic. Click here for more details.
- aiohomematic/caches/dynamic.py +8 -12
- aiohomematic/caches/persistent.py +27 -22
- aiohomematic/caches/visibility.py +275 -252
- aiohomematic/central/__init__.py +26 -31
- aiohomematic/const.py +103 -76
- aiohomematic/model/calculated/__init__.py +3 -3
- aiohomematic/model/calculated/data_point.py +5 -1
- aiohomematic/model/custom/data_point.py +4 -0
- aiohomematic/model/data_point.py +16 -3
- aiohomematic/model/device.py +35 -64
- aiohomematic/model/hub/__init__.py +5 -9
- aiohomematic/model/hub/data_point.py +4 -0
- aiohomematic/model/update.py +4 -0
- aiohomematic/rega_scripts/fetch_all_device_data.fn +48 -31
- aiohomematic/support.py +15 -2
- {aiohomematic-2025.8.7.dist-info → aiohomematic-2025.8.9.dist-info}/METADATA +1 -1
- {aiohomematic-2025.8.7.dist-info → aiohomematic-2025.8.9.dist-info}/RECORD +20 -20
- {aiohomematic-2025.8.7.dist-info → aiohomematic-2025.8.9.dist-info}/WHEEL +0 -0
- {aiohomematic-2025.8.7.dist-info → aiohomematic-2025.8.9.dist-info}/licenses/LICENSE +0 -0
- {aiohomematic-2025.8.7.dist-info → aiohomematic-2025.8.9.dist-info}/top_level.txt +0 -0
aiohomematic/caches/dynamic.py
CHANGED
|
@@ -25,11 +25,13 @@ from collections.abc import Mapping
|
|
|
25
25
|
from datetime import datetime
|
|
26
26
|
import logging
|
|
27
27
|
from typing import Any, Final, cast
|
|
28
|
+
from urllib.parse import unquote
|
|
28
29
|
|
|
29
30
|
from aiohomematic import central as hmcu
|
|
30
31
|
from aiohomematic.const import (
|
|
31
32
|
DP_KEY_VALUE,
|
|
32
33
|
INIT_DATETIME,
|
|
34
|
+
ISO_8859_1,
|
|
33
35
|
LAST_COMMAND_SEND_STORE_TIMEOUT,
|
|
34
36
|
MAX_CACHE_AGE,
|
|
35
37
|
NO_CACHE_ENTRY,
|
|
@@ -272,7 +274,6 @@ class CentralDataCache:
|
|
|
272
274
|
|
|
273
275
|
__slots__ = (
|
|
274
276
|
"_central",
|
|
275
|
-
"_escaped_channel_cache",
|
|
276
277
|
"_refreshed_at",
|
|
277
278
|
"_value_cache",
|
|
278
279
|
)
|
|
@@ -283,7 +284,6 @@ class CentralDataCache:
|
|
|
283
284
|
# { key, value}
|
|
284
285
|
self._value_cache: Final[dict[Interface, Mapping[str, Any]]] = {}
|
|
285
286
|
self._refreshed_at: Final[dict[Interface, datetime]] = {}
|
|
286
|
-
self._escaped_channel_cache: Final[dict[str, str]] = {}
|
|
287
287
|
|
|
288
288
|
async def load(self, direct_call: bool = False, interface: Interface | None = None) -> None:
|
|
289
289
|
"""Fetch data from backend."""
|
|
@@ -310,7 +310,10 @@ class CentralDataCache:
|
|
|
310
310
|
|
|
311
311
|
def add_data(self, interface: Interface, all_device_data: Mapping[str, Any]) -> None:
|
|
312
312
|
"""Add data to cache."""
|
|
313
|
-
self._value_cache[interface] =
|
|
313
|
+
self._value_cache[interface] = {
|
|
314
|
+
unquote(string=k, encoding=ISO_8859_1): unquote(string=v, encoding=ISO_8859_1) if isinstance(v, str) else v
|
|
315
|
+
for k, v in all_device_data.items()
|
|
316
|
+
}
|
|
314
317
|
self._refreshed_at[interface] = datetime.now()
|
|
315
318
|
|
|
316
319
|
def get_data(
|
|
@@ -320,14 +323,8 @@ class CentralDataCache:
|
|
|
320
323
|
parameter: str,
|
|
321
324
|
) -> Any:
|
|
322
325
|
"""Get data from cache."""
|
|
323
|
-
if not self._is_empty(interface=interface):
|
|
324
|
-
|
|
325
|
-
if (escaped := self._escaped_channel_cache.get(channel_address)) is None:
|
|
326
|
-
escaped = channel_address.replace(":", "%3A") if ":" in channel_address else channel_address
|
|
327
|
-
self._escaped_channel_cache[channel_address] = escaped
|
|
328
|
-
key = f"{interface}.{escaped}.{parameter}"
|
|
329
|
-
if (iface_cache := self._value_cache.get(interface)) is not None:
|
|
330
|
-
return iface_cache.get(key, NO_CACHE_ENTRY)
|
|
326
|
+
if not self._is_empty(interface=interface) and (iface_cache := self._value_cache.get(interface)) is not None:
|
|
327
|
+
return iface_cache.get(f"{interface}.{channel_address}.{parameter}", NO_CACHE_ENTRY)
|
|
331
328
|
return NO_CACHE_ENTRY
|
|
332
329
|
|
|
333
330
|
def clear(self, interface: Interface | None = None) -> None:
|
|
@@ -335,7 +332,6 @@ class CentralDataCache:
|
|
|
335
332
|
if interface:
|
|
336
333
|
self._value_cache[interface] = {}
|
|
337
334
|
self._refreshed_at[interface] = INIT_DATETIME
|
|
338
|
-
self._escaped_channel_cache.clear()
|
|
339
335
|
else:
|
|
340
336
|
for _interface in self._central.interfaces:
|
|
341
337
|
self.clear(interface=_interface)
|
|
@@ -208,9 +208,15 @@ class DeviceDescriptionCache(BasePersistentCache):
|
|
|
208
208
|
|
|
209
209
|
def add_device(self, interface_id: str, device_description: DeviceDescription) -> None:
|
|
210
210
|
"""Add a device to the cache."""
|
|
211
|
+
# Fast-path: If the address is not yet known, skip costly removal operations.
|
|
212
|
+
if (address := device_description["ADDRESS"]) not in self._device_descriptions[interface_id]:
|
|
213
|
+
self._raw_device_descriptions[interface_id].append(device_description)
|
|
214
|
+
self._process_device_description(interface_id=interface_id, device_description=device_description)
|
|
215
|
+
return
|
|
216
|
+
# Address exists: remove old entries before adding the new description.
|
|
211
217
|
self._remove_device(
|
|
212
218
|
interface_id=interface_id,
|
|
213
|
-
addresses_to_remove=[
|
|
219
|
+
addresses_to_remove=[address],
|
|
214
220
|
)
|
|
215
221
|
self._raw_device_descriptions[interface_id].append(device_description)
|
|
216
222
|
self._process_device_description(interface_id=interface_id, device_description=device_description)
|
|
@@ -228,23 +234,22 @@ class DeviceDescriptionCache(BasePersistentCache):
|
|
|
228
234
|
|
|
229
235
|
def _remove_device(self, interface_id: str, addresses_to_remove: list[str]) -> None:
|
|
230
236
|
"""Remove a device from the cache."""
|
|
237
|
+
# Use a set for faster membership checks
|
|
238
|
+
addresses_set = set(addresses_to_remove)
|
|
231
239
|
self._raw_device_descriptions[interface_id] = [
|
|
232
|
-
device
|
|
233
|
-
for device in self._raw_device_descriptions[interface_id]
|
|
234
|
-
if device["ADDRESS"] not in addresses_to_remove
|
|
240
|
+
device for device in self._raw_device_descriptions[interface_id] if device["ADDRESS"] not in addresses_set
|
|
235
241
|
]
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return tuple(self._addresses[interface_id].keys())
|
|
242
|
+
addr_map = self._addresses[interface_id]
|
|
243
|
+
desc_map = self._device_descriptions[interface_id]
|
|
244
|
+
for address in addresses_set:
|
|
245
|
+
# Pop with default to avoid KeyError and try/except overhead
|
|
246
|
+
if ADDRESS_SEPARATOR not in address:
|
|
247
|
+
addr_map.pop(address, None)
|
|
248
|
+
desc_map.pop(address, None)
|
|
249
|
+
|
|
250
|
+
def get_addresses(self, interface_id: str) -> frozenset[str]:
|
|
251
|
+
"""Return the addresses by interface as a set."""
|
|
252
|
+
return frozenset(self._addresses[interface_id])
|
|
248
253
|
|
|
249
254
|
def get_device_descriptions(self, interface_id: str) -> Mapping[str, DeviceDescription]:
|
|
250
255
|
"""Return the devices by interface."""
|
|
@@ -288,9 +293,10 @@ class DeviceDescriptionCache(BasePersistentCache):
|
|
|
288
293
|
device_address = get_device_address(address)
|
|
289
294
|
self._device_descriptions[interface_id][address] = device_description
|
|
290
295
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
296
|
+
# Avoid redundant membership checks; set.add is idempotent and cheaper than check+add
|
|
297
|
+
addr_set = self._addresses[interface_id][device_address]
|
|
298
|
+
addr_set.add(device_address)
|
|
299
|
+
addr_set.add(address)
|
|
294
300
|
|
|
295
301
|
async def load(self) -> DataOperationResult:
|
|
296
302
|
"""Load device data from disk into _device_description_cache."""
|
|
@@ -420,13 +426,12 @@ class ParamsetDescriptionCache(BasePersistentCache):
|
|
|
420
426
|
def _add_address_parameter(self, channel_address: str, paramsets: list[dict[str, Any]]) -> None:
|
|
421
427
|
"""Add address parameter to cache."""
|
|
422
428
|
device_address, channel_no = get_split_channel_address(channel_address)
|
|
429
|
+
cache = self._address_parameter_cache
|
|
423
430
|
for paramset in paramsets:
|
|
424
431
|
if not paramset:
|
|
425
432
|
continue
|
|
426
433
|
for parameter in paramset:
|
|
427
|
-
|
|
428
|
-
self._address_parameter_cache[(device_address, parameter)] = set()
|
|
429
|
-
self._address_parameter_cache[(device_address, parameter)].add(channel_no)
|
|
434
|
+
cache.setdefault((device_address, parameter), set()).add(channel_no)
|
|
430
435
|
|
|
431
436
|
async def load(self) -> DataOperationResult:
|
|
432
437
|
"""Load paramset descriptions from disk into paramset cache."""
|