|
38 | 38 |
|
39 | 39 | _LOGGER = logging.getLogger(__name__) |
40 | 40 |
|
41 | | - |
42 | 41 | NODE_FEATURES = ( |
43 | 42 | NodeFeature.AVAILABLE, |
44 | 43 | NodeFeature.INFO, |
45 | 44 | NodeFeature.PING, |
46 | 45 | ) |
47 | 46 |
|
48 | | - |
49 | 47 | CACHE_FIRMWARE = "firmware" |
50 | 48 | CACHE_NODE_TYPE = "node_type" |
51 | 49 | CACHE_HARDWARE = "hardware" |
52 | 50 | CACHE_NODE_INFO_TIMESTAMP = "node_info_timestamp" |
53 | 51 |
|
| 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 | +} |
54 | 63 |
|
55 | 64 | class PlugwiseBaseNode(FeaturePublisher, ABC): |
56 | 65 | """Abstract Base Class for a Plugwise node.""" |
@@ -512,15 +521,12 @@ async def update_node_details( |
512 | 521 | self._node_info.model = model_info[0] |
513 | 522 | # Correct model when node_type doesn't match |
514 | 523 | # 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] |
524 | 530 |
|
525 | 531 | # Handle + devices |
526 | 532 | if len(model_info) > 1 and "+" in model_info[1]: |
|
0 commit comments