Skip to content

Commit 497ee31

Browse files
authored
Merge pull request #249 from plugwise/correct_model_2
Improve PR #248
2 parents af13cee + 9c32f55 commit 497ee31

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

plugwise_usb/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,14 @@
8888
"070051": "Switch",
8989
"080029": "Switch",
9090
}
91+
92+
TYPE_MODEL: Final[dict[int, tuple[str]]] = {
93+
0: ("Stick",),
94+
1: ("Circle", "Stealth"),
95+
3: ("Switch",),
96+
5: ("Sense",),
97+
6: ("Scan",),
98+
7: ("Celsius",),
99+
8: ("Celsius",),
100+
9: ("Stealth",),
101+
}

plugwise_usb/nodes/node.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
RelayState,
2727
)
2828
from ..connection import StickController
29-
from ..constants import SUPPRESS_INITIALIZATION_WARNINGS, UTF8
29+
from ..constants import SUPPRESS_INITIALIZATION_WARNINGS, TYPE_MODEL, UTF8
3030
from ..exceptions import FeatureError, NodeError
3131
from ..helpers.util import version_to_model
3232
from ..messages.requests import NodeInfoRequest, NodePingRequest
@@ -38,20 +38,17 @@
3838

3939
_LOGGER = logging.getLogger(__name__)
4040

41-
4241
NODE_FEATURES = (
4342
NodeFeature.AVAILABLE,
4443
NodeFeature.INFO,
4544
NodeFeature.PING,
4645
)
4746

48-
4947
CACHE_FIRMWARE = "firmware"
5048
CACHE_NODE_TYPE = "node_type"
5149
CACHE_HARDWARE = "hardware"
5250
CACHE_NODE_INFO_TIMESTAMP = "node_info_timestamp"
5351

54-
5552
class PlugwiseBaseNode(FeaturePublisher, ABC):
5653
"""Abstract Base Class for a Plugwise node."""
5754

@@ -512,15 +509,12 @@ async def update_node_details(
512509
self._node_info.model = model_info[0]
513510
# Correct model when node_type doesn't match
514511
# Switch reports hardware version of paired Circle (pw_usb_beta #245)
515-
if (
516-
self._node_info.node_type is not None
517-
and (
518-
correct_model := self._node_info.node_type.name.lower().split("_")[0]
519-
) not in self._node_info.model.lower()
520-
):
521-
self._node_info.model = correct_model.capitalize()
522-
# Replace model_info list
523-
model_info = [self._node_info.model]
512+
if self._node_info.node_type is not None:
513+
allowed_models = TYPE_MODEL.get(self._node_info.node_type.value)
514+
if allowed_models and model_info[0] not in allowed_models:
515+
# Replace model_info list
516+
model_info = [allowed_models[0]] # Not correct for 1 but should not be a problem
517+
self._node_info.model = model_info[0]
524518

525519
# Handle + devices
526520
if len(model_info) > 1 and "+" in model_info[1]:

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 = "v0.40.1b0"
7+
version = "v0.40.1b1"
88
license = "MIT"
99
keywords = ["home", "automation", "plugwise", "module", "usb"]
1010
classifiers = [

0 commit comments

Comments
 (0)