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.const import STATE_ON
from homeassistant.const import STATE_ON, STATE_OFF
from homeassistant.components.binary_sensor import (
BinarySensorEntity,
@@ -133,12 +133,14 @@ class WindowBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity):
_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 @@ class MotionBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity):
"""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 @@ class PresenceBinarySensor(VersatileThermostatBaseEntity, BinarySensorEntity):
_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

View File

@@ -2299,21 +2299,21 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
)
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 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
# 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 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
)
self.update_custom_attributes()
return True
def recalculate(self):
"""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:
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