* Adding flow and async * Fixes to init * Lint and type * Fixed coveragerc file * Added Test Coverage * Added Update Listener and removed unused code * Wrong integration name in init. * Nothing * Added yaml import flow * Added YAML import functionality * Added back aladdin_connect files to coverage rc * Removed commented code * Clean up error message * Update homeassistant/components/aladdin_connect/__init__.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update homeassistant/components/aladdin_connect/__init__.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update homeassistant/components/aladdin_connect/config_flow.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Updated Documentation errors * recommended change broke cover.py - backed out * Cleaned up unused defenitions * implimented recommended changes from gjohansson * Dev environment cleanup * Raised errors for better recovery, replaced removed update files, utilized PLATFORM vars to init platform * Added back removal * Added Code Owner * Fixed more comment errors and import duplicates * Added test coverage and formated code * Added test coverage for model and init * Added test_cover for full testing coverage * Added await to async call * Added missing asserts to failure tests * Updated tranlsation * Fixed wording in yaml import function, white space in const.py, return from validate_input. * Update homeassistant/components/aladdin_connect/config_flow.py Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com> * "too much" whitespace * Added back mising strings.json errors * Added ConfigFlowReconfig and tests * Finished up reauth config flow and associated tests * Added reauth to strings, removed username from reauth * recommended changes, ran script.translations, added auth test to reauth * put back self.entry.data unpack. * Cleanup for error message, fixed missing "asserts" in tests * Added yaml import assertions * Fixed documentation errors in test_cover. * remove unused string. * revised tests and wording for yaml import * Documentation cleanup. * Changed sideeffect names Co-authored-by: G Johansson <goran.johansson@shiftit.se> Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
"""Test for Aladdin Connect init logic."""
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.components.aladdin_connect.const import DOMAIN
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
YAML_CONFIG = {"username": "test-user", "password": "test-password"}
|
|
|
|
|
|
async def test_unload_entry(hass: HomeAssistant):
|
|
"""Test successful unload of entry."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={"username": "test-user", "password": "test-password"},
|
|
)
|
|
entry.add_to_hass(hass)
|
|
|
|
with patch(
|
|
"homeassistant.components.aladdin_connect.cover.AladdinConnectClient.login",
|
|
return_value=True,
|
|
):
|
|
|
|
assert (await async_setup_component(hass, DOMAIN, entry)) is True
|
|
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
assert entry.state is ConfigEntryState.LOADED
|
|
|
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
async def test_entry_password_fail(hass: HomeAssistant):
|
|
"""Test successful unload of entry."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={"username": "test-user", "password": "test-password"},
|
|
)
|
|
entry.add_to_hass(hass)
|
|
|
|
with patch(
|
|
"homeassistant.components.aladdin_connect.cover.AladdinConnectClient.login",
|
|
return_value=False,
|
|
):
|
|
|
|
assert (await async_setup_component(hass, DOMAIN, entry)) is True
|
|
assert entry.state is ConfigEntryState.SETUP_ERROR
|
|
|
|
|
|
async def test_load_and_unload(hass: HomeAssistant) -> None:
|
|
"""Test loading and unloading Aladdin Connect entry."""
|
|
config_entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data=YAML_CONFIG,
|
|
unique_id="test-id",
|
|
)
|
|
config_entry.add_to_hass(hass)
|
|
with patch(
|
|
"homeassistant.components.aladdin_connect.cover.AladdinConnectClient.login",
|
|
return_value=True,
|
|
):
|
|
|
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert config_entry.state == ConfigEntryState.LOADED
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
|
|
assert await config_entry.async_unload(hass)
|
|
await hass.async_block_till_done()
|
|
assert config_entry.state == ConfigEntryState.NOT_LOADED
|