mirror of
https://github.com/home-assistant/core.git
synced 2026-05-04 03:51:12 +02:00
Update SharkIQ authentication method (#151046)
This commit is contained in:
committed by
Franck Nijhof
parent
9a43f2776d
commit
ca79f4c963
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"]
|
||||
}
|
||||
|
||||
Generated
+1
-1
@@ -2768,7 +2768,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
|
||||
|
||||
Generated
+1
-1
@@ -2290,7 +2290,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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user