From 3e41422caaacdbd7bb0396437effc4cf1991bfb4 Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 31 Jan 2018 00:59:43 +0200 Subject: [PATCH] Fix demo platform support (#12070) * Fixing demo platform to use support_flags * Fixed tests as well * Moved humidity low / high as always available based on defaults * Updated demo platform to show more combinations --- homeassistant/components/climate/demo.py | 50 ++++++++++++++++++------ tests/components/climate/test_demo.py | 4 +- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/climate/demo.py b/homeassistant/components/climate/demo.py index 357b1d56200..102155babea 100644 --- a/homeassistant/components/climate/demo.py +++ b/homeassistant/components/climate/demo.py @@ -14,23 +14,19 @@ from homeassistant.components.climate import ( SUPPORT_ON_OFF) from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_TEMPERATURE -SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY | - SUPPORT_TARGET_HUMIDITY_LOW | SUPPORT_TARGET_HUMIDITY_HIGH | - SUPPORT_AWAY_MODE | SUPPORT_HOLD_MODE | SUPPORT_FAN_MODE | - SUPPORT_OPERATION_MODE | SUPPORT_AUX_HEAT | - SUPPORT_SWING_MODE | SUPPORT_TARGET_TEMPERATURE_HIGH | - SUPPORT_TARGET_TEMPERATURE_LOW | SUPPORT_ON_OFF) +SUPPORT_FLAGS = SUPPORT_TARGET_HUMIDITY_LOW | SUPPORT_TARGET_HUMIDITY_HIGH def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Demo climate devices.""" add_devices([ DemoClimate('HeatPump', 68, TEMP_FAHRENHEIT, None, None, 77, - 'Auto Low', None, None, 'Auto', 'heat', None, None, None), + None, None, None, None, 'heat', None, None, + None, True), DemoClimate('Hvac', 21, TEMP_CELSIUS, True, None, 22, 'On High', - 67, 54, 'Off', 'cool', False, None, None), - DemoClimate('Ecobee', None, TEMP_CELSIUS, None, None, 23, 'Auto Low', - None, None, 'Auto', 'auto', None, 24, 21) + 67, 54, 'Off', 'cool', False, None, None, None), + DemoClimate('Ecobee', None, TEMP_CELSIUS, None, 'home', 23, 'Auto Low', + None, None, 'Auto', 'auto', None, 24, 21, None) ]) @@ -40,9 +36,37 @@ class DemoClimate(ClimateDevice): def __init__(self, name, target_temperature, unit_of_measurement, away, hold, current_temperature, current_fan_mode, target_humidity, current_humidity, current_swing_mode, - current_operation, aux, target_temp_high, target_temp_low): + current_operation, aux, target_temp_high, target_temp_low, + is_on): """Initialize the climate device.""" self._name = name + self._support_flags = SUPPORT_FLAGS + if target_temperature is not None: + self._support_flags = \ + self._support_flags | SUPPORT_TARGET_TEMPERATURE + if away is not None: + self._support_flags = self._support_flags | SUPPORT_AWAY_MODE + if hold is not None: + self._support_flags = self._support_flags | SUPPORT_HOLD_MODE + if current_fan_mode is not None: + self._support_flags = self._support_flags | SUPPORT_FAN_MODE + if target_humidity is not None: + self._support_flags = \ + self._support_flags | SUPPORT_TARGET_HUMIDITY + if current_swing_mode is not None: + self._support_flags = self._support_flags | SUPPORT_SWING_MODE + if current_operation is not None: + self._support_flags = self._support_flags | SUPPORT_OPERATION_MODE + if aux is not None: + self._support_flags = self._support_flags | SUPPORT_AUX_HEAT + if target_temp_high is not None: + self._support_flags = \ + self._support_flags | SUPPORT_TARGET_TEMPERATURE_HIGH + if target_temp_low is not None: + self._support_flags = \ + self._support_flags | SUPPORT_TARGET_TEMPERATURE_LOW + if is_on is not None: + self._support_flags = self._support_flags | SUPPORT_ON_OFF self._target_temperature = target_temperature self._target_humidity = target_humidity self._unit_of_measurement = unit_of_measurement @@ -59,12 +83,12 @@ class DemoClimate(ClimateDevice): self._swing_list = ['Auto', '1', '2', '3', 'Off'] self._target_temperature_high = target_temp_high self._target_temperature_low = target_temp_low - self._on = True + self._on = is_on @property def supported_features(self): """Return the list of supported features.""" - return SUPPORT_FLAGS + return self._support_flags @property def should_poll(self): diff --git a/tests/components/climate/test_demo.py b/tests/components/climate/test_demo.py index 9098494bf48..b2633a75583 100644 --- a/tests/components/climate/test_demo.py +++ b/tests/components/climate/test_demo.py @@ -224,10 +224,10 @@ class TestDemoClimate(unittest.TestCase): def test_set_hold_mode_none(self): """Test setting the hold mode off/false.""" - climate.set_hold_mode(self.hass, None, ENTITY_ECOBEE) + climate.set_hold_mode(self.hass, 'off', ENTITY_ECOBEE) self.hass.block_till_done() state = self.hass.states.get(ENTITY_ECOBEE) - self.assertEqual(None, state.attributes.get('hold_mode')) + self.assertEqual('off', state.attributes.get('hold_mode')) def test_set_aux_heat_bad_attr(self): """Test setting the auxiliary heater without required attribute."""