2019-11-06 22:55:39 +00:00
|
|
|
"""Tests for the WLED integration."""
|
2021-06-11 09:36:54 +00:00
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
2021-01-01 21:31:56 +00:00
|
|
|
|
2020-06-03 00:29:49 +00:00
|
|
|
from wled import WLEDConnectionError
|
2019-11-06 22:55:39 +00:00
|
|
|
|
|
|
|
from homeassistant.components.wled.const import DOMAIN
|
2021-05-20 17:19:20 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
2019-11-06 22:55:39 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2021-06-11 09:36:54 +00:00
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
async def test_load_unload_config_entry(
|
|
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_wled: AsyncMock
|
|
|
|
) -> None:
|
|
|
|
"""Test the WLED configuration entry 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
|
|
|
|
|
|
|
|
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert not hass.data.get(DOMAIN)
|
2019-11-06 22:55:39 +00:00
|
|
|
|
|
|
|
|
2021-06-09 18:15:46 +00:00
|
|
|
@patch(
|
2021-06-11 09:36:54 +00:00
|
|
|
"homeassistant.components.wled.coordinator.WLED.request",
|
2021-06-09 18:15:46 +00:00
|
|
|
side_effect=WLEDConnectionError,
|
|
|
|
)
|
2019-11-06 22:55:39 +00:00
|
|
|
async def test_config_entry_not_ready(
|
2021-06-11 09:36:54 +00:00
|
|
|
mock_request: MagicMock, hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
2019-11-06 22:55:39 +00:00
|
|
|
) -> None:
|
|
|
|
"""Test the WLED configuration entry not ready."""
|
2021-06-11 09:36:54 +00:00
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
2019-11-06 22:55:39 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2021-06-11 09:36:54 +00:00
|
|
|
assert mock_request.call_count == 1
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
2019-11-06 22:55:39 +00:00
|
|
|
|
2020-01-04 21:48:31 +00:00
|
|
|
|
2021-06-11 09:36:54 +00:00
|
|
|
async def test_setting_unique_id(
|
|
|
|
hass: HomeAssistant, init_integration: MockConfigEntry
|
|
|
|
) -> None:
|
|
|
|
"""Test we set unique ID if not set yet."""
|
2020-01-04 21:48:31 +00:00
|
|
|
assert hass.data[DOMAIN]
|
2021-06-11 09:36:54 +00:00
|
|
|
assert init_integration.unique_id == "aabbccddeeff"
|