diff --git a/homeassistant/components/sharkiq/__init__.py b/homeassistant/components/sharkiq/__init__.py index e560bb77b57..b87f52ba7b1 100644 --- a/homeassistant/components/sharkiq/__init__.py +++ b/homeassistant/components/sharkiq/__init__.py @@ -3,6 +3,7 @@ import asyncio from contextlib import suppress +import aiohttp from sharkiq import ( AylaApi, SharkIqAuthError, @@ -15,7 +16,7 @@ from homeassistant import exceptions from homeassistant.config_entries import ConfigEntry 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 homeassistant.helpers.aiohttp_client import async_create_clientsession from .const import ( API_TIMEOUT, @@ -56,10 +57,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b data={**config_entry.data, CONF_REGION: SHARKIQ_REGION_DEFAULT}, ) + new_websession = async_create_clientsession( + hass, + cookie_jar=aiohttp.CookieJar(unsafe=True, quote_cookie=False), + ) + ayla_api = get_ayla_api( username=config_entry.data[CONF_USERNAME], password=config_entry.data[CONF_PASSWORD], - websession=async_get_clientsession(hass), + websession=new_websession, europe=(config_entry.data[CONF_REGION] == SHARKIQ_REGION_EUROPE), ) @@ -94,7 +100,7 @@ async def async_disconnect_or_timeout(coordinator: SharkIqUpdateCoordinator): await coordinator.ayla_api.async_sign_out() -async def async_update_options(hass, config_entry): +async def async_update_options(hass: HomeAssistant, config_entry): """Update options.""" await hass.config_entries.async_reload(config_entry.entry_id) diff --git a/homeassistant/components/sharkiq/config_flow.py b/homeassistant/components/sharkiq/config_flow.py index 87367fcf093..7174c634787 100644 --- a/homeassistant/components/sharkiq/config_flow.py +++ b/homeassistant/components/sharkiq/config_flow.py @@ -15,7 +15,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import selector -from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.aiohttp_client import async_create_clientsession from .const import ( DOMAIN, @@ -44,15 +44,19 @@ async def _validate_input( hass: HomeAssistant, data: Mapping[str, Any] ) -> dict[str, str]: """Validate the user input allows us to connect.""" + new_websession = async_create_clientsession( + hass, + cookie_jar=aiohttp.CookieJar(unsafe=True, quote_cookie=False), + ) ayla_api = get_ayla_api( username=data[CONF_USERNAME], password=data[CONF_PASSWORD], - websession=async_get_clientsession(hass), + websession=new_websession, europe=(data[CONF_REGION] == SHARKIQ_REGION_EUROPE), ) try: - async with asyncio.timeout(10): + async with asyncio.timeout(15): LOGGER.debug("Initialize connection to Ayla networks API") await ayla_api.async_sign_in() except (TimeoutError, aiohttp.ClientError, TypeError) as error: diff --git a/homeassistant/components/sharkiq/manifest.json b/homeassistant/components/sharkiq/manifest.json index c29fc582462..793f65483ea 100644 --- a/homeassistant/components/sharkiq/manifest.json +++ b/homeassistant/components/sharkiq/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/sharkiq", "iot_class": "cloud_polling", "loggers": ["sharkiq"], - "requirements": ["sharkiq==1.1.1"] + "requirements": ["sharkiq==1.4.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 1621210affa..f748ce835ac 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2771,7 +2771,7 @@ sentry-sdk==1.45.1 sfrbox-api==0.0.12 # homeassistant.components.sharkiq -sharkiq==1.1.1 +sharkiq==1.4.0 # homeassistant.components.aquostv sharp_aquos_rc==0.3.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 988cb55718d..09366052d24 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2293,7 +2293,7 @@ sentry-sdk==1.45.1 sfrbox-api==0.0.12 # homeassistant.components.sharkiq -sharkiq==1.1.1 +sharkiq==1.4.0 # homeassistant.components.simplefin simplefin4py==0.0.18 diff --git a/tests/components/sharkiq/test_config_flow.py b/tests/components/sharkiq/test_config_flow.py index 22a77678c0d..f96b2f31e0b 100644 --- a/tests/components/sharkiq/test_config_flow.py +++ b/tests/components/sharkiq/test_config_flow.py @@ -47,6 +47,7 @@ async def test_form(hass: HomeAssistant) -> None: with ( patch("sharkiq.AylaApi.async_sign_in", return_value=True), + patch("sharkiq.AylaApi.async_set_cookie"), patch( "homeassistant.components.sharkiq.async_setup_entry", return_value=True, @@ -84,7 +85,10 @@ async def test_form_error(hass: HomeAssistant, exc: Exception, base_error: str) DOMAIN, context={"source": config_entries.SOURCE_USER} ) - with patch.object(AylaApi, "async_sign_in", side_effect=exc): + with ( + patch.object(AylaApi, "async_sign_in", side_effect=exc), + patch("sharkiq.AylaApi.async_set_cookie"), + ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], CONFIG, @@ -101,7 +105,10 @@ async def test_reauth_success(hass: HomeAssistant) -> None: result = await mock_config.start_reauth_flow(hass) - with patch("sharkiq.AylaApi.async_sign_in", return_value=True): + with ( + patch("sharkiq.AylaApi.async_sign_in", return_value=True), + patch("sharkiq.AylaApi.async_set_cookie"), + ): result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=CONFIG ) @@ -132,7 +139,10 @@ async def test_reauth( result = await mock_config.start_reauth_flow(hass) - with patch("sharkiq.AylaApi.async_sign_in", side_effect=side_effect): + with ( + patch("sharkiq.AylaApi.async_sign_in", side_effect=side_effect), + patch("sharkiq.AylaApi.async_set_cookie"), + ): result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=CONFIG ) diff --git a/tests/components/sharkiq/test_vacuum.py b/tests/components/sharkiq/test_vacuum.py index bfb2176026b..5b5339ec7a2 100644 --- a/tests/components/sharkiq/test_vacuum.py +++ b/tests/components/sharkiq/test_vacuum.py @@ -80,6 +80,9 @@ class MockAyla(AylaApi): async def async_sign_in(self): """Instead of signing in, just return.""" + async def async_set_cookie(self): + """Instead of getting cookies, just return.""" + async def async_refresh_auth(self): """Instead of refreshing auth, just return."""