Skip to content

Commit 1817a4e

Browse files
author
Vilppu Vuorinen
committed
Round target temperatures when they are being set
1 parent adb820e commit 1817a4e

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Changed
99
- Guard against zero Ata device energy meter reading. Latest firmware returns occasional zeroes breaking energy consumption integrations.
10+
- Round temperatures being set to the nearest temperature_increment using round half up.
1011

1112
## [2.11.0] - 2021-10-03
1213
### Added

pymelcloud/ata_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def apply_write(self, state: Dict[str, Any], key: str, value: Any):
156156
flags = state.get(EFFECTIVE_FLAGS, 0)
157157

158158
if key == PROPERTY_TARGET_TEMPERATURE:
159-
state["SetTemperature"] = value
159+
state["SetTemperature"] = self.round_temperature(value)
160160
flags = flags | 0x04
161161
elif key == PROPERTY_OPERATION_MODE:
162162
state["OperationMode"] = _operation_mode_to(value)

pymelcloud/atw_device.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,28 +297,28 @@ def apply_write(self, state: Dict[str, Any], key: str, value: Any):
297297
flags = state.get(EFFECTIVE_FLAGS, 0)
298298

299299
if key == PROPERTY_TARGET_TANK_TEMPERATURE:
300-
state["SetTankWaterTemperature"] = value
300+
state["SetTankWaterTemperature"] = self.round_temperature(value)
301301
flags |= 0x1000000000020
302302
elif key == PROPERTY_OPERATION_MODE:
303303
state["ForcedHotWaterMode"] = value == OPERATION_MODE_FORCE_HOT_WATER
304304
flags |= 0x10000
305305
elif key == PROPERTY_ZONE_1_TARGET_TEMPERATURE:
306-
state["SetTemperatureZone1"] = value
306+
state["SetTemperatureZone1"] = self.round_temperature(value)
307307
flags |= 0x200000080
308308
elif key == PROPERTY_ZONE_2_TARGET_TEMPERATURE:
309-
state["SetTemperatureZone2"] = value
309+
state["SetTemperatureZone2"] = self.round_temperature(value)
310310
flags |= 0x800000200
311311
elif key == PROPERTY_ZONE_1_TARGET_HEAT_FLOW_TEMPERATURE:
312-
state["SetHeatFlowTemperatureZone1"] = value
312+
state["SetHeatFlowTemperatureZone1"] = self.round_temperature(value)
313313
flags |= 0x1000000000000
314314
elif key == PROPERTY_ZONE_1_TARGET_COOL_FLOW_TEMPERATURE:
315-
state["SetCoolFlowTemperatureZone1"] = value
315+
state["SetCoolFlowTemperatureZone1"] = self.round_temperature(value)
316316
flags |= 0x1000000000000
317317
elif key == PROPERTY_ZONE_2_TARGET_HEAT_FLOW_TEMPERATURE:
318-
state["SetHeatFlowTemperatureZone2"] = value
318+
state["SetHeatFlowTemperatureZone2"] = self.round_temperature(value)
319319
flags |= 0x1000000000000
320320
elif key == PROPERTY_ZONE_2_TARGET_COOL_FLOW_TEMPERATURE:
321-
state["SetCoolFlowTemperatureZone2"] = value
321+
state["SetCoolFlowTemperatureZone2"] = self.round_temperature(value)
322322
flags |= 0x1000000000000
323323
elif key == PROPERTY_ZONE_1_OPERATION_MODE:
324324
state["OperationModeZone1"] = value

pymelcloud/device.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ def get_state_prop(self, name: str) -> Optional[Any]:
6060
return None
6161
return self._state.get(name)
6262

63+
def round_temperature(self, temperature: float) -> float:
64+
"""Round a temperature to the nearest temperature increment."""
65+
increment = self.temperature_increment
66+
if temperature < 0:
67+
half_increment = -increment / 2.0
68+
else:
69+
half_increment = increment / 2.0
70+
return round((temperature + half_increment) / increment) * increment
71+
6372
@abstractmethod
6473
def apply_write(self, state: Dict[str, Any], key: str, value: Any):
6574
"""Apply writes to state object.

0 commit comments

Comments
 (0)