From 76e64a05703d4277690c10d8316c12d241fe4627 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 11:15:33 +0200 Subject: [PATCH 1/8] Check for file-exists in read_cache() --- plugwise_usb/helpers/cache.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugwise_usb/helpers/cache.py b/plugwise_usb/helpers/cache.py index ef79cf2af..0a179e863 100644 --- a/plugwise_usb/helpers/cache.py +++ b/plugwise_usb/helpers/cache.py @@ -64,9 +64,7 @@ async def initialize_cache(self, create_root_folder: bool = False) -> None: cache_dir = self._get_writable_os_dir() await makedirs(cache_dir, exist_ok=True) self._cache_path = cache_dir - self._cache_file = os_path_join(self._cache_path, self._file_name) - self._cache_file_exists = await ospath.exists(self._cache_file) self._initialized = True _LOGGER.debug("Start using network cache file: %s", self._cache_file) @@ -166,6 +164,7 @@ async def read_cache(self) -> dict[str, str]: _LOGGER.debug("Cache file has no name, return empty cache data") return current_data + self._cache_file_exists = await ospath.exists(self._cache_file) if not self._cache_file_exists: _LOGGER.debug( "Cache file '%s' does not exist, return empty cache data", From cc9d58617dad9696529e1d4a6616460633445503 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 13:08:20 +0200 Subject: [PATCH 2/8] Correct function-name only a single nodetype update is stored --- plugwise_usb/network/cache.py | 2 +- plugwise_usb/network/registry.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise_usb/network/cache.py b/plugwise_usb/network/cache.py index ade46b712..2cb9431e2 100644 --- a/plugwise_usb/network/cache.py +++ b/plugwise_usb/network/cache.py @@ -69,7 +69,7 @@ async def restore_cache(self) -> None: str(node_type), ) - async def update_nodetypes(self, mac: str, node_type: NodeType | None) -> None: + async def update_nodetype(self, mac: str, node_type: NodeType | None) -> None: """Save node information in cache.""" if node_type is None: return diff --git a/plugwise_usb/network/registry.py b/plugwise_usb/network/registry.py index 679d35efc..feedda1d9 100644 --- a/plugwise_usb/network/registry.py +++ b/plugwise_usb/network/registry.py @@ -184,7 +184,7 @@ async def update_network_nodetype(self, mac: str, node_type: NodeType) -> None: """Update NodeType inside registry and cache.""" if self._network_cache is None or mac == "": return - await self._network_cache.update_nodetypes(mac, node_type) + await self._network_cache.update_nodetype(mac, node_type) def update_network_registration(self, mac: str) -> bool: """Add a mac to the network registration list return True if it was newly added.""" From 32be4751e7082f9283501d69fb8e44931919ccfc Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 13:27:28 +0200 Subject: [PATCH 3/8] Also block adding Circle+ to nodetype-cache --- plugwise_usb/network/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise_usb/network/cache.py b/plugwise_usb/network/cache.py index 2cb9431e2..94235fc0f 100644 --- a/plugwise_usb/network/cache.py +++ b/plugwise_usb/network/cache.py @@ -71,7 +71,7 @@ async def restore_cache(self) -> None: async def update_nodetype(self, mac: str, node_type: NodeType | None) -> None: """Save node information in cache.""" - if node_type is None: + if node_type in (None, NodeType.CIRCLE_PLUS): return if (current_node_type := self._nodetypes.get(mac)) is not None: if current_node_type == node_type: From 3f13bd298c8825f8dc4a95c7cb690be7e1d7c532 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 13:31:19 +0200 Subject: [PATCH 4/8] Adapt shorter functionname in testcode --- tests/test_usb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_usb.py b/tests/test_usb.py index ad4979fb0..7de3159ab 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -1732,7 +1732,7 @@ 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.save_cache() - await pw_nw_cache.update_nodetypes( + await pw_nw_cache.update_nodetype( "1234ABCD4321FEDC", pw_api.NodeType.STEALTH ) mock_file_stream.writelines.assert_called_with( From 1685a55c428ec65363e96b17bd8ca943ab3fa289 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 13:34:44 +0200 Subject: [PATCH 5/8] Bump to v0.47.1a0 test-version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index df84cf0fc..fcd5be364 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise_usb" -version = "0.47.0" +version = "0.47.1a0" license = "MIT" keywords = ["home", "automation", "plugwise", "module", "usb"] classifiers = [ From b21ace796de2cc76d15039740206cbf3c6a4b82d Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 14:37:11 +0200 Subject: [PATCH 6/8] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dd6d43b6..ed92dd003 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # Changelog +## v0.47.1 - 2025-09-27 + +- PR [351](https://github.com/plugwise/python-plugwise-usb/pull/351): Avoid unintentional overwrite of nodetype.cache file at start/reload. + ## v0.47.0 - 2025-09-26 -- PR [345](https://github.com/plugwise/python-plugwise-usb/pull/345): New Feature: schedule clock synchronization every 3600 seconds +- PR [345](https://github.com/plugwise/python-plugwise-usb/pull/345): New Feature: schedule clock synchronization every 3600 seconds. ## v0.46.1 - 2025-09-25 From 8d9fcaae09b662db464849374e6c6ecf64d9ac73 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 16:49:47 +0200 Subject: [PATCH 7/8] Improve debug-message, downgrade to info --- plugwise_usb/network/cache.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugwise_usb/network/cache.py b/plugwise_usb/network/cache.py index 94235fc0f..c098cdbf0 100644 --- a/plugwise_usb/network/cache.py +++ b/plugwise_usb/network/cache.py @@ -58,8 +58,10 @@ async def restore_cache(self) -> None: node_type = None if node_type in (None, NodeType.CIRCLE_PLUS): - _LOGGER.warning( - "Invalid NodeType in cache for mac %s: %s", mac, node_value + _LOGGER.info( + "Invalid NodeType %s found in cache for mac %s, ignoring...", + node_value, + mac, ) continue self._nodetypes[mac] = node_type From ce5f18e3c9651ca7640ec045ce01119180a74ab7 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 27 Sep 2025 16:52:04 +0200 Subject: [PATCH 8/8] Set release-version 0.47.1 in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fcd5be364..1640eeb98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise_usb" -version = "0.47.1a0" +version = "0.47.1" license = "MIT" keywords = ["home", "automation", "plugwise", "module", "usb"] classifiers = [