Skip to content

Commit ca79f4c

Browse files
funkybunchfrenck
authored andcommitted
Update SharkIQ authentication method (home-assistant#151046)
1 parent 9a43f27 commit ca79f4c

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

homeassistant/components/sharkiq/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
from contextlib import suppress
55

6+
import aiohttp
67
from sharkiq import (
78
AylaApi,
89
SharkIqAuthError,
@@ -15,7 +16,7 @@
1516
from homeassistant.config_entries import ConfigEntry
1617
from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
1718
from homeassistant.core import HomeAssistant
18-
from homeassistant.helpers.aiohttp_client import async_get_clientsession
19+
from homeassistant.helpers.aiohttp_client import async_create_clientsession
1920

2021
from .const import (
2122
API_TIMEOUT,
@@ -56,10 +57,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
5657
data={**config_entry.data, CONF_REGION: SHARKIQ_REGION_DEFAULT},
5758
)
5859

60+
new_websession = async_create_clientsession(
61+
hass,
62+
cookie_jar=aiohttp.CookieJar(unsafe=True, quote_cookie=False),
63+
)
64+
5965
ayla_api = get_ayla_api(
6066
username=config_entry.data[CONF_USERNAME],
6167
password=config_entry.data[CONF_PASSWORD],
62-
websession=async_get_clientsession(hass),
68+
websession=new_websession,
6369
europe=(config_entry.data[CONF_REGION] == SHARKIQ_REGION_EUROPE),
6470
)
6571

@@ -94,7 +100,7 @@ async def async_disconnect_or_timeout(coordinator: SharkIqUpdateCoordinator):
94100
await coordinator.ayla_api.async_sign_out()
95101

96102

97-
async def async_update_options(hass, config_entry):
103+
async def async_update_options(hass: HomeAssistant, config_entry):
98104
"""Update options."""
99105
await hass.config_entries.async_reload(config_entry.entry_id)
100106

homeassistant/components/sharkiq/config_flow.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from homeassistant.core import HomeAssistant
1616
from homeassistant.exceptions import HomeAssistantError
1717
from homeassistant.helpers import selector
18-
from homeassistant.helpers.aiohttp_client import async_get_clientsession
18+
from homeassistant.helpers.aiohttp_client import async_create_clientsession
1919

2020
from .const import (
2121
DOMAIN,
@@ -44,15 +44,19 @@ async def _validate_input(
4444
hass: HomeAssistant, data: Mapping[str, Any]
4545
) -> dict[str, str]:
4646
"""Validate the user input allows us to connect."""
47+
new_websession = async_create_clientsession(
48+
hass,
49+
cookie_jar=aiohttp.CookieJar(unsafe=True, quote_cookie=False),
50+
)
4751
ayla_api = get_ayla_api(
4852
username=data[CONF_USERNAME],
4953
password=data[CONF_PASSWORD],
50-
websession=async_get_clientsession(hass),
54+
websession=new_websession,
5155
europe=(data[CONF_REGION] == SHARKIQ_REGION_EUROPE),
5256
)
5357

5458
try:
55-
async with asyncio.timeout(10):
59+
async with asyncio.timeout(15):
5660
LOGGER.debug("Initialize connection to Ayla networks API")
5761
await ayla_api.async_sign_in()
5862
except (TimeoutError, aiohttp.ClientError, TypeError) as error:

homeassistant/components/sharkiq/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"documentation": "https://www.home-assistant.io/integrations/sharkiq",
77
"iot_class": "cloud_polling",
88
"loggers": ["sharkiq"],
9-
"requirements": ["sharkiq==1.1.1"]
9+
"requirements": ["sharkiq==1.4.0"]
1010
}

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/components/sharkiq/test_config_flow.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async def test_form(hass: HomeAssistant) -> None:
4747

4848
with (
4949
patch("sharkiq.AylaApi.async_sign_in", return_value=True),
50+
patch("sharkiq.AylaApi.async_set_cookie"),
5051
patch(
5152
"homeassistant.components.sharkiq.async_setup_entry",
5253
return_value=True,
@@ -84,7 +85,10 @@ async def test_form_error(hass: HomeAssistant, exc: Exception, base_error: str)
8485
DOMAIN, context={"source": config_entries.SOURCE_USER}
8586
)
8687

87-
with patch.object(AylaApi, "async_sign_in", side_effect=exc):
88+
with (
89+
patch.object(AylaApi, "async_sign_in", side_effect=exc),
90+
patch("sharkiq.AylaApi.async_set_cookie"),
91+
):
8892
result2 = await hass.config_entries.flow.async_configure(
8993
result["flow_id"],
9094
CONFIG,
@@ -101,7 +105,10 @@ async def test_reauth_success(hass: HomeAssistant) -> None:
101105

102106
result = await mock_config.start_reauth_flow(hass)
103107

104-
with patch("sharkiq.AylaApi.async_sign_in", return_value=True):
108+
with (
109+
patch("sharkiq.AylaApi.async_sign_in", return_value=True),
110+
patch("sharkiq.AylaApi.async_set_cookie"),
111+
):
105112
result = await hass.config_entries.flow.async_configure(
106113
result["flow_id"], user_input=CONFIG
107114
)
@@ -132,7 +139,10 @@ async def test_reauth(
132139

133140
result = await mock_config.start_reauth_flow(hass)
134141

135-
with patch("sharkiq.AylaApi.async_sign_in", side_effect=side_effect):
142+
with (
143+
patch("sharkiq.AylaApi.async_sign_in", side_effect=side_effect),
144+
patch("sharkiq.AylaApi.async_set_cookie"),
145+
):
136146
result = await hass.config_entries.flow.async_configure(
137147
result["flow_id"], user_input=CONFIG
138148
)

tests/components/sharkiq/test_vacuum.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class MockAyla(AylaApi):
8080
async def async_sign_in(self):
8181
"""Instead of signing in, just return."""
8282

83+
async def async_set_cookie(self):
84+
"""Instead of getting cookies, just return."""
85+
8386
async def async_refresh_auth(self):
8487
"""Instead of refreshing auth, just return."""
8588

0 commit comments

Comments
 (0)