From 6e4e4f23fc0a07e58a282a5ce3f89047eeb32d4a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 31 May 2025 09:05:54 +0200 Subject: [PATCH 1/6] Improve type-model checking-correcting --- plugwise_usb/nodes/node.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index 665f7e730..b63f104bf 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -38,19 +38,28 @@ _LOGGER = logging.getLogger(__name__) - NODE_FEATURES = ( NodeFeature.AVAILABLE, NodeFeature.INFO, NodeFeature.PING, ) - CACHE_FIRMWARE = "firmware" CACHE_NODE_TYPE = "node_type" CACHE_HARDWARE = "hardware" CACHE_NODE_INFO_TIMESTAMP = "node_info_timestamp" +TYPE_MODEL: Final[dict[int, tuple[str]]] = { + 0: ("Stick"), + 1: ("Circle", "Stealth"), + 3: ("Switch"), + 4: (), + 5: ("Sense"), + 6: ("Scan"), + 7: ("Celsius"), + 8: ("Celcius"), + 9: ("Stealth"), +} class PlugwiseBaseNode(FeaturePublisher, ABC): """Abstract Base Class for a Plugwise node.""" @@ -512,15 +521,12 @@ async def update_node_details( 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 := self._node_info.node_type.name.lower().split("_")[0] - ) not in self._node_info.model.lower() - ): - self._node_info.model = correct_model.capitalize() - # Replace model_info list - model_info = [self._node_info.model] + if self._node_info.node_type is not None: + allowed_models = TYPE_MODEL.get(self._node_info.node_type.value) + if model_info[0] not in allowed_models: + # Replace model_info list + model_info = [allowed_models[0]] # Not Ok for 1 but should not be a problem + self._node_info.model = model_info[0] # Handle + devices if len(model_info) > 1 and "+" in model_info[1]: From 17190082336c193c9b47d83f77b372ae3f12fe93 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 31 May 2025 09:23:18 +0200 Subject: [PATCH 2/6] Move TYPE_MODEL to constants and import --- plugwise_usb/constants.py | 12 ++++++++++++ plugwise_usb/nodes/node.py | 14 +------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugwise_usb/constants.py b/plugwise_usb/constants.py index eb99c232c..be264db7c 100644 --- a/plugwise_usb/constants.py +++ b/plugwise_usb/constants.py @@ -88,3 +88,15 @@ "070051": "Switch", "080029": "Switch", } + +TYPE_MODEL: Final[dict[int, tuple[str]]] = { + 0: ("Stick"), + 1: ("Circle", "Stealth"), + 3: ("Switch"), + 4: (), + 5: ("Sense"), + 6: ("Scan"), + 7: ("Celsius"), + 8: ("Celcius"), + 9: ("Stealth"), +} diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index b63f104bf..6a6c38a03 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -26,7 +26,7 @@ RelayState, ) from ..connection import StickController -from ..constants import SUPPRESS_INITIALIZATION_WARNINGS, UTF8 +from ..constants import SUPPRESS_INITIALIZATION_WARNINGS, TYPE_MODEL, UTF8 from ..exceptions import FeatureError, NodeError from ..helpers.util import version_to_model from ..messages.requests import NodeInfoRequest, NodePingRequest @@ -49,18 +49,6 @@ CACHE_HARDWARE = "hardware" CACHE_NODE_INFO_TIMESTAMP = "node_info_timestamp" -TYPE_MODEL: Final[dict[int, tuple[str]]] = { - 0: ("Stick"), - 1: ("Circle", "Stealth"), - 3: ("Switch"), - 4: (), - 5: ("Sense"), - 6: ("Scan"), - 7: ("Celsius"), - 8: ("Celcius"), - 9: ("Stealth"), -} - class PlugwiseBaseNode(FeaturePublisher, ABC): """Abstract Base Class for a Plugwise node.""" From 9bc7bfd84d9cd294092beaa1bdf47bcb9101e0cd Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 31 May 2025 09:29:18 +0200 Subject: [PATCH 3/6] Extra guarding required --- 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 6a6c38a03..e0bcd34e5 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -511,7 +511,7 @@ async def update_node_details( # Switch reports hardware version of paired Circle (pw_usb_beta #245) if self._node_info.node_type is not None: allowed_models = TYPE_MODEL.get(self._node_info.node_type.value) - if model_info[0] not in allowed_models: + if allowed_models is not None and model_info[0] not in allowed_models: # Replace model_info list model_info = [allowed_models[0]] # Not Ok for 1 but should not be a problem self._node_info.model = model_info[0] From 7b8761188a579d9140205d57762ea18b96ad8fb7 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 31 May 2025 09:33:02 +0200 Subject: [PATCH 4/6] Bump to v0.40.1b1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 856b8852d..80e822057 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise_usb" -version = "v0.40.1b0" +version = "v0.40.1b1" license = "MIT" keywords = ["home", "automation", "plugwise", "module", "usb"] classifiers = [ From c9644f6086ff397beebcd20cfa30513b2e1fef07 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 31 May 2025 09:42:21 +0200 Subject: [PATCH 5/6] Fix typo --- plugwise_usb/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise_usb/constants.py b/plugwise_usb/constants.py index be264db7c..41bc0d62c 100644 --- a/plugwise_usb/constants.py +++ b/plugwise_usb/constants.py @@ -97,6 +97,6 @@ 5: ("Sense"), 6: ("Scan"), 7: ("Celsius"), - 8: ("Celcius"), + 8: ("Celsius"), 9: ("Stealth"), } From 9c32f557cd8c836062560017f1637d53545fd4ab Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 31 May 2025 09:56:58 +0200 Subject: [PATCH 6/6] Implement review feedback --- plugwise_usb/constants.py | 15 +++++++-------- plugwise_usb/nodes/node.py | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugwise_usb/constants.py b/plugwise_usb/constants.py index 41bc0d62c..2e4f4441c 100644 --- a/plugwise_usb/constants.py +++ b/plugwise_usb/constants.py @@ -90,13 +90,12 @@ } TYPE_MODEL: Final[dict[int, tuple[str]]] = { - 0: ("Stick"), + 0: ("Stick",), 1: ("Circle", "Stealth"), - 3: ("Switch"), - 4: (), - 5: ("Sense"), - 6: ("Scan"), - 7: ("Celsius"), - 8: ("Celsius"), - 9: ("Stealth"), + 3: ("Switch",), + 5: ("Sense",), + 6: ("Scan",), + 7: ("Celsius",), + 8: ("Celsius",), + 9: ("Stealth",), } diff --git a/plugwise_usb/nodes/node.py b/plugwise_usb/nodes/node.py index e0bcd34e5..d73d5933e 100644 --- a/plugwise_usb/nodes/node.py +++ b/plugwise_usb/nodes/node.py @@ -511,9 +511,9 @@ async def update_node_details( # Switch reports hardware version of paired Circle (pw_usb_beta #245) if self._node_info.node_type is not None: allowed_models = TYPE_MODEL.get(self._node_info.node_type.value) - if allowed_models is not None and model_info[0] not in allowed_models: + if allowed_models and model_info[0] not in allowed_models: # Replace model_info list - model_info = [allowed_models[0]] # Not Ok for 1 but should not be a problem + model_info = [allowed_models[0]] # Not correct for 1 but should not be a problem self._node_info.model = model_info[0] # Handle + devices