Assemble platforms upfront in devolo Home Network (#80126)
* Assemble platforms upfront in devolo Home Network * Add tests * Optimize mocks * Use async_forward_entry_setups * Adapt tests to newly added switch platform
This commit is contained in:
parent
bdd786b1f0
commit
b195d5d1db
6 changed files with 79 additions and 27 deletions
|
@ -19,6 +19,20 @@ def mock_device():
|
|||
yield device
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def mock_repeater_device(mock_device: MockDevice):
|
||||
"""Mock connecting to a devolo home network repeater device."""
|
||||
mock_device.plcnet = None
|
||||
yield mock_device
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def mock_nonwifi_device(mock_device: MockDevice):
|
||||
"""Mock connecting to a devolo home network device without wifi."""
|
||||
mock_device.device.features = ["reset", "update", "led", "intmtg"]
|
||||
yield mock_device
|
||||
|
||||
|
||||
@pytest.fixture(name="info")
|
||||
def mock_validate_input():
|
||||
"""Mock setup entry and user input."""
|
||||
|
|
|
@ -4,10 +4,15 @@ from unittest.mock import patch
|
|||
from devolo_plc_api.exceptions.device import DeviceNotFound
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR
|
||||
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER
|
||||
from homeassistant.components.devolo_home_network.const import DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_IP_ADDRESS, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import async_get_platforms
|
||||
|
||||
from . import configure_integration
|
||||
from .const import IP
|
||||
|
@ -73,3 +78,28 @@ async def test_hass_stop(hass: HomeAssistant, mock_device: MockDevice) -> None:
|
|||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
mock_device.async_disconnect.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"device, expected_platforms",
|
||||
[
|
||||
["mock_device", (BINARY_SENSOR, DEVICE_TRACKER, SENSOR, SWITCH)],
|
||||
["mock_repeater_device", (DEVICE_TRACKER, SENSOR, SWITCH)],
|
||||
["mock_nonwifi_device", (BINARY_SENSOR, SENSOR, SWITCH)],
|
||||
],
|
||||
)
|
||||
async def test_platforms(
|
||||
hass: HomeAssistant,
|
||||
device: str,
|
||||
expected_platforms: set[str],
|
||||
request: pytest.FixtureRequest,
|
||||
):
|
||||
"""Test platform assembly."""
|
||||
request.getfixturevalue(device)
|
||||
entry = configure_integration(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
platforms = [platform.domain for platform in async_get_platforms(hass, DOMAIN)]
|
||||
assert len(platforms) == len(expected_platforms)
|
||||
assert all(platform in platforms for platform in expected_platforms)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue