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 3337b0602..0eba7822d 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, 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( + loc_id, preset, temperature, attribute + ) + return case "temperature_offset": await self.set_offset(dev_id, temperature) return @@ -259,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 @@ -300,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)