Skip to content

Commit 12a1770

Browse files
authored
Merge pull request #344 from plugwise/limit-nodetypes-in-cache
Don't store plus-device in nodetypes cache
2 parents a3ed4d9 + f86812c commit 12a1770

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- 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.
66
- PR [342](https://github.com/plugwise/python-plugwise-usb/pull/342): Improve node_type chaching.
77
- PR [343](https://github.com/plugwise/python-plugwise-usb/pull/343): Improve writing of cache-files.
8+
- PR [344](https://github.com/plugwise/python-plugwise-usb/pull/344): Don't store plus-device in nodetypes cache
89

910
## 0.46.0 - 2025-09-12
1011

plugwise_usb/network/cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def nodetypes(self) -> dict[str, NodeType]:
2727
async def save_cache(self) -> None:
2828
"""Save the node information to file."""
2929
cache_data_to_save: dict[str, str] = {
30-
mac: node_type.name for mac, node_type in self._nodetypes.items()
30+
mac: node_type.name
31+
for mac, node_type in self._nodetypes.items()
32+
if node_type.value > 1
3133
}
3234
_LOGGER.debug("Save NodeTypes for %s Nodes", len(cache_data_to_save))
3335
await self.write_cache(
@@ -55,7 +57,7 @@ async def restore_cache(self) -> None:
5557
except ValueError:
5658
node_type = None
5759

58-
if node_type is None:
60+
if node_type in (None, NodeType.CIRCLE_PLUS):
5961
_LOGGER.warning(
6062
"Invalid NodeType in cache for mac %s: %s", mac, node_value
6163
)

tests/test_usb.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,9 +1711,7 @@ async def makedirs(cache_dir: str, exist_ok: bool) -> None:
17111711
mock_file_stream = MagicMock(readlines=lambda *args, **kwargs: file_chunks_iter)
17121712
with patch("aiofiles.threadpool.sync_open", return_value=mock_file_stream):
17131713
await pw_nw_cache.restore_cache()
1714-
assert pw_nw_cache.nodetypes == {
1715-
"0123456789ABCDEF": pw_api.NodeType.CIRCLE_PLUS,
1716-
}
1714+
assert pw_nw_cache.nodetypes == {}
17171715

17181716
# test with valid data
17191717
mock_read_data = [
@@ -1726,7 +1724,6 @@ async def makedirs(cache_dir: str, exist_ok: bool) -> None:
17261724
with patch("aiofiles.threadpool.sync_open", return_value=mock_file_stream):
17271725
await pw_nw_cache.restore_cache()
17281726
assert pw_nw_cache.nodetypes == {
1729-
"0123456789ABCDEF": pw_api.NodeType.CIRCLE_PLUS,
17301727
"FEDCBA9876543210": pw_api.NodeType.CIRCLE,
17311728
"1298347650AFBECD": pw_api.NodeType.SCAN,
17321729
}
@@ -1738,14 +1735,12 @@ async def makedirs(cache_dir: str, exist_ok: bool) -> None:
17381735
)
17391736
mock_file_stream.writelines.assert_called_with(
17401737
[
1741-
"0123456789ABCDEF;CIRCLE_PLUS\n",
17421738
"FEDCBA9876543210;CIRCLE\n",
17431739
"1298347650AFBECD;SCAN\n",
17441740
"1234ABCD4321FEDC;STEALTH\n",
17451741
]
17461742
)
17471743
assert pw_nw_cache.nodetypes == {
1748-
"0123456789ABCDEF": pw_api.NodeType.CIRCLE_PLUS,
17491744
"FEDCBA9876543210": pw_api.NodeType.CIRCLE,
17501745
"1298347650AFBECD": pw_api.NodeType.SCAN,
17511746
"1234ABCD4321FEDC": pw_api.NodeType.STEALTH,

0 commit comments

Comments
 (0)