Skip to content

Commit

Permalink
SharkIQ Hotfix - Handle current installations by using default `REGIO…
Browse files Browse the repository at this point in the history
…N` (home-assistant#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>
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

funkybunch and frenck authored Apr 5, 2023
1 parent 8495da1 commit 1f7ebe9
Showing 3 changed files with 41 additions and 3 deletions.
15 changes: 14 additions & 1 deletion homeassistant/components/sharkiq/__init__.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,14 @@
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],
4 changes: 4 additions & 0 deletions tests/components/sharkiq/const.py
Original file line number Diff line number Diff line change
@@ -76,4 +76,8 @@
CONF_PASSWORD: TEST_PASSWORD,
CONF_REGION: TEST_REGION,
}
CONFIG_NO_REGION = {
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: TEST_PASSWORD,
}
ENTRY_ID = "0123456789abcdef0123456789abcdef"
25 changes: 23 additions & 2 deletions tests/components/sharkiq/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -8,12 +8,32 @@
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()

0 comments on commit 1f7ebe9

Please sign in to comment.