hass-core/tests/components/wled/test_init.py
Franck Nijhof 78b83c653a
Add WLED integration (#28542)
* Add WLED integration

* Use f-string for uniq id in sensor platform

* Typing improvements

* Removes sensor & light platform

* Remove PARALLEL_UPDATES from integration level

* Correct type in code comment 'themselves'

* Use async_track_time_interval in async context

* Remove stale code

* Remove decorator from Flow handler

* Remove unused __init__ from config flow

* Move show form methods to sync

* Only wrap lines that can raise in try except block

* Remove domain and platform from uniq id

* Wrap light state in bool object in is_on method

* Use async_schedule_update_ha_state in async context

* Return empty dict in device state attributes instead of None

* Remove unneeded setdefault call in setup entry

* Cancel update timer on entry unload

* Restructure config flow code

* Adjust tests for new uniq id

* Correct typo AdGuard Home -> WLED in config flow file comment

* Convert internal package imports to be relative

* Reformat JSON files with Prettier

* Improve tests based on review comments

* Add test for zeroconf when no data is provided

* Cleanup and extended tests
2019-11-06 23:55:39 +01:00

60 lines
1.9 KiB
Python

"""Tests for the WLED integration."""
import aiohttp
from asynctest import patch
from homeassistant.components.wled.const import DOMAIN
from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY
from homeassistant.const import STATE_ON
from homeassistant.core import HomeAssistant
from tests.components.wled import init_integration
from tests.test_util.aiohttp import AiohttpClientMocker
async def test_config_entry_not_ready(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the WLED configuration entry not ready."""
aioclient_mock.get("http://example.local:80/json/", exc=aiohttp.ClientError)
entry = await init_integration(hass, aioclient_mock)
assert entry.state == ENTRY_STATE_SETUP_RETRY
async def test_unload_config_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the WLED configuration entry unloading."""
entry = await init_integration(hass, aioclient_mock)
assert hass.data[DOMAIN]
await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert not hass.data.get(DOMAIN)
async def test_interval_update(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the WLED configuration entry unloading."""
entry = await init_integration(hass, aioclient_mock, skip_setup=True)
interval_action = False
def async_track_time_interval(hass, action, interval):
nonlocal interval_action
interval_action = action
with patch(
"homeassistant.components.wled.async_track_time_interval",
new=async_track_time_interval,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert interval_action
await interval_action() # pylint: disable=not-callable
await hass.async_block_till_done()
state = hass.states.get("light.wled_rgb_light")
assert state.state == STATE_ON