issue #556 - enhance motion detection feature (2)

This commit is contained in:
Jean-Marc Collin
2024-10-16 05:08:57 +00:00
parent 492c95aff5
commit 0f585be0c9
2 changed files with 31 additions and 6 deletions

View File

@@ -1654,11 +1654,20 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
if not long_enough: if not long_enough:
_LOGGER.debug( _LOGGER.debug(
"Motion delay condition is not satisfied. Check motion sensor state" "Motion delay condition is not satisfied (the sensor have change its state during the delay). Check motion sensor state"
) )
# Get sensor current state # Get sensor current state
motion_state = self.hass.states.get(self._motion_sensor_entity_id) motion_state = self.hass.states.get(self._motion_sensor_entity_id)
if motion_state == new_state.state and new_state.state == STATE_ON: _LOGGER.debug(
"%s - motion_state=%s, new_state.state=%s",
self,
motion_state.state,
new_state.state,
)
if (
motion_state.state == new_state.state
and new_state.state == STATE_ON
):
_LOGGER.debug( _LOGGER.debug(
"%s - the motion sensor is finally 'on' after the delay", self "%s - the motion sensor is finally 'on' after the delay", self
) )

View File

@@ -97,7 +97,12 @@ async def test_movement_management_time_not_enough(
return_value=False, return_value=False,
), patch( ), patch(
"homeassistant.helpers.condition.state", return_value=False "homeassistant.helpers.condition.state", return_value=False
) as mock_condition: ) as mock_condition, patch(
"homeassistant.core.StateMachine.get",
return_value=State(
entity_id="binary_sensor.mock_motion_sensor", state=STATE_OFF
),
):
event_timestamp = now - timedelta(minutes=4) event_timestamp = now - timedelta(minutes=4)
try_condition = await send_motion_change_event(entity, True, False, event_timestamp) try_condition = await send_motion_change_event(entity, True, False, event_timestamp)
@@ -156,7 +161,12 @@ async def test_movement_management_time_not_enough(
return_value=True, return_value=True,
) as mock_device_active, patch( ) as mock_device_active, patch(
"homeassistant.helpers.condition.state", return_value=False "homeassistant.helpers.condition.state", return_value=False
) as mock_condition: ) as mock_condition, patch(
"homeassistant.core.StateMachine.get",
return_value=State(
entity_id="binary_sensor.mock_motion_sensor", state=STATE_OFF
),
):
event_timestamp = now - timedelta(minutes=2) event_timestamp = now - timedelta(minutes=2)
try_condition = await send_motion_change_event(entity, False, True, event_timestamp) try_condition = await send_motion_change_event(entity, False, True, event_timestamp)
@@ -685,7 +695,10 @@ async def test_movement_management_with_stop_during_condition_last_state_on(
"custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.is_device_active", "custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.is_device_active",
return_value=True, return_value=True,
), patch("homeassistant.helpers.condition.state", return_value=False), patch( ), patch("homeassistant.helpers.condition.state", return_value=False), patch(
"homeassistant.core.StateMachine.get", return_value=STATE_OFF "homeassistant.core.StateMachine.get",
return_value=State(
entity_id="binary_sensor.mock_motion_sensor", state=STATE_OFF
),
): ):
event_timestamp = now - timedelta(minutes=5) event_timestamp = now - timedelta(minutes=5)
try_condition1 = await send_motion_change_event( try_condition1 = await send_motion_change_event(
@@ -705,7 +718,10 @@ async def test_movement_management_with_stop_during_condition_last_state_on(
"custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.is_device_active", "custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.is_device_active",
return_value=True, return_value=True,
), patch("homeassistant.helpers.condition.state", return_value=False), patch( ), patch("homeassistant.helpers.condition.state", return_value=False), patch(
"homeassistant.core.StateMachine.get", return_value=STATE_ON "homeassistant.core.StateMachine.get",
return_value=State(
entity_id="binary_sensor.mock_motion_sensor", state=STATE_ON
),
): ):
event_timestamp = now - timedelta(minutes=5) event_timestamp = now - timedelta(minutes=5)
try_condition1 = await send_motion_change_event( try_condition1 = await send_motion_change_event(