From 0671e008a1ce3fd9c22380e8d75e152779a9d612 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Sat, 18 Mar 2023 12:18:44 +0100 Subject: [PATCH] Issue #63 - security parameters cannot be set to 0 --- .../versatile_thermostat/climate.py | 6 ++- .../versatile_thermostat/tests/test_bugs.py | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/custom_components/versatile_thermostat/climate.py b/custom_components/versatile_thermostat/climate.py index 4a0a6e0..4fbf7b6 100644 --- a/custom_components/versatile_thermostat/climate.py +++ b/custom_components/versatile_thermostat/climate.py @@ -454,11 +454,13 @@ def post_init(self, entry_infos): self._security_delay_min = entry_infos.get(CONF_SECURITY_DELAY_MIN) self._security_min_on_percent = ( entry_infos.get(CONF_SECURITY_MIN_ON_PERCENT) - or DEFAULT_SECURITY_MIN_ON_PERCENT + if entry_infos.get(CONF_SECURITY_MIN_ON_PERCENT) is not None + else DEFAULT_SECURITY_MIN_ON_PERCENT ) self._security_default_on_percent = ( entry_infos.get(CONF_SECURITY_DEFAULT_ON_PERCENT) - or DEFAULT_SECURITY_DEFAULT_ON_PERCENT + if entry_infos.get(CONF_SECURITY_DEFAULT_ON_PERCENT) is not None + else DEFAULT_SECURITY_DEFAULT_ON_PERCENT ) self._minimal_activation_delay = entry_infos.get(CONF_MINIMAL_ACTIVATION_DELAY) self._last_temperature_mesure = datetime.now(tz=self._current_tz) diff --git a/custom_components/versatile_thermostat/tests/test_bugs.py b/custom_components/versatile_thermostat/tests/test_bugs.py index d8f55c8..013809e 100644 --- a/custom_components/versatile_thermostat/tests/test_bugs.py +++ b/custom_components/versatile_thermostat/tests/test_bugs.py @@ -82,3 +82,50 @@ async def test_bug_56( # Should not failed entity.update_custom_attributes() + + +async def test_bug_63( + hass: HomeAssistant, + skip_hass_states_is_state, + skip_turn_on_off_heater, + skip_send_event, +): + """Test that it should be possible to set the security_default_on_percent to 0""" + + entry = MockConfigEntry( + domain=DOMAIN, + title="TheOverSwitchMockName", + unique_id="uniqueId", + data={ + CONF_NAME: "TheOverSwitchMockName", + CONF_THERMOSTAT_TYPE: CONF_THERMOSTAT_SWITCH, + CONF_TEMP_SENSOR: "sensor.mock_temp_sensor", + CONF_EXTERNAL_TEMP_SENSOR: "sensor.mock_ext_temp_sensor", + CONF_CYCLE_MIN: 5, + CONF_TEMP_MIN: 15, + CONF_TEMP_MAX: 30, + "eco_temp": 17, + "comfort_temp": 18, + "boost_temp": 19, + CONF_USE_WINDOW_FEATURE: False, + CONF_USE_MOTION_FEATURE: False, + CONF_USE_POWER_FEATURE: False, + CONF_USE_PRESENCE_FEATURE: False, + CONF_HEATER: "switch.mock_switch", + CONF_PROP_FUNCTION: PROPORTIONAL_FUNCTION_TPI, + CONF_TPI_COEF_INT: 0.3, + CONF_TPI_COEF_EXT: 0.01, + CONF_MINIMAL_ACTIVATION_DELAY: 30, + CONF_SECURITY_DELAY_MIN: 5, + CONF_SECURITY_MIN_ON_PERCENT: 0.5, + CONF_SECURITY_DEFAULT_ON_PERCENT: 0.0, # !! here + CONF_DEVICE_POWER: 200, + }, + ) + + entity: VersatileThermostat = await create_thermostat( + hass, entry, "climate.theoverswitchmockname" + ) + assert entity + + assert entity._security_default_on_percent == 0