diff --git a/CHANGELOG.md b/CHANGELOG.md index 68744d125..04a8aa729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/plugwise_usb/network/cache.py b/plugwise_usb/network/cache.py index 06e672ccb..ade46b712 100644 --- a/plugwise_usb/network/cache.py +++ b/plugwise_usb/network/cache.py @@ -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( @@ -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 ) diff --git a/tests/test_usb.py b/tests/test_usb.py index fae43238c..59ce895f3 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -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 = [ @@ -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, } @@ -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,