* Phase out periodic tasks * false by default or some tests will block forever, will need to fix each one manually * kwarg works * kwarg works * kwarg works * fixes * fix more tests * fix more tests * fix lifx * opensky * pvpc_hourly_pricing * adjust more * adjust more * smarttub * adjust more * adjust more * adjust more * adjust more * adjust * no eager executor * zha * qnap_qsw * fix more * fix fix * docs * its a wrapper now * add more coverage * coverage * cover all combos * more fixes * more fixes * more fixes * remaining issues are legit bugs in tests * make tplink test more predictable * more fixes * feedreader * grind out some more * make test race safe * one more
89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
"""OpenSky sensor tests."""
|
|
|
|
from datetime import timedelta
|
|
from unittest.mock import patch
|
|
|
|
from freezegun.api import FrozenDateTimeFactory
|
|
from syrupy import SnapshotAssertion
|
|
|
|
from homeassistant.components.opensky.const import (
|
|
EVENT_OPENSKY_ENTRY,
|
|
EVENT_OPENSKY_EXIT,
|
|
)
|
|
from homeassistant.core import Event, HomeAssistant
|
|
|
|
from . import get_states_response_fixture
|
|
from .conftest import ComponentSetup
|
|
|
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
|
|
|
|
|
async def test_sensor(
|
|
hass: HomeAssistant,
|
|
config_entry: MockConfigEntry,
|
|
setup_integration: ComponentSetup,
|
|
snapshot: SnapshotAssertion,
|
|
):
|
|
"""Test setup sensor."""
|
|
await setup_integration(config_entry)
|
|
|
|
state = hass.states.get("sensor.opensky")
|
|
assert state == snapshot
|
|
events = []
|
|
|
|
async def event_listener(event: Event) -> None:
|
|
events.append(event)
|
|
|
|
hass.bus.async_listen(EVENT_OPENSKY_ENTRY, event_listener)
|
|
hass.bus.async_listen(EVENT_OPENSKY_EXIT, event_listener)
|
|
assert events == []
|
|
|
|
|
|
async def test_sensor_altitude(
|
|
hass: HomeAssistant,
|
|
config_entry_altitude: MockConfigEntry,
|
|
setup_integration: ComponentSetup,
|
|
snapshot: SnapshotAssertion,
|
|
):
|
|
"""Test setup sensor with a set altitude."""
|
|
await setup_integration(config_entry_altitude)
|
|
|
|
state = hass.states.get("sensor.opensky")
|
|
assert state == snapshot
|
|
|
|
|
|
async def test_sensor_updating(
|
|
hass: HomeAssistant,
|
|
config_entry: MockConfigEntry,
|
|
freezer: FrozenDateTimeFactory,
|
|
setup_integration: ComponentSetup,
|
|
snapshot: SnapshotAssertion,
|
|
):
|
|
"""Test updating sensor."""
|
|
await setup_integration(config_entry)
|
|
|
|
events = []
|
|
|
|
async def event_listener(event: Event) -> None:
|
|
events.append(event)
|
|
|
|
hass.bus.async_listen(EVENT_OPENSKY_ENTRY, event_listener)
|
|
hass.bus.async_listen(EVENT_OPENSKY_EXIT, event_listener)
|
|
|
|
async def skip_time_and_check_events() -> None:
|
|
freezer.tick(timedelta(minutes=15))
|
|
async_fire_time_changed(hass)
|
|
await hass.async_block_till_done(wait_background_tasks=True)
|
|
|
|
assert events == snapshot
|
|
|
|
with patch(
|
|
"python_opensky.OpenSky.get_states",
|
|
return_value=get_states_response_fixture("opensky/states_1.json"),
|
|
):
|
|
await skip_time_and_check_events()
|
|
with patch(
|
|
"python_opensky.OpenSky.get_states",
|
|
return_value=get_states_response_fixture("opensky/states.json"),
|
|
):
|
|
await skip_time_and_check_events()
|