2019-12-08 08:26:31 +00:00
|
|
|
"""Tests for the Elgato Key Light integration."""
|
2022-01-14 16:16:59 +00:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
from elgato import ElgatoConnectionError
|
2019-12-08 08:26:31 +00:00
|
|
|
|
|
|
|
from homeassistant.components.elgato.const import DOMAIN
|
2021-05-20 17:19:20 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
2019-12-08 08:26:31 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2022-01-14 16:16:59 +00:00
|
|
|
from tests.common import MockConfigEntry
|
2019-12-08 08:26:31 +00:00
|
|
|
|
|
|
|
|
2022-01-14 16:16:59 +00:00
|
|
|
async def test_load_unload_config_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
mock_elgato: MagicMock,
|
2019-12-08 08:26:31 +00:00
|
|
|
) -> None:
|
2022-01-14 16:16:59 +00:00
|
|
|
"""Test the Elgato configuration entry loading/unloading."""
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
|
|
|
assert len(mock_elgato.info.mock_calls) == 1
|
|
|
|
|
|
|
|
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
2019-12-08 08:26:31 +00:00
|
|
|
|
2022-01-14 16:16:59 +00:00
|
|
|
assert not hass.data.get(DOMAIN)
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
2019-12-08 08:26:31 +00:00
|
|
|
|
|
|
|
|
2022-01-14 16:16:59 +00:00
|
|
|
async def test_config_entry_not_ready(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
mock_elgato: MagicMock,
|
2019-12-08 08:26:31 +00:00
|
|
|
) -> None:
|
2022-01-14 16:16:59 +00:00
|
|
|
"""Test the Elgato configuration entry not ready."""
|
2022-01-21 18:38:02 +00:00
|
|
|
mock_elgato.state.side_effect = ElgatoConnectionError
|
2019-12-08 08:26:31 +00:00
|
|
|
|
2022-01-14 16:16:59 +00:00
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
2019-12-08 08:26:31 +00:00
|
|
|
await hass.async_block_till_done()
|
2022-01-14 16:16:59 +00:00
|
|
|
|
2022-01-21 18:38:02 +00:00
|
|
|
assert len(mock_elgato.state.mock_calls) == 1
|
2022-01-14 16:16:59 +00:00
|
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|