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 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", diff --git a/plugwise_usb/network/cache.py b/plugwise_usb/network/cache.py index ade46b712..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 @@ -69,9 +71,9 @@ 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: + 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: 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.""" diff --git a/pyproject.toml b/pyproject.toml index df84cf0fc..1640eeb98 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.1" license = "MIT" keywords = ["home", "automation", "plugwise", "module", "usb"] classifiers = [ 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(