From 6a1501b59c4d65ae158213c6a69b65acef06a809 Mon Sep 17 00:00:00 2001 From: Tyler Page Date: Thu, 24 Oct 2019 00:10:57 +0000 Subject: [PATCH] Cover all possible values for venstar operation_mode (#27949) * cover all possible values for operation_mode * Update climate.py * Update climate.py * Update climate.py mapped homeassistant constants to client ones so we don't have to check for both * black + pylint * move mode_map to __init__() * Update climate.py * Update climate.py --- homeassistant/components/venstar/climate.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/venstar/climate.py b/homeassistant/components/venstar/climate.py index 81afef97541..280e691337d 100644 --- a/homeassistant/components/venstar/climate.py +++ b/homeassistant/components/venstar/climate.py @@ -98,6 +98,11 @@ class VenstarThermostat(ClimateDevice): """Initialize the thermostat.""" self._client = client self._humidifier = humidifier + self._mode_map = { + HVAC_MODE_HEAT: self._client.MODE_HEAT, + HVAC_MODE_COOL: self._client.MODE_COOL, + HVAC_MODE_AUTO: self._client.MODE_AUTO, + } def update(self): """Update the data from the thermostat.""" @@ -266,20 +271,20 @@ class VenstarThermostat(ClimateDevice): def set_temperature(self, **kwargs): """Set a new target temperature.""" set_temp = True - operation_mode = kwargs.get(ATTR_HVAC_MODE, self._client.mode) + operation_mode = kwargs.get(ATTR_HVAC_MODE) temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW) temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH) temperature = kwargs.get(ATTR_TEMPERATURE) - if operation_mode != self._client.mode: - set_temp = self._set_operation_mode(operation_mode) + if operation_mode and self._mode_map.get(operation_mode) != self._client.mode: + set_temp = self._set_operation_mode(self._mode_map.get(operation_mode)) if set_temp: - if operation_mode == self._client.MODE_HEAT: + if self._mode_map.get(operation_mode, self._client.mode) == self._client.MODE_HEAT: success = self._client.set_setpoints(temperature, self._client.cooltemp) - elif operation_mode == self._client.MODE_COOL: + elif self._mode_map.get(operation_mode, self._client.mode) == self._client.MODE_COOL: success = self._client.set_setpoints(self._client.heattemp, temperature) - elif operation_mode == self._client.MODE_AUTO: + elif self._mode_map.get(operation_mode, self._client.mode) == self._client.MODE_AUTO: success = self._client.set_setpoints(temp_low, temp_high) else: success = False