Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.7 KiB
Python
Raw Permalink Normal View History

"""Tests for the update module."""
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from .common import ALL_DEVICE_NAMES, mock_devices_response
from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker
@pytest.mark.parametrize("device_name", ALL_DEVICE_NAMES)
async def test_update_state(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
config_entry: MockConfigEntry,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
device_name: str,
) -> None:
"""Test the resulting setup state is as expected for the platform."""
# Configure the API devices call for device_name
mock_devices_response(aioclient_mock, device_name)
# setup platform - only including the named device
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
# Check device registry
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
assert devices == snapshot(name="devices")
# Check entity registry
entities = [
entity
for entity in er.async_entries_for_config_entry(
entity_registry, config_entry.entry_id
)
if entity.domain == UPDATE_DOMAIN
]
assert entities == snapshot(name="entities")
# Check states
for entity in entities:
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id)