mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add device tracker test for Vodafone Station (#134334)
This commit is contained in:
parent
89c73f56b1
commit
111ef13a3f
@ -19,18 +19,19 @@ MOCK_CONFIG = {
|
||||
|
||||
MOCK_USER_DATA = MOCK_CONFIG[DOMAIN][CONF_DEVICES][0]
|
||||
|
||||
|
||||
DEVICE_DATA_QUERY = {
|
||||
"xx:xx:xx:xx:xx:xx": VodafoneStationDevice(
|
||||
DEVICE_1_MAC = "xx:xx:xx:xx:xx:xx"
|
||||
DEVICE_1 = {
|
||||
DEVICE_1_MAC: VodafoneStationDevice(
|
||||
connected=True,
|
||||
connection_type="wifi",
|
||||
ip_address="192.168.1.10",
|
||||
name="WifiDevice0",
|
||||
mac="xx:xx:xx:xx:xx:xx",
|
||||
mac=DEVICE_1_MAC,
|
||||
type="laptop",
|
||||
wifi="2.4G",
|
||||
),
|
||||
}
|
||||
DEVICE_DATA_QUERY = DEVICE_1
|
||||
|
||||
SERIAL = "m123456789"
|
||||
|
||||
|
48
tests/components/vodafone_station/test_device_tracker.py
Normal file
48
tests/components/vodafone_station/test_device_tracker.py
Normal file
@ -0,0 +1,48 @@
|
||||
"""Define tests for the Vodafone Station device tracker."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.vodafone_station.const import DOMAIN, SCAN_INTERVAL
|
||||
from homeassistant.components.vodafone_station.coordinator import CONSIDER_HOME_SECONDS
|
||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DEVICE_1, DEVICE_1_MAC, DEVICE_DATA_QUERY, MOCK_USER_DATA
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_coordinator_consider_home(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_vodafone_station_router: AsyncMock,
|
||||
) -> None:
|
||||
"""Test if device is considered not_home when disconnected."""
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
device_tracker = f"device_tracker.vodafone_station_{DEVICE_1_MAC.replace(":", "_")}"
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(device_tracker)
|
||||
assert state
|
||||
assert state.state == STATE_HOME
|
||||
|
||||
DEVICE_1[DEVICE_1_MAC].connected = False
|
||||
DEVICE_DATA_QUERY.update(DEVICE_1)
|
||||
mock_vodafone_station_router.get_devices_data.return_value = DEVICE_DATA_QUERY
|
||||
|
||||
freezer.tick(SCAN_INTERVAL + CONSIDER_HOME_SECONDS)
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
state = hass.states.get(device_tracker)
|
||||
assert state
|
||||
assert state.state == STATE_NOT_HOME
|
Loading…
x
Reference in New Issue
Block a user