mirror of
https://github.com/home-assistant/core.git
synced 2026-01-25 00:52:39 +01:00
* Add twinkly integration * Add tests for the Twinkly integration * Update Twinkly client package to fix typo * Remove support of configuration.yaml from Twinkly integration * Add ability to unload Twinkly component from the UI * Remove dead code from Twinkly * Fix invalid error namespace in Twinkly for python 3.7 * Fix tests failing on CI * Workaround code analysis issue * Move twinkly client init out of entry setup so it can be re-used between entries * Test the twinkly component initialization * React to PR review and add few more tests
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
"""Tests of the initialization of the twinly integration."""
|
|
|
|
from uuid import uuid4
|
|
|
|
from homeassistant.components.twinkly import async_setup_entry, async_unload_entry
|
|
from homeassistant.components.twinkly.const import (
|
|
CONF_ENTRY_HOST,
|
|
CONF_ENTRY_ID,
|
|
CONF_ENTRY_MODEL,
|
|
CONF_ENTRY_NAME,
|
|
DOMAIN as TWINKLY_DOMAIN,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.async_mock import patch
|
|
from tests.common import MockConfigEntry
|
|
from tests.components.twinkly import TEST_HOST, TEST_MODEL, TEST_NAME_ORIGINAL
|
|
|
|
|
|
async def test_setup_entry(hass: HomeAssistant):
|
|
"""Validate that setup entry also configure the client."""
|
|
|
|
id = str(uuid4())
|
|
config_entry = MockConfigEntry(
|
|
domain=TWINKLY_DOMAIN,
|
|
data={
|
|
CONF_ENTRY_HOST: TEST_HOST,
|
|
CONF_ENTRY_ID: id,
|
|
CONF_ENTRY_NAME: TEST_NAME_ORIGINAL,
|
|
CONF_ENTRY_MODEL: TEST_MODEL,
|
|
},
|
|
entry_id=id,
|
|
)
|
|
|
|
def setup_mock(_, __):
|
|
return True
|
|
|
|
with patch(
|
|
"homeassistant.config_entries.ConfigEntries.async_forward_entry_setup",
|
|
side_effect=setup_mock,
|
|
):
|
|
await async_setup_entry(hass, config_entry)
|
|
|
|
assert hass.data[TWINKLY_DOMAIN][id] is not None
|
|
|
|
|
|
async def test_unload_entry(hass: HomeAssistant):
|
|
"""Validate that unload entry also clear the client."""
|
|
|
|
id = str(uuid4())
|
|
config_entry = MockConfigEntry(
|
|
domain=TWINKLY_DOMAIN,
|
|
data={
|
|
CONF_ENTRY_HOST: TEST_HOST,
|
|
CONF_ENTRY_ID: id,
|
|
CONF_ENTRY_NAME: TEST_NAME_ORIGINAL,
|
|
CONF_ENTRY_MODEL: TEST_MODEL,
|
|
},
|
|
entry_id=id,
|
|
)
|
|
|
|
# Put random content at the location where the client should have been placed by setup
|
|
hass.data.setdefault(TWINKLY_DOMAIN, {})[id] = config_entry
|
|
|
|
await async_unload_entry(hass, config_entry)
|
|
|
|
assert hass.data[TWINKLY_DOMAIN].get(id) is None
|