Skip to content

Commit 6e4e4f2

Browse files
committed
Improve type-model checking-correcting
1 parent af13cee commit 6e4e4f2

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

plugwise_usb/nodes/node.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,28 @@
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

52+
TYPE_MODEL: Final[dict[int, tuple[str]]] = {
53+
0: ("Stick"),
54+
1: ("Circle", "Stealth"),
55+
3: ("Switch"),
56+
4: (),
57+
5: ("Sense"),
58+
6: ("Scan"),
59+
7: ("Celsius"),
60+
8: ("Celcius"),
61+
9: ("Stealth"),
62+
}
5463

5564
class PlugwiseBaseNode(FeaturePublisher, ABC):
5665
"""Abstract Base Class for a Plugwise node."""
@@ -512,15 +521,12 @@ async def update_node_details(
512521
self._node_info.model = model_info[0]
513522
# Correct model when node_type doesn't match
514523
# 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]
524+
if self._node_info.node_type is not None:
525+
allowed_models = TYPE_MODEL.get(self._node_info.node_type.value)
526+
if model_info[0] not in allowed_models:
527+
# Replace model_info list
528+
model_info = [allowed_models[0]] # Not Ok for 1 but should not be a problem
529+
self._node_info.model = model_info[0]
524530

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

0 commit comments

Comments
 (0)