diff --git a/homeassistant/components/sharkiq/__init__.py b/homeassistant/components/sharkiq/__init__.py index 738dd595a5a7b1da360e9964f639a66fa720ab56..b6cae8ad6053b91240f98f055c7a11ed399e75b8 100644 --- a/homeassistant/components/sharkiq/__init__.py +++ b/homeassistant/components/sharkiq/__init__.py @@ -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], diff --git a/tests/components/sharkiq/const.py b/tests/components/sharkiq/const.py index 8ec7d424ffa164df3ed7a8c404ce0de7f9095d67..b4f9d72dafddb7d2fea94c0e1aeecf30a59d0c62 100644 --- a/tests/components/sharkiq/const.py +++ b/tests/components/sharkiq/const.py @@ -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" diff --git a/tests/components/sharkiq/test_config_flow.py b/tests/components/sharkiq/test_config_flow.py index c7a0603f8651c4b89d0e8a550ea36e35ba6023a5..248bb57f04c6447473186f4002e0d2098a4081f1 100644 --- a/tests/components/sharkiq/test_config_flow.py +++ b/tests/components/sharkiq/test_config_flow.py @@ -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 .const import CONFIG, TEST_PASSWORD, TEST_REGION, TEST_USERNAME, UNIQUE_ID +from homeassistant.setup import async_setup_component + +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()