Skip to content

Commit

Permalink
Cleanup DeviceDescriptionCache (#1651)
Browse files Browse the repository at this point in the history
* Cleanup DeviceDescriptionCache

* Update persistent.py
  • Loading branch information
SukramJ authored Aug 20, 2024
1 parent 6c793c7 commit e23bf07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 2024.8.10 (2024-08-20)

- Cleanup ParamsetDescriptionCache
- Cleanup DeviceDescriptionCache

# Version 2024.8.9 (2024-08-20)

Expand Down
14 changes: 7 additions & 7 deletions hahomematic/caches/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, central: hmcu.CentralUnit) -> None:
persistant_cache=self._raw_device_descriptions,
)
# {interface_id, {device_address, [channel_address]}}
self._addresses: Final[dict[str, dict[str, list[str]]]] = {}
self._addresses: Final[dict[str, dict[str, set[str]]]] = {}
# {interface_id, {address, device_descriptions}}
self._device_descriptions: Final[dict[str, dict[str, dict[str, Any]]]] = {}

Expand Down Expand Up @@ -162,9 +162,9 @@ def _remove_device(self, interface_id: str, deleted_addresses: list[str]) -> Non

for address in deleted_addresses:
try:
if ":" not in address and self._addresses.get(interface_id, {}).get(address, []):
if ":" not in address and self._addresses.get(interface_id, {}).get(address):
del self._addresses[interface_id][address]
if self._device_descriptions.get(interface_id, {}).get(address, {}):
if self._device_descriptions.get(interface_id, {}).get(address):
del self._device_descriptions[interface_id][address]
except KeyError:
_LOGGER.warning("REMOVE_DEVICE failed: Unable to delete: %s", address)
Expand All @@ -176,7 +176,7 @@ def get_addresses(self, interface_id: str) -> tuple[str, ...]:
def get_channels(self, interface_id: str, device_address: str) -> Mapping[str, Channel]:
"""Return the device channels by interface and device_address."""
channels: dict[str, Channel] = {}
for channel_address in self._addresses.get(interface_id, {}).get(device_address, []):
for channel_address in self._addresses.get(interface_id, {}).get(device_address, set()):
channel_name = str(
self.get_device_parameter(
interface_id=interface_id,
Expand Down Expand Up @@ -248,12 +248,12 @@ def _convert_device_description(
self._device_descriptions[interface_id][address] = device_description

if ":" not in address and address not in self._addresses[interface_id]:
self._addresses[interface_id][address] = [address]
self._addresses[interface_id][address] = {address}
if ":" in address:
device_address = get_device_address(address)
if device_address not in self._addresses[interface_id]:
self._addresses[interface_id][device_address] = []
self._addresses[interface_id][device_address].append(address)
self._addresses[interface_id][device_address] = set()
self._addresses[interface_id][device_address].add(address)

async def load(self) -> DataOperationResult:
"""Load device data from disk into _device_description_cache."""
Expand Down

0 comments on commit e23bf07

Please sign in to comment.