Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup DeviceDescriptionCache #1651

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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