Skip to content

Commit dec9a83

Browse files
authored
Merge pull request #351 from plugwise/improve-cache-3
Continuous cache improving
2 parents b757359 + ce5f18e commit dec9a83

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Changelog
22

3+
## v0.47.1 - 2025-09-27
4+
5+
- PR [351](https://github.com/plugwise/python-plugwise-usb/pull/351): Avoid unintentional overwrite of nodetype.cache file at start/reload.
6+
37
## v0.47.0 - 2025-09-26
48

5-
- PR [345](https://github.com/plugwise/python-plugwise-usb/pull/345): New Feature: schedule clock synchronization every 3600 seconds
9+
- PR [345](https://github.com/plugwise/python-plugwise-usb/pull/345): New Feature: schedule clock synchronization every 3600 seconds.
610

711
## v0.46.1 - 2025-09-25
812

plugwise_usb/helpers/cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ async def initialize_cache(self, create_root_folder: bool = False) -> None:
6464
cache_dir = self._get_writable_os_dir()
6565
await makedirs(cache_dir, exist_ok=True)
6666
self._cache_path = cache_dir
67-
6867
self._cache_file = os_path_join(self._cache_path, self._file_name)
69-
self._cache_file_exists = await ospath.exists(self._cache_file)
7068
self._initialized = True
7169
_LOGGER.debug("Start using network cache file: %s", self._cache_file)
7270

@@ -166,6 +164,7 @@ async def read_cache(self) -> dict[str, str]:
166164
_LOGGER.debug("Cache file has no name, return empty cache data")
167165
return current_data
168166

167+
self._cache_file_exists = await ospath.exists(self._cache_file)
169168
if not self._cache_file_exists:
170169
_LOGGER.debug(
171170
"Cache file '%s' does not exist, return empty cache data",

plugwise_usb/network/cache.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ async def restore_cache(self) -> None:
5858
node_type = None
5959

6060
if node_type in (None, NodeType.CIRCLE_PLUS):
61-
_LOGGER.warning(
62-
"Invalid NodeType in cache for mac %s: %s", mac, node_value
61+
_LOGGER.info(
62+
"Invalid NodeType %s found in cache for mac %s, ignoring...",
63+
node_value,
64+
mac,
6365
)
6466
continue
6567
self._nodetypes[mac] = node_type
@@ -69,9 +71,9 @@ async def restore_cache(self) -> None:
6971
str(node_type),
7072
)
7173

72-
async def update_nodetypes(self, mac: str, node_type: NodeType | None) -> None:
74+
async def update_nodetype(self, mac: str, node_type: NodeType | None) -> None:
7375
"""Save node information in cache."""
74-
if node_type is None:
76+
if node_type in (None, NodeType.CIRCLE_PLUS):
7577
return
7678
if (current_node_type := self._nodetypes.get(mac)) is not None:
7779
if current_node_type == node_type:

plugwise_usb/network/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async def update_network_nodetype(self, mac: str, node_type: NodeType) -> None:
184184
"""Update NodeType inside registry and cache."""
185185
if self._network_cache is None or mac == "":
186186
return
187-
await self._network_cache.update_nodetypes(mac, node_type)
187+
await self._network_cache.update_nodetype(mac, node_type)
188188

189189
def update_network_registration(self, mac: str) -> bool:
190190
"""Add a mac to the network registration list return True if it was newly added."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise_usb"
7-
version = "0.47.0"
7+
version = "0.47.1"
88
license = "MIT"
99
keywords = ["home", "automation", "plugwise", "module", "usb"]
1010
classifiers = [

tests/test_usb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ async def makedirs(cache_dir: str, exist_ok: bool) -> None:
17321732

17331733
with patch("aiofiles.threadpool.sync_open", return_value=mock_file_stream):
17341734
# await pw_nw_cache.save_cache()
1735-
await pw_nw_cache.update_nodetypes(
1735+
await pw_nw_cache.update_nodetype(
17361736
"1234ABCD4321FEDC", pw_api.NodeType.STEALTH
17371737
)
17381738
mock_file_stream.writelines.assert_called_with(

0 commit comments

Comments
 (0)