diff --git a/custom_components/versatile_thermostat/binary_sensor.py b/custom_components/versatile_thermostat/binary_sensor.py index 364d7545..6874a45b 100644 --- a/custom_components/versatile_thermostat/binary_sensor.py +++ b/custom_components/versatile_thermostat/binary_sensor.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant, callback, Event -from homeassistant.const import STATE_ON +from homeassistant.const import STATE_ON, STATE_OFF from homeassistant.components.binary_sensor import ( BinarySensorEntity, @@ -133,12 +133,14 @@ async def async_my_climate_changed(self, event: Event = None): _LOGGER.debug("%s - climate state change", self._attr_unique_id) old_state = self._attr_is_on - self._attr_is_on = ( - self.my_climate.window_state == STATE_ON - or self.my_climate.window_auto_state == STATE_ON - ) - if old_state != self._attr_is_on: - self.async_write_ha_state() + # Issue 120 - only take defined presence value + if self.my_climate.window_state in [STATE_ON, STATE_OFF] or self.my_climate.window_auto_state in [STATE_ON, STATE_OFF]: + self._attr_is_on = ( + self.my_climate.window_state == STATE_ON + or self.my_climate.window_auto_state == STATE_ON + ) + if old_state != self._attr_is_on: + self.async_write_ha_state() return @property @@ -171,9 +173,11 @@ async def async_my_climate_changed(self, event: Event = None): """Called when my climate have change""" _LOGGER.debug("%s - climate state change", self._attr_unique_id) old_state = self._attr_is_on - self._attr_is_on = self.my_climate.motion_state == STATE_ON - if old_state != self._attr_is_on: - self.async_write_ha_state() + # Issue 120 - only take defined presence value + if self.my_climate.motion_state in [STATE_ON, STATE_OFF]: + self._attr_is_on = self.my_climate.motion_state == STATE_ON + if old_state != self._attr_is_on: + self.async_write_ha_state() return @property @@ -204,9 +208,11 @@ async def async_my_climate_changed(self, event: Event = None): _LOGGER.debug("%s - climate state change", self._attr_unique_id) old_state = self._attr_is_on - self._attr_is_on = self.my_climate.presence_state == STATE_ON - if old_state != self._attr_is_on: - self.async_write_ha_state() + # Issue 120 - only take defined presence value + if self.my_climate.presence_state in [STATE_ON, STATE_OFF]: + self._attr_is_on = self.my_climate.presence_state == STATE_ON + if old_state != self._attr_is_on: + self.async_write_ha_state() return @property diff --git a/custom_components/versatile_thermostat/climate.py b/custom_components/versatile_thermostat/climate.py index fa999124..a2c3dedf 100644 --- a/custom_components/versatile_thermostat/climate.py +++ b/custom_components/versatile_thermostat/climate.py @@ -2299,21 +2299,21 @@ async def _async_control_heating(self, force=False, _=None): ) try: under.startup() - except UnknownEntity as err: + except UnknownEntity: # still not found, we an stop here - return + return False # Check overpowering condition # Not necessary for switch because each switch is checking at startup overpowering: bool = await self.check_overpowering() if overpowering: _LOGGER.debug("%s - End of cycle (overpowering)", self) - return + return True security: bool = await self.check_security() if security and self._is_over_climate: _LOGGER.debug("%s - End of cycle (security and over climate)", self) - return + return True # Stop here if we are off if self._hvac_mode == HVACMode.OFF: @@ -2321,7 +2321,7 @@ async def _async_control_heating(self, force=False, _=None): # A security to force stop heater if still active if self._is_device_active: await self._async_underlying_entity_turn_off() - return + return True if not self._is_over_climate: for under in self._underlyings: @@ -2333,6 +2333,7 @@ async def _async_control_heating(self, force=False, _=None): ) self.update_custom_attributes() + return True def recalculate(self): """A utility function to force the calculation of a the algo and diff --git a/custom_components/versatile_thermostat/tests/test_bugs.py b/custom_components/versatile_thermostat/tests/test_bugs.py index b6a3a7cb..09fcb0a1 100644 --- a/custom_components/versatile_thermostat/tests/test_bugs.py +++ b/custom_components/versatile_thermostat/tests/test_bugs.py @@ -62,11 +62,9 @@ async def test_bug_56( # try to call _async_control_heating try: - await entity._async_control_heating() + ret = await entity._async_control_heating() # an exception should be send - assert False - except UnknownEntity: - pass + assert ret is False except Exception: # pylint: disable=broad-exception-caught assert False