From bc8b9aece766f9f7049fc6f52fce41daea83397d Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 6 Nov 2026 16:22:08 +0100 Subject: [PATCH 1/4] Move if under match-case --- plugwise/smile.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugwise/smile.py b/plugwise/smile.py index 3337b0602..8bba85891 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -185,16 +185,17 @@ async def set_number( For a preset temperature, setpoint picks the heating (setpoint, setpoint_low) or cooling (setpoint_high) value. """ - if key in PRESET_TEMPERATURES: - if (attribute := PRESET_SETPOINT_ATTRIBUTES.get(setpoint)) is None: - raise PlugwiseError(f"Plugwise: invalid preset setpoint {setpoint}") - # An Adam zone is its own location, an Anna thermostat has one - loc_id = self.gw_entities[dev_id].get("location", dev_id) - preset = PRESET_TEMPERATURES[key] - await self.set_preset_temperature(loc_id, preset, temperature, attribute) - return - match key: + case preset if preset in PRESET_TEMPERATURES: + if (attribute := PRESET_SETPOINT_ATTRIBUTES.get(setpoint)) is None: + raise PlugwiseError(f"Plugwise: invalid preset setpoint {setpoint}") + # An Adam zone dev_id is its own location, an Anna/Emma thermostat has one location + loc_id = self.gw_entities[dev_id].get("location", dev_id) + preset = PRESET_TEMPERATURES[key] + await self.set_preset_temperature( + loc_id, preset, temperature, attribute + ) + return case "temperature_offset": await self.set_offset(dev_id, temperature) return From 727fcf909960012e76dd11259fab476a361d37dc Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 6 Nov 2026 16:31:08 +0100 Subject: [PATCH 2/4] Optimize if-else --- plugwise/smile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugwise/smile.py b/plugwise/smile.py index 8bba85891..c2f9e8d91 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -260,12 +260,13 @@ async def set_preset_temperature( # The gateway replaces the whole directive set, so every preset is sent. # The lock keeps a concurrent write from resending a stale value for another preset. async with self._preset_lock: - heating = float(then.get("heating_setpoint")) - cooling = float(then.get("cooling_setpoint")) if attribute == "heating_setpoint": + cooling = float(then.get("cooling_setpoint")) heating = temperature else: cooling = temperature + heating = float(then.get("heating_setpoint")) + # Where a zone may not cool, the stored cooling setpoint is a default nobody can change if ( self._cooling_present From 73a99e3c0f907affcc74a8d9e0068bb5695af4ca Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 6 Nov 2026 16:39:31 +0100 Subject: [PATCH 3/4] Add comment --- plugwise/smile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/smile.py b/plugwise/smile.py index c2f9e8d91..4ee9fbf56 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -302,6 +302,7 @@ async def set_preset_temperature( "" ) await self.call_request(f"{RULES};id={rule_id}", method="put", data=data) + # Update self._domain_objects for testing an update for then in self._domain_objects.findall(locator): then.set(attribute, value) From 9481276f74bbabd615ba9d71f197d88f74252400 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 6 Nov 2026 16:54:35 +0100 Subject: [PATCH 4/4] Update CHANGELOG --- CHANGELOG.md | 4 ++++ plugwise/smile.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41fdef5f0..5d5192cfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Ongoing + +- Code optimizations via PR [#946](https://github.com/plugwise/python-plugwise/pull/946) + ## v1.16.0 - Contribution PR [#940](https://github.com/plugwise/python-plugwise/pull/940) by @MartvanMale: diff --git a/plugwise/smile.py b/plugwise/smile.py index 4ee9fbf56..0eba7822d 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -189,7 +189,7 @@ async def set_number( case preset if preset in PRESET_TEMPERATURES: if (attribute := PRESET_SETPOINT_ATTRIBUTES.get(setpoint)) is None: raise PlugwiseError(f"Plugwise: invalid preset setpoint {setpoint}") - # An Adam zone dev_id is its own location, an Anna/Emma thermostat has one location + # An Adam zone dev_id is its own location, a stand-alone Anna/Emma thermostat has one location loc_id = self.gw_entities[dev_id].get("location", dev_id) preset = PRESET_TEMPERATURES[key] await self.set_preset_temperature(