SharkIQ Hotfix - Handle current installations by using default REGION
(#90741)
* Add default region on async_setup_entry * Move logic to migration function * Move update logic back to setup function, but updates the config if needed. * Remove commented out code * Update Tests & Config setting method * Update homeassistant/components/sharkiq/__init__.py Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update homeassistant/components/sharkiq/__init__.py Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Accept Suggestions & Formatting --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
8495da1af0
commit
1f7ebe9249
3 changed files with 40 additions and 2 deletions
|
@ -17,7 +17,14 @@ from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import API_TIMEOUT, DOMAIN, LOGGER, PLATFORMS, SHARKIQ_REGION_EUROPE
|
||||
from .const import (
|
||||
API_TIMEOUT,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
PLATFORMS,
|
||||
SHARKIQ_REGION_DEFAULT,
|
||||
SHARKIQ_REGION_EUROPE,
|
||||
)
|
||||
from .update_coordinator import SharkIqUpdateCoordinator
|
||||
|
||||
|
||||
|
@ -43,6 +50,12 @@ async def async_connect_or_timeout(ayla_api: AylaApi) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
"""Initialize the sharkiq platform via config entry."""
|
||||
if CONF_REGION not in config_entry.data:
|
||||
hass.config_entries.async_update_entry(
|
||||
config_entry,
|
||||
data={**config_entry.data, CONF_REGION: SHARKIQ_REGION_DEFAULT},
|
||||
)
|
||||
|
||||
ayla_api = get_ayla_api(
|
||||
username=config_entry.data[CONF_USERNAME],
|
||||
password=config_entry.data[CONF_PASSWORD],
|
||||
|
|
|
@ -76,4 +76,8 @@ CONFIG = {
|
|||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_REGION: TEST_REGION,
|
||||
}
|
||||
CONFIG_NO_REGION = {
|
||||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
}
|
||||
ENTRY_ID = "0123456789abcdef0123456789abcdef"
|
||||
|
|
|
@ -8,12 +8,32 @@ from sharkiq import AylaApi, SharkIqAuthError, SharkIqError
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.components.sharkiq.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .const import CONFIG, TEST_PASSWORD, TEST_REGION, TEST_USERNAME, UNIQUE_ID
|
||||
from .const import (
|
||||
CONFIG,
|
||||
CONFIG_NO_REGION,
|
||||
TEST_PASSWORD,
|
||||
TEST_REGION,
|
||||
TEST_USERNAME,
|
||||
UNIQUE_ID,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_setup_success_no_region(hass: HomeAssistant) -> None:
|
||||
"""Test reauth flow."""
|
||||
mock_config = MockConfigEntry(
|
||||
domain=DOMAIN, unique_id=UNIQUE_ID, data=CONFIG_NO_REGION
|
||||
)
|
||||
mock_config.add_to_hass(hass)
|
||||
|
||||
result = await async_setup_component(hass=hass, domain=DOMAIN, config=mock_config)
|
||||
|
||||
assert result is True
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant) -> None:
|
||||
"""Test we get the form."""
|
||||
|
||||
|
@ -39,6 +59,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
"password": TEST_PASSWORD,
|
||||
"region": TEST_REGION,
|
||||
}
|
||||
|
||||
await hass.async_block_till_done()
|
||||
mock_setup_entry.assert_called_once()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue