Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix flaky Risco test #44788

Merged
merged 3 commits into from
Jan 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Try to fix flaky Risco test
  • Loading branch information
OnFreund committed Jan 3, 2021
commit 702a4be29c161e4f6b48f2ae1d9cd27f6a8f666d
11 changes: 6 additions & 5 deletions tests/components/risco/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"""Tests for the Risco event sensors."""
from datetime import timedelta
from unittest.mock import MagicMock, patch

from homeassistant.components.risco import (
LAST_EVENT_TIMESTAMP_KEY,
CannotConnectError,
UnauthorizedError,
)
from homeassistant.components.risco.const import DOMAIN, EVENTS_COORDINATOR
from homeassistant.components.risco.const import DOMAIN
from homeassistant.util import dt

from .util import TEST_CONFIG, setup_risco
from .util import two_zone_alarm # noqa: F401

from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, async_fire_time_changed

ENTITY_IDS = {
"Alarm": "sensor.risco_test_site_name_alarm_events",
Expand Down Expand Up @@ -176,7 +178,7 @@ async def test_setup(hass, two_zone_alarm): # noqa: F811
), patch(
"homeassistant.components.risco.Store.async_save",
) as save_mock:
entry = await setup_risco(hass)
await setup_risco(hass)
await hass.async_block_till_done()
save_mock.assert_awaited_once_with(
{LAST_EVENT_TIMESTAMP_KEY: TEST_EVENTS[0].time}
Expand All @@ -188,14 +190,13 @@ async def test_setup(hass, two_zone_alarm): # noqa: F811
for category, entity_id in ENTITY_IDS.items():
_check_state(hass, category, entity_id)

coordinator = hass.data[DOMAIN][entry.entry_id][EVENTS_COORDINATOR]
with patch(
"homeassistant.components.risco.RiscoAPI.get_events", return_value=[]
) as events_mock, patch(
"homeassistant.components.risco.Store.async_load",
return_value={LAST_EVENT_TIMESTAMP_KEY: TEST_EVENTS[0].time},
):
await coordinator.async_refresh()
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=65))
await hass.async_block_till_done()
events_mock.assert_awaited_once_with(TEST_EVENTS[0].time, 10)

Expand Down