From 797ee81fc9b8f4d0ef6314df6f45b98b5507f3c4 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 8 Mar 2021 18:11:54 -0500 Subject: [PATCH] Update zwave_js supported features list to be static (#47623) --- homeassistant/components/zwave_js/climate.py | 22 +++++++++-------- tests/components/zwave_js/test_climate.py | 26 +++++++++++++++++++- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/zwave_js/climate.py b/homeassistant/components/zwave_js/climate.py index 325cf14b379..26e9e730283 100644 --- a/homeassistant/components/zwave_js/climate.py +++ b/homeassistant/components/zwave_js/climate.py @@ -162,6 +162,15 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): add_to_watched_value_ids=True, ) self._set_modes_and_presets() + self._supported_features = SUPPORT_PRESET_MODE + # If any setpoint value exists, we can assume temperature + # can be set + if any(self._setpoint_values.values()): + self._supported_features |= SUPPORT_TARGET_TEMPERATURE + if HVAC_MODE_HEAT_COOL in self.hvac_modes: + self._supported_features |= SUPPORT_TARGET_TEMPERATURE_RANGE + if self._fan_mode: + self._supported_features |= SUPPORT_FAN_MODE def _setpoint_value(self, setpoint_type: ThermostatSetpointType) -> ZwaveValue: """Optionally return a ZwaveValue for a setpoint.""" @@ -259,7 +268,7 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): return None try: temp = self._setpoint_value(self._current_mode_setpoint_enums[0]) - except ValueError: + except (IndexError, ValueError): return None return temp.value if temp else None @@ -271,7 +280,7 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): return None try: temp = self._setpoint_value(self._current_mode_setpoint_enums[1]) - except ValueError: + except (IndexError, ValueError): return None return temp.value if temp else None @@ -335,14 +344,7 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): @property def supported_features(self) -> int: """Return the list of supported features.""" - support = SUPPORT_PRESET_MODE - if len(self._current_mode_setpoint_enums) == 1: - support |= SUPPORT_TARGET_TEMPERATURE - if len(self._current_mode_setpoint_enums) > 1: - support |= SUPPORT_TARGET_TEMPERATURE_RANGE - if self._fan_mode: - support |= SUPPORT_FAN_MODE - return support + return self._supported_features async def async_set_fan_mode(self, fan_mode: str) -> None: """Set new target fan mode.""" diff --git a/tests/components/zwave_js/test_climate.py b/tests/components/zwave_js/test_climate.py index fe3e0708acc..a31aad19603 100644 --- a/tests/components/zwave_js/test_climate.py +++ b/tests/components/zwave_js/test_climate.py @@ -24,9 +24,17 @@ from homeassistant.components.climate.const import ( SERVICE_SET_HVAC_MODE, SERVICE_SET_PRESET_MODE, SERVICE_SET_TEMPERATURE, + SUPPORT_FAN_MODE, + SUPPORT_PRESET_MODE, + SUPPORT_TARGET_TEMPERATURE, + SUPPORT_TARGET_TEMPERATURE_RANGE, ) from homeassistant.components.zwave_js.climate import ATTR_FAN_STATE -from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE +from homeassistant.const import ( + ATTR_ENTITY_ID, + ATTR_SUPPORTED_FEATURES, + ATTR_TEMPERATURE, +) from .common import ( CLIMATE_DANFOSS_LC13_ENTITY, @@ -58,6 +66,13 @@ async def test_thermostat_v2( assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE assert state.attributes[ATTR_FAN_MODE] == "Auto low" assert state.attributes[ATTR_FAN_STATE] == "Idle / off" + assert ( + state.attributes[ATTR_SUPPORTED_FEATURES] + == SUPPORT_PRESET_MODE + | SUPPORT_TARGET_TEMPERATURE + | SUPPORT_TARGET_TEMPERATURE_RANGE + | SUPPORT_FAN_MODE + ) # Test setting preset mode await hass.services.async_call( @@ -408,6 +423,10 @@ async def test_setpoint_thermostat(hass, client, climate_danfoss_lc_13, integrat assert state.attributes[ATTR_TEMPERATURE] == 14 assert state.attributes[ATTR_HVAC_MODES] == [HVAC_MODE_HEAT] assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE + assert ( + state.attributes[ATTR_SUPPORTED_FEATURES] + == SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE + ) client.async_send_command_no_wait.reset_mock() @@ -491,6 +510,10 @@ async def test_thermostat_heatit(hass, client, climate_heatit_z_trm3, integratio assert state.attributes[ATTR_TEMPERATURE] == 22.5 assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_IDLE assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE + assert ( + state.attributes[ATTR_SUPPORTED_FEATURES] + == SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE + ) async def test_thermostat_srt321_hrt4_zw(hass, client, srt321_hrt4_zw, integration): @@ -507,3 +530,4 @@ async def test_thermostat_srt321_hrt4_zw(hass, client, srt321_hrt4_zw, integrati HVAC_MODE_HEAT, ] assert state.attributes[ATTR_CURRENT_TEMPERATURE] is None + assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_PRESET_MODE