Skip to content

Commit bb344df

Browse files
authored
Merge pull request #155 from plugwise/fix_control_state
Revert bad changes, more improvements found
2 parents 216c7d1 + 2d47463 commit bb344df

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Plugwise module."""
22

3-
__version__ = "0.16.7a2"
3+
__version__ = "0.16.7a4"
44

55
from plugwise.smile import Smile
66
from plugwise.stick import Stick

plugwise/helper.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def _appliance_info_finder(self, appliance: etree, appl: Munch) -> Munch:
480480
appl.model = appl.name = self.smile_name
481481
appl.v_name = "Plugwise B.V."
482482

483-
# Adam: check for ZigBee mac address
483+
# Adam: look for the ZigBee MAC address of the Smile
484484
if self.smile_name == "Adam" and (
485485
found := self._modules.find(".//protocols/zig_bee_coordinator")
486486
):
@@ -700,15 +700,13 @@ def _match_locations(self) -> dict[str, Any]:
700700

701701
def _control_state(self, loc_id: str) -> str | None:
702702
"""Helper-function for _device_data_adam().
703-
Adam: find the thermostat control_state of a location, from LOCATIONS.
703+
Adam: find the thermostat control_state of a location, from DOMAIN_OBJECTS.
704704
Represents the heating/cooling demand-state of the local master thermostat.
705705
Note: heating or cooling can still be active when the setpoint has been reached.
706706
"""
707707
locator = f'location[@id="{loc_id}"]'
708-
if (location := self._locations.find(locator)) is not None:
709-
locator = (
710-
".//actuator_functionalities/thermostat_functionality/control_state"
711-
)
708+
if (location := self._domain_objects.find(locator)) is not None:
709+
locator = './/actuator_functionalities/thermostat_functionality[type="thermostat"]/control_state'
712710
if (ctrl_state := location.find(locator)) is not None:
713711
return ctrl_state.text
714712

@@ -1085,7 +1083,7 @@ def _power_data_peak_value(self, loc: str) -> Munch:
10851083

10861084
def _power_data_from_location(self, loc_id: str) -> dict[str, Any] | None:
10871085
"""Helper-function for smile.py: _get_device_data().
1088-
Collect the power-data based on Location ID.
1086+
Collect the power-data based on Location ID, from LOCATIONS.
10891087
"""
10901088
direct_data: dict[str, any] = {}
10911089
loc = Munch()
@@ -1250,10 +1248,10 @@ def _last_used_schedule(self, loc_id: str, rule_ids: dict[str]) -> str | None:
12501248

12511249
def _object_value(self, obj_id: str, measurement: str) -> float | int | bool | None:
12521250
"""Helper-function for smile.py: _get_device_data() and _device_data_anna().
1253-
Obtain the value/state for the given object.
1251+
Obtain the value/state for the given object from DOMAIN_OBJECTS.
12541252
"""
12551253
val: float | int | None = None
1256-
search = self._locations
1254+
search = self._domain_objects
12571255
locator = (
12581256
f'.//location[@id="{obj_id}"]/logs/point_log'
12591257
f'[type="{measurement}"]/period/measurement'

plugwise/smile.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ async def _smile_detect_legacy(
274274
self, result: etree, dsmrmain: etree
275275
) -> tuple[str, str]:
276276
"""Helper-function for _smile_detect()."""
277+
# Stretch: find the MAC of the zigbee master_controller (= Stick)
277278
if network := result.find(".//module/protocols/master_controller"):
278279
self.smile_zigbee_mac_address = network.find("mac_address").text
279-
# Stretch: check for orphaned Sticks
280+
# Find the active MAC in case there is an orphaned Stick
280281
if zb_networks := result.findall(".//network"):
281282
for zb_network in zb_networks:
282283
if zb_network.find(".//nodes/network_router"):
@@ -332,13 +333,11 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
332333
"""
333334
model: str | None = None
334335
if (gateway := result.find(".//gateway")) is not None:
335-
model = result.find(".//gateway/vendor_model").text
336-
self.smile_fw_version = result.find(".//gateway/firmware_version").text
337-
self.smile_hw_version = result.find(".//gateway/hardware_version").text
338-
if gateway.find("hostname") is not None:
339-
self.smile_hostname = gateway.find("hostname").text
340-
if gateway.find("mac_address") is not None:
341-
self.smile_mac_address = gateway.find("mac_address").text
336+
model = gateway.find("vendor_model").text
337+
self.smile_fw_version = gateway.find("firmware_version").text
338+
self.smile_hw_version = gateway.find("hardware_version").text
339+
self.smile_hostname = gateway.find("hostname").text
340+
self.smile_mac_address = gateway.find("mac_address").text
342341
else:
343342
model = await self._smile_detect_legacy(result, dsmrmain)
344343

@@ -397,8 +396,7 @@ async def _update_domain_objects(self) -> None:
397396

398397
# If Plugwise notifications present:
399398
self._notifications = {}
400-
notifications: etree = self._domain_objects.findall(".//notification")
401-
for notification in notifications:
399+
for notification in self._domain_objects.findall(".//notification"):
402400
try:
403401
msg_id = notification.attrib["id"]
404402
msg_type = notification.find("type").text

tests/test_smile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ async def test_connect_anna_heatpump_cooling(self):
21882188
},
21892189
# Gateway
21902190
"015ae9ea3f964e668e490fa39da3870b": {
2191-
"sensors": {"outdoor_temperature": 20.2}
2191+
"sensors": {"outdoor_temperature": 22.0}
21922192
},
21932193
}
21942194

0 commit comments

Comments
 (0)