init home-assistant
This commit is contained in:
51
home-assistant/tests/components/vesync/test_switch.py
Normal file
51
home-assistant/tests/components/vesync/test_switch.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""Tests for the switch module."""
|
||||
|
||||
import pytest
|
||||
import requests_mock
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_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
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_name", ALL_DEVICE_NAMES)
|
||||
async def test_switch_state(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
requests_mock: requests_mock.Mocker,
|
||||
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(requests_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 == SWITCH_DOMAIN
|
||||
]
|
||||
assert entities == snapshot(name="entities")
|
||||
|
||||
# Check states
|
||||
for entity in entities:
|
||||
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id)
|
||||
Reference in New Issue
Block a user