Refactor set_temperature in venstar climate (#145297)

Clarify logic in venstar climate set_temperature
This commit is contained in:
epenet 2025-05-20 11:46:53 +02:00 committed by GitHub
parent c3fe5f012e
commit f2233b3034
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -258,32 +258,28 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
_LOGGER.error("Failed to change the operation mode") _LOGGER.error("Failed to change the operation mode")
return success return success
def set_temperature(self, **kwargs): def set_temperature(self, **kwargs: Any) -> None:
"""Set a new target temperature.""" """Set a new target temperature."""
set_temp = True set_temp = True
operation_mode = kwargs.get(ATTR_HVAC_MODE) operation_mode: HVACMode | None = kwargs.get(ATTR_HVAC_MODE)
temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW) temp_low: float | None = kwargs.get(ATTR_TARGET_TEMP_LOW)
temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH) temp_high: float | None = kwargs.get(ATTR_TARGET_TEMP_HIGH)
temperature = kwargs.get(ATTR_TEMPERATURE) temperature: float | None = kwargs.get(ATTR_TEMPERATURE)
if operation_mode and self._mode_map.get(operation_mode) != self._client.mode: client_mode = self._client.mode
if (
operation_mode
and (new_mode := self._mode_map.get(operation_mode)) != client_mode
):
set_temp = self._set_operation_mode(operation_mode) set_temp = self._set_operation_mode(operation_mode)
client_mode = new_mode
if set_temp: if set_temp:
if ( if client_mode == self._client.MODE_HEAT:
self._mode_map.get(operation_mode, self._client.mode)
== self._client.MODE_HEAT
):
success = self._client.set_setpoints(temperature, self._client.cooltemp) success = self._client.set_setpoints(temperature, self._client.cooltemp)
elif ( elif client_mode == self._client.MODE_COOL:
self._mode_map.get(operation_mode, self._client.mode)
== self._client.MODE_COOL
):
success = self._client.set_setpoints(self._client.heattemp, temperature) success = self._client.set_setpoints(self._client.heattemp, temperature)
elif ( elif client_mode == self._client.MODE_AUTO:
self._mode_map.get(operation_mode, self._client.mode)
== self._client.MODE_AUTO
):
success = self._client.set_setpoints(temp_low, temp_high) success = self._client.set_setpoints(temp_low, temp_high)
else: else:
success = False success = False