Skip to content

Commit af13cee

Browse files
authored
Merge pull request #248 from plugwise/correct_model
Handle mismatch between NodeType and type deducted from hardware-version
2 parents e3e84a4 + 6cd62ed commit af13cee

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.40.1
4+
5+
- Improve device Name and Model detection for Switch [#248](https://github.com/plugwise/python-plugwise-usb/pull/248)
6+
37
## v0.40.0
48

59
- Make auto-joining work: (@bouwew)

plugwise_usb/nodes/node.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,18 @@ async def update_node_details(
490490
) -> bool:
491491
"""Process new node info and return true if all fields are updated."""
492492
complete = True
493+
if node_type is None:
494+
complete = False
495+
else:
496+
self._node_info.node_type = NodeType(node_type)
497+
self._set_cache(CACHE_NODE_TYPE, self._node_info.node_type.value)
498+
493499
if firmware is None:
494500
complete = False
495501
else:
496502
self._node_info.firmware = firmware
497503
self._set_cache(CACHE_FIRMWARE, firmware)
504+
498505
if hardware is None:
499506
complete = False
500507
else:
@@ -503,6 +510,18 @@ async def update_node_details(
503510
hardware, model_info = version_to_model(hardware)
504511
model_info = model_info.split(" ")
505512
self._node_info.model = model_info[0]
513+
# Correct model when node_type doesn't match
514+
# 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+
506525
# Handle + devices
507526
if len(model_info) > 1 and "+" in model_info[1]:
508527
self._node_info.model = model_info[0] + " " + model_info[1]
@@ -522,21 +541,19 @@ async def update_node_details(
522541
if self._node_info.model is not None:
523542
self._node_info.name = f"{model_info[0]} {self._node_info.mac[-5:]}"
524543
self._set_cache(CACHE_HARDWARE, hardware)
544+
525545
if timestamp is None:
526546
complete = False
527547
else:
528548
self._node_info.timestamp = timestamp
529549
self._set_cache(CACHE_NODE_INFO_TIMESTAMP, timestamp)
530-
if node_type is None:
531-
complete = False
532-
else:
533-
self._node_info.node_type = NodeType(node_type)
534-
self._set_cache(CACHE_NODE_TYPE, self._node_info.node_type.value)
550+
535551
await self.save_cache()
536552
if timestamp is not None and timestamp > datetime.now(tz=UTC) - timedelta(
537553
minutes=5
538554
):
539555
await self._available_update_state(True, timestamp)
556+
540557
return complete
541558

542559
async def is_online(self) -> bool:

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

0 commit comments

Comments
 (0)