From 86b0381b96f60d26eae6f932d68ba5e097045081 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 29 May 2025 17:49:57 +0200 Subject: [PATCH 1/9] Debug for testing --- plugwise_usb/nodes/node.py | 15 ++++++++++----- scripts/tests_and_coverage.sh | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index 1c0d74efb..063d9b9b4 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -490,11 +490,18 @@ async def update_node_details( ) -> bool: """Process new node info and return true if all fields are updated.""" complete = True + if node_type is None: + complete = False + else: + self._node_info.node_type = NodeType(node_type) + self._set_cache(CACHE_NODE_TYPE, self._node_info.node_type.value) + if firmware is None: complete = False else: self._node_info.firmware = firmware self._set_cache(CACHE_FIRMWARE, firmware) + if hardware is None: complete = False else: @@ -503,6 +510,7 @@ async def update_node_details( hardware, model_info = version_to_model(hardware) model_info = model_info.split(" ") self._node_info.model = model_info[0] + _LOGGER.debug("NodeType: %s", self._node_info.node_type) # Handle + devices if len(model_info) > 1 and "+" in model_info[1]: self._node_info.model = model_info[0] + " " + model_info[1] @@ -522,16 +530,13 @@ async def update_node_details( if self._node_info.model is not None: self._node_info.name = f"{model_info[0]} {self._node_info.mac[-5:]}" self._set_cache(CACHE_HARDWARE, hardware) + if timestamp is None: complete = False else: self._node_info.timestamp = timestamp self._set_cache(CACHE_NODE_INFO_TIMESTAMP, timestamp) - if node_type is None: - complete = False - else: - self._node_info.node_type = NodeType(node_type) - self._set_cache(CACHE_NODE_TYPE, self._node_info.node_type.value) + await self.save_cache() if timestamp is not None and timestamp > datetime.now(tz=UTC) - timedelta( minutes=5 diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 884a5221b..7e62cab10 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -23,7 +23,8 @@ set +u if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then # Python tests (rerun with debug if failures) - PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ + # PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || + PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ fi if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then From 6acf0141015ebb25788eface11738bb007480c5a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 29 May 2025 19:09:16 +0200 Subject: [PATCH 2/9] Correct model when node_type and model don't match --- plugwise_usb/nodes/node.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index 063d9b9b4..941d0d92f 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -510,7 +510,14 @@ async def update_node_details( hardware, model_info = version_to_model(hardware) model_info = model_info.split(" ") self._node_info.model = model_info[0] - _LOGGER.debug("NodeType: %s", self._node_info.node_type) + if ( + self._node_info.node_type is not None + and ( + correct_model := str(self._node_info.node_type.name).lower() + ) not in self._node_info.model.lower() + ): + self._node_info.model = correct_model.capitalize() + # Handle + devices if len(model_info) > 1 and "+" in model_info[1]: self._node_info.model = model_info[0] + " " + model_info[1] @@ -542,6 +549,7 @@ async def update_node_details( minutes=5 ): await self._available_update_state(True, timestamp) + return complete async def is_online(self) -> bool: From d2d63a89ae4454417f623a2ff5f2cd8defa16a10 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 30 May 2025 08:44:14 +0200 Subject: [PATCH 3/9] Pass correct_model into name as well --- plugwise_usb/nodes/node.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index 941d0d92f..24269b117 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -517,6 +517,7 @@ async def update_node_details( ) not in self._node_info.model.lower() ): self._node_info.model = correct_model.capitalize() + model_info[0] = self._node_info.model # Handle + devices if len(model_info) > 1 and "+" in model_info[1]: From d305ea8116b36148644bc2286a68e0e659e5b7fd Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 30 May 2025 16:06:54 +0200 Subject: [PATCH 4/9] Use front-part of node_type --- plugwise_usb/nodes/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index 24269b117..901c64918 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -513,7 +513,7 @@ async def update_node_details( if ( self._node_info.node_type is not None and ( - correct_model := str(self._node_info.node_type.name).lower() + correct_model := str(self._node_info.node_type.name).lower().split("_")[0] ) not in self._node_info.model.lower() ): self._node_info.model = correct_model.capitalize() From 3628a4d72bcfe12ddf2a3f6f96481fbb7aa1ca84 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 30 May 2025 16:12:49 +0200 Subject: [PATCH 5/9] Remove type info --- plugwise_usb/nodes/node.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index 901c64918..665f7e730 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -510,14 +510,17 @@ async def update_node_details( hardware, model_info = version_to_model(hardware) model_info = model_info.split(" ") self._node_info.model = model_info[0] + # Correct model when node_type doesn't match + # Switch reports hardware version of paired Circle (pw_usb_beta #245) if ( self._node_info.node_type is not None and ( - correct_model := str(self._node_info.node_type.name).lower().split("_")[0] + correct_model := self._node_info.node_type.name.lower().split("_")[0] ) not in self._node_info.model.lower() ): self._node_info.model = correct_model.capitalize() - model_info[0] = self._node_info.model + # Replace model_info list + model_info = [self._node_info.model] # Handle + devices if len(model_info) > 1 and "+" in model_info[1]: From 5b328a7887e046c1907766fc8108572fdfefe843 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 30 May 2025 17:03:59 +0200 Subject: [PATCH 6/9] Back to normal test-output --- scripts/tests_and_coverage.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 7e62cab10..884a5221b 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -23,8 +23,7 @@ set +u if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then # Python tests (rerun with debug if failures) - # PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || - PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ + PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ fi if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then From dd5dc3a988ba1d9959bbb3d773cf4749f3fdd595 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 30 May 2025 20:11:05 +0200 Subject: [PATCH 7/9] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0d3a5d17..9a2790d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.40.1 + +- Improve device Name and Model detection for Switch + ## v0.40.0 - Make auto-joining work: (@bouwew) From 02d4f42178015cd370f06ab1ee5bcfa7fdb539ad Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 30 May 2025 20:11:43 +0200 Subject: [PATCH 8/9] Bump to v0.40.1b0 test-release --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 451bb18ca..856b8852d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise_usb" -version = "v0.40.0" +version = "v0.40.1b0" license = "MIT" keywords = ["home", "automation", "plugwise", "module", "usb"] classifiers = [ From 6cd62edb158ef5a0cac381d576e2151c2e032e2e Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 30 May 2025 20:13:04 +0200 Subject: [PATCH 9/9] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a2790d18..4035116aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## v0.40.1 -- Improve device Name and Model detection for Switch +- Improve device Name and Model detection for Switch [#248](https://github.com/plugwise/python-plugwise-usb/pull/248) ## v0.40.0