From b98ca49a56a441f84bd49eb29e510f27f6b566ab Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 12 Apr 2021 16:12:38 -0400 Subject: [PATCH] Add min and max temp properties to zwave_js.climate (#49125) --- homeassistant/components/zwave_js/climate.py | 39 +++++++++++++++++++- tests/components/zwave_js/test_climate.py | 4 ++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zwave_js/climate.py b/homeassistant/components/zwave_js/climate.py index 41ea873c5f8..0cad9de8065 100644 --- a/homeassistant/components/zwave_js/climate.py +++ b/homeassistant/components/zwave_js/climate.py @@ -18,7 +18,11 @@ from zwave_js_server.const import ( ) from zwave_js_server.model.value import Value as ZwaveValue -from homeassistant.components.climate import ClimateEntity +from homeassistant.components.climate import ( + DEFAULT_MAX_TEMP, + DEFAULT_MIN_TEMP, + ClimateEntity, +) from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, ATTR_TARGET_TEMP_HIGH, @@ -49,6 +53,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.temperature import convert_temperature from .const import DATA_CLIENT, DATA_UNSUBSCRIBE, DOMAIN from .discovery import ZwaveDiscoveryInfo @@ -375,6 +380,38 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): """Return the list of supported features.""" return self._supported_features + @property + def min_temp(self) -> float: + """Return the minimum temperature.""" + min_temp = DEFAULT_MIN_TEMP + base_unit = TEMP_CELSIUS + try: + temp = self._setpoint_value(self._current_mode_setpoint_enums[0]) + if temp.metadata.min: + min_temp = temp.metadata.min + base_unit = self.temperature_unit + # In case of any error, we fallback to the default + except (IndexError, ValueError, TypeError): + pass + + return convert_temperature(min_temp, base_unit, self.temperature_unit) + + @property + def max_temp(self) -> float: + """Return the maximum temperature.""" + max_temp = DEFAULT_MAX_TEMP + base_unit = TEMP_CELSIUS + try: + temp = self._setpoint_value(self._current_mode_setpoint_enums[0]) + if temp.metadata.max: + max_temp = temp.metadata.max + base_unit = self.temperature_unit + # In case of any error, we fallback to the default + except (IndexError, ValueError, TypeError): + pass + + return convert_temperature(max_temp, base_unit, self.temperature_unit) + async def async_set_fan_mode(self, fan_mode: str) -> None: """Set new target fan mode.""" if not self._fan_mode: diff --git a/tests/components/zwave_js/test_climate.py b/tests/components/zwave_js/test_climate.py index 2084e771546..8682ce98b5b 100644 --- a/tests/components/zwave_js/test_climate.py +++ b/tests/components/zwave_js/test_climate.py @@ -9,6 +9,8 @@ from homeassistant.components.climate.const import ( ATTR_HVAC_ACTION, ATTR_HVAC_MODE, ATTR_HVAC_MODES, + ATTR_MAX_TEMP, + ATTR_MIN_TEMP, ATTR_PRESET_MODE, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, @@ -448,6 +450,8 @@ 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_SUPPORTED_FEATURES] == SUPPORT_TARGET_TEMPERATURE + assert state.attributes[ATTR_MIN_TEMP] == 5 + assert state.attributes[ATTR_MAX_TEMP] == 35 async def test_thermostat_srt321_hrt4_zw(hass, client, srt321_hrt4_zw, integration):