Skip to content

Commit

Permalink
Fix flakey advantage_air test (#117224)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed May 11, 2024
1 parent f35b9c2 commit 9e107a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 16 additions & 1 deletion tests/components/advantage_air/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import timedelta
from unittest.mock import AsyncMock

from homeassistant.components.advantage_air import ADVANTAGE_AIR_SYNC_INTERVAL
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -74,11 +75,18 @@ async def test_binary_sensor_async_setup_entry(

async_fire_time_changed(
hass,
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
dt_util.utcnow() + timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL + 1),
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 1

async_fire_time_changed(
hass,
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 2

state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
Expand All @@ -96,6 +104,13 @@ async def test_binary_sensor_async_setup_entry(
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()

async_fire_time_changed(
hass,
dt_util.utcnow() + timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL + 1),
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 1

async_fire_time_changed(
hass,
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
Expand Down
12 changes: 10 additions & 2 deletions tests/components/advantage_air/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import timedelta
from unittest.mock import AsyncMock

from homeassistant.components.advantage_air import ADVANTAGE_AIR_SYNC_INTERVAL
from homeassistant.components.advantage_air.const import DOMAIN as ADVANTAGE_AIR_DOMAIN
from homeassistant.components.advantage_air.sensor import (
ADVANTAGE_AIR_SERVICE_SET_TIME_TO,
Expand Down Expand Up @@ -123,17 +124,24 @@ async def test_sensor_platform_disabled_entity(

assert not hass.states.get(entity_id)

mock_get.reset_mock()
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done(wait_background_tasks=True)
mock_get.reset_mock()

async_fire_time_changed(
hass,
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
dt_util.utcnow() + timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL + 1),
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 1

async_fire_time_changed(
hass,
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
)
await hass.async_block_till_done(wait_background_tasks=True)
assert len(mock_get.mock_calls) == 2

state = hass.states.get(entity_id)
assert state
assert int(state.state) == 25
Expand Down

0 comments on commit 9e107a0

Please sign in to comment.