Issue #120 - presence sensor not updated

This commit is contained in:
Jean-Marc Collin
2023-10-15 19:04:46 +02:00
parent 66297c6044
commit 81900ceeea
3 changed files with 27 additions and 22 deletions

View File

@@ -3,7 +3,7 @@ import logging
from homeassistant.core import HomeAssistant, callback, Event 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 ( from homeassistant.components.binary_sensor import (
BinarySensorEntity, BinarySensorEntity,
@@ -133,12 +133,14 @@ class WindowBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity):
_LOGGER.debug("%s - climate state change", self._attr_unique_id) _LOGGER.debug("%s - climate state change", self._attr_unique_id)
old_state = self._attr_is_on old_state = self._attr_is_on
self._attr_is_on = ( # Issue 120 - only take defined presence value
self.my_climate.window_state == STATE_ON if self.my_climate.window_state in [STATE_ON, STATE_OFF] or self.my_climate.window_auto_state in [STATE_ON, STATE_OFF]:
or self.my_climate.window_auto_state == STATE_ON self._attr_is_on = (
) self.my_climate.window_state == STATE_ON
if old_state != self._attr_is_on: or self.my_climate.window_auto_state == STATE_ON
self.async_write_ha_state() )
if old_state != self._attr_is_on:
self.async_write_ha_state()
return return
@property @property
@@ -171,9 +173,11 @@ class MotionBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity):
"""Called when my climate have change""" """Called when my climate have change"""
_LOGGER.debug("%s - climate state change", self._attr_unique_id) _LOGGER.debug("%s - climate state change", self._attr_unique_id)
old_state = self._attr_is_on old_state = self._attr_is_on
self._attr_is_on = self.my_climate.motion_state == STATE_ON # Issue 120 - only take defined presence value
if old_state != self._attr_is_on: if self.my_climate.motion_state in [STATE_ON, STATE_OFF]:
self.async_write_ha_state() self._attr_is_on = self.my_climate.motion_state == STATE_ON
if old_state != self._attr_is_on:
self.async_write_ha_state()
return return
@property @property
@@ -204,9 +208,11 @@ class PresenceBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity):
_LOGGER.debug("%s - climate state change", self._attr_unique_id) _LOGGER.debug("%s - climate state change", self._attr_unique_id)
old_state = self._attr_is_on old_state = self._attr_is_on
self._attr_is_on = self.my_climate.presence_state == STATE_ON # Issue 120 - only take defined presence value
if old_state != self._attr_is_on: if self.my_climate.presence_state in [STATE_ON, STATE_OFF]:
self.async_write_ha_state() self._attr_is_on = self.my_climate.presence_state == STATE_ON
if old_state != self._attr_is_on:
self.async_write_ha_state()
return return
@property @property

View File

@@ -2299,21 +2299,21 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
) )
try: try:
under.startup() under.startup()
except UnknownEntity as err: except UnknownEntity:
# still not found, we an stop here # still not found, we an stop here
return return False
# Check overpowering condition # Check overpowering condition
# Not necessary for switch because each switch is checking at startup # Not necessary for switch because each switch is checking at startup
overpowering: bool = await self.check_overpowering() overpowering: bool = await self.check_overpowering()
if overpowering: if overpowering:
_LOGGER.debug("%s - End of cycle (overpowering)", self) _LOGGER.debug("%s - End of cycle (overpowering)", self)
return return True
security: bool = await self.check_security() security: bool = await self.check_security()
if security and self._is_over_climate: if security and self._is_over_climate:
_LOGGER.debug("%s - End of cycle (security and over climate)", self) _LOGGER.debug("%s - End of cycle (security and over climate)", self)
return return True
# Stop here if we are off # Stop here if we are off
if self._hvac_mode == HVACMode.OFF: if self._hvac_mode == HVACMode.OFF:
@@ -2321,7 +2321,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
# A security to force stop heater if still active # A security to force stop heater if still active
if self._is_device_active: if self._is_device_active:
await self._async_underlying_entity_turn_off() await self._async_underlying_entity_turn_off()
return return True
if not self._is_over_climate: if not self._is_over_climate:
for under in self._underlyings: for under in self._underlyings:
@@ -2333,6 +2333,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
) )
self.update_custom_attributes() self.update_custom_attributes()
return True
def recalculate(self): def recalculate(self):
"""A utility function to force the calculation of a the algo and """A utility function to force the calculation of a the algo and

View File

@@ -62,11 +62,9 @@ async def test_bug_56(
# try to call _async_control_heating # try to call _async_control_heating
try: try:
await entity._async_control_heating() ret = await entity._async_control_heating()
# an exception should be send # an exception should be send
assert False assert ret is False
except UnknownEntity:
pass
except Exception: # pylint: disable=broad-exception-caught except Exception: # pylint: disable=broad-exception-caught
assert False assert False