init home-assistant
This commit is contained in:
1
home-assistant/tests/components/ping/__init__.py
Normal file
1
home-assistant/tests/components/ping/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for ping component."""
|
||||
63
home-assistant/tests/components/ping/conftest.py
Normal file
63
home-assistant/tests/components/ping/conftest.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""Test configuration for ping."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from icmplib import Host
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.device_tracker import CONF_CONSIDER_HOME
|
||||
from homeassistant.components.ping import CONF_PING_COUNT, DOMAIN
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patch_setup(*args, **kwargs):
|
||||
"""Patch setup methods."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.ping.async_setup_entry",
|
||||
return_value=True,
|
||||
),
|
||||
patch("homeassistant.components.ping.async_setup", return_value=True),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def patch_ping():
|
||||
"""Patch icmplib async_ping."""
|
||||
mock = Host("10.10.10.10", 5, [10, 1, 2, 5, 6])
|
||||
|
||||
with (
|
||||
patch("homeassistant.components.ping.helpers.async_ping", return_value=mock),
|
||||
patch("homeassistant.components.ping.async_ping", return_value=mock),
|
||||
):
|
||||
yield mock
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
async def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
||||
"""Return a MockConfigEntry for testing."""
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="10.10.10.10",
|
||||
options={
|
||||
CONF_HOST: "10.10.10.10",
|
||||
CONF_PING_COUNT: 10.0,
|
||||
CONF_CONSIDER_HOME: 180,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_integration")
|
||||
async def mock_setup_integration(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, patch_ping
|
||||
) -> None:
|
||||
"""Fixture for setting up the component."""
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
15
home-assistant/tests/components/ping/const.py
Normal file
15
home-assistant/tests/components/ping/const.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""Constants for tests."""
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from icmplib import Host
|
||||
|
||||
BINARY_SENSOR_IMPORT_DATA = {
|
||||
"name": "test2",
|
||||
"host": "127.0.0.1",
|
||||
"count": 1,
|
||||
"scan_interval": 50,
|
||||
"consider_home": timedelta(seconds=240),
|
||||
}
|
||||
|
||||
NON_AVAILABLE_HOST_PING = Host("192.168.178.1", 10, [])
|
||||
@@ -0,0 +1,61 @@
|
||||
# serializer version: 1
|
||||
# name: test_setup_and_update
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.10_10_10_10',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.CONNECTIVITY: 'connectivity'>,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'ping',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_setup_and_update.1
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'connectivity',
|
||||
'friendly_name': '10.10.10.10',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.10_10_10_10',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_setup_and_update.2
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'connectivity',
|
||||
'friendly_name': '10.10.10.10',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.10_10_10_10',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
157
home-assistant/tests/components/ping/snapshots/test_sensor.ambr
Normal file
157
home-assistant/tests/components/ping/snapshots/test_sensor.ambr
Normal file
@@ -0,0 +1,157 @@
|
||||
# serializer version: 1
|
||||
# name: test_setup_and_update[round_trip_time_average]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.10_10_10_10_round_trip_time_average',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Round Trip Time Average',
|
||||
'platform': 'ping',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'round_trip_time_avg',
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_setup_and_update[round_trip_time_average].1
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'duration',
|
||||
'friendly_name': '10.10.10.10 Round Trip Time Average',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.10_10_10_10_round_trip_time_average',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '4.8',
|
||||
})
|
||||
# ---
|
||||
# name: test_setup_and_update[round_trip_time_maximum]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.10_10_10_10_round_trip_time_maximum',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Round Trip Time Maximum',
|
||||
'platform': 'ping',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'round_trip_time_max',
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_setup_and_update[round_trip_time_maximum].1
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'duration',
|
||||
'friendly_name': '10.10.10.10 Round Trip Time Maximum',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.10_10_10_10_round_trip_time_maximum',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '10',
|
||||
})
|
||||
# ---
|
||||
# name: test_setup_and_update[round_trip_time_mean_deviation]
|
||||
None
|
||||
# ---
|
||||
# name: test_setup_and_update[round_trip_time_mean_deviation].1
|
||||
None
|
||||
# ---
|
||||
# name: test_setup_and_update[round_trip_time_minimum]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.10_10_10_10_round_trip_time_minimum',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Round Trip Time Minimum',
|
||||
'platform': 'ping',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'round_trip_time_min',
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_setup_and_update[round_trip_time_minimum].1
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'duration',
|
||||
'friendly_name': '10.10.10.10 Round Trip Time Minimum',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': <UnitOfTime.MILLISECONDS: 'ms'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.10_10_10_10_round_trip_time_minimum',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '1',
|
||||
})
|
||||
# ---
|
||||
66
home-assistant/tests/components/ping/test_binary_sensor.py
Normal file
66
home-assistant/tests/components/ping/test_binary_sensor.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""Test the binary sensor platform of ping."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from icmplib import Host
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.components.ping.const import CONF_IMPORTED_BY, DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_integration")
|
||||
async def test_setup_and_update(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test sensor setup and update."""
|
||||
|
||||
# check if binary sensor is there
|
||||
entry = entity_registry.async_get("binary_sensor.10_10_10_10")
|
||||
assert entry == snapshot(exclude=props("unique_id"))
|
||||
|
||||
state = hass.states.get("binary_sensor.10_10_10_10")
|
||||
assert state == snapshot
|
||||
|
||||
# check if the sensor turns off.
|
||||
with patch(
|
||||
"homeassistant.components.ping.helpers.async_ping",
|
||||
return_value=Host(address="10.10.10.10", packets_sent=10, rtts=[]),
|
||||
):
|
||||
freezer.tick(timedelta(minutes=6))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.10_10_10_10")
|
||||
assert state == snapshot
|
||||
|
||||
|
||||
async def test_disabled_after_import(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test if binary sensor is disabled after import."""
|
||||
config_entry.add_to_hass(hass)
|
||||
hass.config_entries.async_update_entry(
|
||||
config_entry, data={CONF_IMPORTED_BY: "device_tracker"}
|
||||
)
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# check if entity is disabled after import by device tracker
|
||||
entry = entity_registry.async_get("binary_sensor.10_10_10_10")
|
||||
assert entry
|
||||
assert entry.disabled
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||
94
home-assistant/tests/components/ping/test_config_flow.py
Normal file
94
home-assistant/tests/components/ping/test_config_flow.py
Normal file
@@ -0,0 +1,94 @@
|
||||
"""Test the Ping (ICMP) config flow."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.ping import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("host", "expected"),
|
||||
[
|
||||
("192.618.178.1", "192.618.178.1"),
|
||||
(" 192.618.178.1 ", "192.618.178.1"),
|
||||
(" demo.host ", "demo.host"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("patch_setup")
|
||||
async def test_form(hass: HomeAssistant, host, expected) -> None:
|
||||
"""Test we get the form."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["step_id"] == "user"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"host": host,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == expected
|
||||
assert result["data"] == {}
|
||||
assert result["options"] == {
|
||||
"count": 5,
|
||||
"host": expected,
|
||||
"consider_home": 180,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("host", "expected_host"),
|
||||
[
|
||||
("192.618.178.1", "192.618.178.1"),
|
||||
(" 192.618.178.1 ", "192.618.178.1"),
|
||||
(" demo.host ", "demo.host"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("patch_setup")
|
||||
async def test_options(hass: HomeAssistant, host: str, expected_host: str) -> None:
|
||||
"""Test options flow."""
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
version=1,
|
||||
source=config_entries.SOURCE_USER,
|
||||
data={},
|
||||
domain=DOMAIN,
|
||||
options={"count": 1, "host": "192.168.1.1", "consider_home": 180},
|
||||
title="192.168.1.1",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"host": host,
|
||||
"count": 10,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
"count": 10,
|
||||
"host": expected_host,
|
||||
"consider_home": 180,
|
||||
}
|
||||
115
home-assistant/tests/components/ping/test_device_tracker.py
Normal file
115
home-assistant/tests/components/ping/test_device_tracker.py
Normal file
@@ -0,0 +1,115 @@
|
||||
"""Test the binary sensor platform of ping."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from icmplib import Host
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entity_registry_enabled_by_default() -> Generator[None]:
|
||||
"""Test fixture that ensures ping device_tracker entities are enabled in the registry."""
|
||||
with patch(
|
||||
"homeassistant.components.ping.device_tracker.PingDeviceTracker.entity_registry_enabled_default",
|
||||
return_value=True,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_integration")
|
||||
async def test_setup_and_update(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test sensor setup and update."""
|
||||
|
||||
entry = entity_registry.async_get("device_tracker.10_10_10_10")
|
||||
assert entry
|
||||
assert entry.disabled
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||
|
||||
# check device tracker state is not there
|
||||
state = hass.states.get("device_tracker.10_10_10_10")
|
||||
assert state is None
|
||||
|
||||
# enable the entity
|
||||
updated_entry = entity_registry.async_update_entity(
|
||||
entity_id="device_tracker.10_10_10_10", disabled_by=None
|
||||
)
|
||||
assert updated_entry != entry
|
||||
assert updated_entry.disabled is False
|
||||
|
||||
# reload config entry to enable entity
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("device_tracker.10_10_10_10")
|
||||
assert state.state == "home"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.ping.helpers.async_ping",
|
||||
return_value=Host(address="10.10.10.10", packets_sent=10, rtts=[]),
|
||||
):
|
||||
# we need to travel two times into the future to run the update twice
|
||||
freezer.tick(timedelta(minutes=1, seconds=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
freezer.tick(timedelta(minutes=4, seconds=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get("device_tracker.10_10_10_10"))
|
||||
assert state.state == "not_home"
|
||||
|
||||
freezer.tick(timedelta(minutes=1, seconds=1))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get("device_tracker.10_10_10_10"))
|
||||
assert state.state == "home"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "setup_integration")
|
||||
async def test_reload_not_triggering_home(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test if reload/restart does not trigger home when device is unavailable."""
|
||||
assert hass.states.get("device_tracker.10_10_10_10").state == "home"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.ping.helpers.async_ping",
|
||||
return_value=Host("10.10.10.10", 5, []),
|
||||
):
|
||||
# device should be "not_home" after consider_home interval
|
||||
freezer.tick(timedelta(minutes=5, seconds=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("device_tracker.10_10_10_10").state == "not_home"
|
||||
|
||||
# reload config entry
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# device should still be "not_home" after a reload
|
||||
assert hass.states.get("device_tracker.10_10_10_10").state == "not_home"
|
||||
|
||||
# device should be "home" after the next refresh
|
||||
freezer.tick(timedelta(seconds=30))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("device_tracker.10_10_10_10").state == "home"
|
||||
33
home-assistant/tests/components/ping/test_sensor.py
Normal file
33
home-assistant/tests/components/ping/test_sensor.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Test sensor platform of Ping."""
|
||||
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "setup_integration")
|
||||
@pytest.mark.parametrize(
|
||||
"sensor_name",
|
||||
[
|
||||
"round_trip_time_average",
|
||||
"round_trip_time_maximum",
|
||||
"round_trip_time_mean_deviation", # should be None in the snapshot
|
||||
"round_trip_time_minimum",
|
||||
],
|
||||
)
|
||||
async def test_setup_and_update(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
sensor_name: str,
|
||||
) -> None:
|
||||
"""Test sensor setup and update."""
|
||||
|
||||
entry = entity_registry.async_get(f"sensor.10_10_10_10_{sensor_name}")
|
||||
assert entry == snapshot(exclude=props("unique_id"))
|
||||
|
||||
state = hass.states.get(f"sensor.10_10_10_10_{sensor_name}")
|
||||
assert state == snapshot
|
||||
Reference in New Issue
Block a user