Skip to content
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
Expand Up @@ -5,6 +5,7 @@
- PR [337](https://github.com/plugwise/python-plugwise-usb/pull/337): Improve node removal, remove and reset the node as executed by Source, and remove the cache-file.
- PR [342](https://github.com/plugwise/python-plugwise-usb/pull/342): Improve node_type chaching.
- PR [343](https://github.com/plugwise/python-plugwise-usb/pull/343): Improve writing of cache-files.
- PR [344](https://github.com/plugwise/python-plugwise-usb/pull/344): Don't store plus-device in nodetypes cache

## 0.46.0 - 2025-09-12

Expand Down
6 changes: 4 additions & 2 deletions plugwise_usb/network/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def nodetypes(self) -> dict[str, NodeType]:
async def save_cache(self) -> None:
"""Save the node information to file."""
cache_data_to_save: dict[str, str] = {
mac: node_type.name for mac, node_type in self._nodetypes.items()
mac: node_type.name
for mac, node_type in self._nodetypes.items()
if node_type.value > 1
}
_LOGGER.debug("Save NodeTypes for %s Nodes", len(cache_data_to_save))
await self.write_cache(
Expand Down Expand Up @@ -55,7 +57,7 @@ async def restore_cache(self) -> None:
except ValueError:
node_type = None

if node_type is None:
if node_type in (None, NodeType.CIRCLE_PLUS):
_LOGGER.warning(
"Invalid NodeType in cache for mac %s: %s", mac, node_value
)
Expand Down
7 changes: 1 addition & 6 deletions tests/test_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,9 +1711,7 @@ async def makedirs(cache_dir: str, exist_ok: bool) -> None:
mock_file_stream = MagicMock(readlines=lambda *args, **kwargs: file_chunks_iter)
with patch("aiofiles.threadpool.sync_open", return_value=mock_file_stream):
await pw_nw_cache.restore_cache()
assert pw_nw_cache.nodetypes == {
"0123456789ABCDEF": pw_api.NodeType.CIRCLE_PLUS,
}
assert pw_nw_cache.nodetypes == {}

# test with valid data
mock_read_data = [
Expand All @@ -1726,7 +1724,6 @@ async def makedirs(cache_dir: str, exist_ok: bool) -> None:
with patch("aiofiles.threadpool.sync_open", return_value=mock_file_stream):
await pw_nw_cache.restore_cache()
assert pw_nw_cache.nodetypes == {
"0123456789ABCDEF": pw_api.NodeType.CIRCLE_PLUS,
"FEDCBA9876543210": pw_api.NodeType.CIRCLE,
"1298347650AFBECD": pw_api.NodeType.SCAN,
}
Expand All @@ -1738,14 +1735,12 @@ async def makedirs(cache_dir: str, exist_ok: bool) -> None:
)
mock_file_stream.writelines.assert_called_with(
[
"0123456789ABCDEF;CIRCLE_PLUS\n",
"FEDCBA9876543210;CIRCLE\n",
"1298347650AFBECD;SCAN\n",
"1234ABCD4321FEDC;STEALTH\n",
]
)
assert pw_nw_cache.nodetypes == {
"0123456789ABCDEF": pw_api.NodeType.CIRCLE_PLUS,
"FEDCBA9876543210": pw_api.NodeType.CIRCLE,
"1298347650AFBECD": pw_api.NodeType.SCAN,
"1234ABCD4321FEDC": pw_api.NodeType.STEALTH,
Expand Down