diff --git a/.devcontainer/configuration.yaml b/.devcontainer/configuration.yaml index a2f1332..bbf0053 100644 --- a/.devcontainer/configuration.yaml +++ b/.devcontainer/configuration.yaml @@ -191,6 +191,9 @@ input_boolean: fake_valve_sonoff_trvzb2: name: Valve Sonoff TRVZB2 icon: mdi:valve + fake_inversed_heater: + name: Inversed Heater + icon: mdi:radiator-off climate: - platform: generic_thermostat @@ -314,6 +317,21 @@ switch: option: comfort-2 target: entity_id: select.seche_serviettes_sdb_rdc_cable_outlet_mode + - platform: template + switches: + fake_inversed_switch: + friendly_name: "A fake inversed switch" + value_template: "{{ is_state('input_boolean.fake_inversed_heater', 'on') }}" + turn_on: + action: input_boolean.turn_on + data: {} + target: + entity_id: input_boolean.fake_inversed_heater + turn_off: + action: input_boolean.turn_off + data: {} + target: + entity_id: input_boolean.fake_inversed_heater frontend: extra_module_url: diff --git a/custom_components/versatile_thermostat/manifest.json b/custom_components/versatile_thermostat/manifest.json index 04e1756..6afcf44 100644 --- a/custom_components/versatile_thermostat/manifest.json +++ b/custom_components/versatile_thermostat/manifest.json @@ -14,6 +14,6 @@ "quality_scale": "silver", "requirements": [], "ssdp": [], - "version": "7.2.0", + "version": "7.2.1", "zeroconf": [] } \ No newline at end of file diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index fc88f25..b39ac45 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -281,8 +281,8 @@ class UnderlyingSwitch(UnderlyingEntity): # not self.is_inversed and real_state # ) is_on = self._hass.states.is_state(self._entity_id, self._on_command.get("state")) - if self.is_inversed: - return not is_on + # if self.is_inversed: + # return not is_on return is_on diff --git a/tests/test_inverted_switch.py b/tests/test_inverted_switch.py index 46f9d72..f0749d1 100644 --- a/tests/test_inverted_switch.py +++ b/tests/test_inverted_switch.py @@ -18,6 +18,12 @@ logging.getLogger().setLevel(logging.DEBUG) async def test_inverted_switch(hass: HomeAssistant, skip_hass_states_is_state): """Test the Window auto management""" + temps = { + "eco": 17, + "comfort": 18, + "boost": 21, + } + entry = MockConfigEntry( domain=DOMAIN, title="TheOverSwitchMockName", @@ -30,14 +36,11 @@ async def test_inverted_switch(hass: HomeAssistant, skip_hass_states_is_state): CONF_CYCLE_MIN: 5, CONF_TEMP_MIN: 15, CONF_TEMP_MAX: 30, - "eco_temp": 17, - "comfort_temp": 18, - "boost_temp": 21, 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_UNDERLYING_LIST: ["switch.mock_switch"], CONF_PROP_FUNCTION: PROPORTIONAL_FUNCTION_TPI, CONF_TPI_COEF_INT: 0.3, CONF_TPI_COEF_EXT: 0.01, @@ -51,14 +54,12 @@ async def test_inverted_switch(hass: HomeAssistant, skip_hass_states_is_state): }, ) - with patch( - "homeassistant.core.ServiceRegistry.async_call" - ) as mock_service_call, patch( - "homeassistant.core.StateMachine.is_state", return_value=True # switch is On + # 0. Create the entity + + with patch("homeassistant.core.ServiceRegistry.async_call") as mock_service_call, patch( + "homeassistant.core.StateMachine.is_state", return_value=False # switch is On so is_state(switch, 'off') is False ): - entity: ThermostatOverSwitch = await create_thermostat( - hass, entry, "climate.theoverswitchmockname" - ) + entity: ThermostatOverSwitch = await create_thermostat(hass, entry, "climate.theoverswitchmockname", temps) assert entity assert entity.is_inversed @@ -78,12 +79,10 @@ async def test_inverted_switch(hass: HomeAssistant, skip_hass_states_is_state): assert mock_service_call.call_count == 0 # 1. Make the temperature down to activate the switch - with patch( - "custom_components.versatile_thermostat.base_thermostat.BaseThermostat.send_event" - ), patch( + with patch("custom_components.versatile_thermostat.base_thermostat.BaseThermostat.send_event"), patch( "homeassistant.core.ServiceRegistry.async_call" ) as mock_service_call, patch( - "homeassistant.core.StateMachine.is_state", return_value=True # switch is Off + "homeassistant.core.StateMachine.is_state", return_value=True # switch is Off so is_state(switch, 'off') is True ): event_timestamp = now - timedelta(minutes=4) await send_temperature_change_event(entity, 19, event_timestamp) diff --git a/tests/test_virtual_switch.py b/tests/test_virtual_switch.py index 1cd59c2..49f0b38 100644 --- a/tests/test_virtual_switch.py +++ b/tests/test_virtual_switch.py @@ -71,6 +71,19 @@ from .commons import * HVACMode.HEAT, True, ), + # Inversed switch without command personnalisations + ( + True, + None, + None, + "turn_off", + {"entity_id": "switch.test"}, + STATE_OFF, + "turn_on", + {"entity_id": "switch.test"}, + STATE_ON, + True, + ), # Error cases invalid command ( False,