Bump aiopyarr to 22.9.0 (#79173)

This commit is contained in:
Robert Hillis 2022-09-28 02:06:24 -04:00 committed by GitHub
parent 0c191df598
commit e360a4fa9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 42 deletions

View File

@ -5,7 +5,7 @@ from collections.abc import Mapping
from typing import Any from typing import Any
from aiohttp import ClientConnectorError from aiohttp import ClientConnectorError
from aiopyarr import SystemStatus, exceptions from aiopyarr import exceptions
from aiopyarr.lidarr_client import LidarrClient from aiopyarr.lidarr_client import LidarrClient
import voluptuous as vol import voluptuous as vol
@ -54,15 +54,16 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN):
else: else:
try: try:
result = await validate_input(self.hass, user_input) if result := await validate_input(self.hass, user_input):
if isinstance(result, tuple):
user_input[CONF_API_KEY] = result[1] user_input[CONF_API_KEY] = result[1]
elif isinstance(result, str):
errors = {"base": result}
except exceptions.ArrAuthenticationException: except exceptions.ArrAuthenticationException:
errors = {"base": "invalid_auth"} errors = {"base": "invalid_auth"}
except (ClientConnectorError, exceptions.ArrConnectionException): except (ClientConnectorError, exceptions.ArrConnectionException):
errors = {"base": "cannot_connect"} errors = {"base": "cannot_connect"}
except exceptions.ArrWrongAppException:
errors = {"base": "wrong_app"}
except exceptions.ArrZeroConfException:
errors = {"base": "zeroconf_failed"}
except exceptions.ArrException: except exceptions.ArrException:
errors = {"base": "unknown"} errors = {"base": "unknown"}
if not errors: if not errors:
@ -95,7 +96,7 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN):
async def validate_input( async def validate_input(
hass: HomeAssistant, data: dict[str, Any] hass: HomeAssistant, data: dict[str, Any]
) -> tuple[str, str, str] | str | SystemStatus: ) -> tuple[str, str, str] | None:
"""Validate the user input allows us to connect. """Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user. Data has the keys from DATA_SCHEMA with values provided by the user.
@ -108,4 +109,5 @@ async def validate_input(
) )
if CONF_API_KEY not in data: if CONF_API_KEY not in data:
return await lidarr.async_try_zeroconf() return await lidarr.async_try_zeroconf()
return await lidarr.async_get_system_status() await lidarr.async_get_system_status()
return None

View File

@ -2,7 +2,7 @@
"domain": "lidarr", "domain": "lidarr",
"name": "Lidarr", "name": "Lidarr",
"documentation": "https://www.home-assistant.io/integrations/lidarr", "documentation": "https://www.home-assistant.io/integrations/lidarr",
"requirements": ["aiopyarr==22.7.0"], "requirements": ["aiopyarr==22.9.0"],
"codeowners": ["@tkdrob"], "codeowners": ["@tkdrob"],
"config_flow": true, "config_flow": true,
"iot_class": "local_polling", "iot_class": "local_polling",

View File

@ -62,15 +62,16 @@ class RadarrConfigFlow(ConfigFlow, domain=DOMAIN):
else: else:
try: try:
result = await validate_input(self.hass, user_input) if result := await validate_input(self.hass, user_input):
if isinstance(result, tuple):
user_input[CONF_API_KEY] = result[1] user_input[CONF_API_KEY] = result[1]
elif isinstance(result, str):
errors = {"base": result}
except exceptions.ArrAuthenticationException: except exceptions.ArrAuthenticationException:
errors = {"base": "invalid_auth"} errors = {"base": "invalid_auth"}
except (ClientConnectorError, exceptions.ArrConnectionException): except (ClientConnectorError, exceptions.ArrConnectionException):
errors = {"base": "cannot_connect"} errors = {"base": "cannot_connect"}
except exceptions.ArrWrongAppException:
errors = {"base": "wrong_app"}
except exceptions.ArrZeroConfException:
errors = {"base": "zeroconf_failed"}
except exceptions.ArrException: except exceptions.ArrException:
errors = {"base": "unknown"} errors = {"base": "unknown"}
if not errors: if not errors:
@ -130,7 +131,7 @@ class RadarrConfigFlow(ConfigFlow, domain=DOMAIN):
async def validate_input( async def validate_input(
hass: HomeAssistant, data: dict[str, Any] hass: HomeAssistant, data: dict[str, Any]
) -> tuple[str, str, str] | str | None: ) -> tuple[str, str, str] | None:
"""Validate the user input allows us to connect.""" """Validate the user input allows us to connect."""
host_configuration = PyArrHostConfiguration( host_configuration = PyArrHostConfiguration(
api_token=data.get(CONF_API_KEY, ""), api_token=data.get(CONF_API_KEY, ""),

View File

@ -2,7 +2,7 @@
"domain": "radarr", "domain": "radarr",
"name": "Radarr", "name": "Radarr",
"documentation": "https://www.home-assistant.io/integrations/radarr", "documentation": "https://www.home-assistant.io/integrations/radarr",
"requirements": ["aiopyarr==22.7.0"], "requirements": ["aiopyarr==22.9.0"],
"codeowners": ["@tkdrob"], "codeowners": ["@tkdrob"],
"config_flow": true, "config_flow": true,
"iot_class": "local_polling", "iot_class": "local_polling",

View File

@ -3,7 +3,7 @@
"name": "Sonarr", "name": "Sonarr",
"documentation": "https://www.home-assistant.io/integrations/sonarr", "documentation": "https://www.home-assistant.io/integrations/sonarr",
"codeowners": ["@ctalkington"], "codeowners": ["@ctalkington"],
"requirements": ["aiopyarr==22.7.0"], "requirements": ["aiopyarr==22.9.0"],
"config_flow": true, "config_flow": true,
"quality_scale": "silver", "quality_scale": "silver",
"iot_class": "local_polling", "iot_class": "local_polling",

View File

@ -237,7 +237,7 @@ aiopvpc==3.0.0
# homeassistant.components.lidarr # homeassistant.components.lidarr
# homeassistant.components.radarr # homeassistant.components.radarr
# homeassistant.components.sonarr # homeassistant.components.sonarr
aiopyarr==22.7.0 aiopyarr==22.9.0
# homeassistant.components.qnap_qsw # homeassistant.components.qnap_qsw
aioqsw==0.2.2 aioqsw==0.2.2

View File

@ -212,7 +212,7 @@ aiopvpc==3.0.0
# homeassistant.components.lidarr # homeassistant.components.lidarr
# homeassistant.components.radarr # homeassistant.components.radarr
# homeassistant.components.sonarr # homeassistant.components.sonarr
aiopyarr==22.7.0 aiopyarr==22.9.0
# homeassistant.components.qnap_qsw # homeassistant.components.qnap_qsw
aioqsw==0.2.2 aioqsw==0.2.2

View File

@ -1,7 +1,7 @@
"""Test Lidarr config flow.""" """Test Lidarr config flow."""
from unittest.mock import patch from unittest.mock import patch
from aiopyarr import ArrAuthenticationException, ArrConnectionException, ArrException from aiopyarr import exceptions
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.lidarr.const import DEFAULT_NAME, DOMAIN from homeassistant.components.lidarr.const import DEFAULT_NAME, DOMAIN
@ -45,7 +45,7 @@ async def test_flow_user_form(
async def test_flow_user_invalid_auth(hass: HomeAssistant) -> None: async def test_flow_user_invalid_auth(hass: HomeAssistant) -> None:
"""Test invalid authentication.""" """Test invalid authentication."""
with _patch_client() as client: with _patch_client() as client:
client.side_effect = ArrAuthenticationException client.side_effect = exceptions.ArrAuthenticationException
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: SOURCE_USER}, context={CONF_SOURCE: SOURCE_USER},
@ -62,7 +62,7 @@ async def test_flow_user_invalid_auth(hass: HomeAssistant) -> None:
async def test_flow_user_cannot_connect(hass: HomeAssistant) -> None: async def test_flow_user_cannot_connect(hass: HomeAssistant) -> None:
"""Test connection error.""" """Test connection error."""
with _patch_client() as client: with _patch_client() as client:
client.side_effect = ArrConnectionException client.side_effect = exceptions.ArrConnectionException
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: SOURCE_USER}, context={CONF_SOURCE: SOURCE_USER},
@ -76,10 +76,44 @@ async def test_flow_user_cannot_connect(hass: HomeAssistant) -> None:
assert result["errors"]["base"] == "cannot_connect" assert result["errors"]["base"] == "cannot_connect"
async def test_wrong_app(hass: HomeAssistant) -> None:
"""Test we show user form on wrong app."""
with patch(
"homeassistant.components.lidarr.config_flow.LidarrClient.async_try_zeroconf",
side_effect=exceptions.ArrWrongAppException,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_USER},
data=MOCK_USER_INPUT,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"]["base"] == "wrong_app"
async def test_zero_conf_failure(hass: HomeAssistant) -> None:
"""Test we show user form on api key retrieval failure."""
with patch(
"homeassistant.components.lidarr.config_flow.LidarrClient.async_try_zeroconf",
side_effect=exceptions.ArrZeroConfException,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_USER},
data=MOCK_USER_INPUT,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"]["base"] == "zeroconf_failed"
async def test_flow_user_unknown_error(hass: HomeAssistant) -> None: async def test_flow_user_unknown_error(hass: HomeAssistant) -> None:
"""Test unknown error.""" """Test unknown error."""
with _patch_client() as client: with _patch_client() as client:
client.side_effect = ArrException client.side_effect = exceptions.ArrException
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: SOURCE_USER}, context={CONF_SOURCE: SOURCE_USER},
@ -93,23 +127,6 @@ async def test_flow_user_unknown_error(hass: HomeAssistant) -> None:
assert result["errors"]["base"] == "unknown" assert result["errors"]["base"] == "unknown"
async def test_flow_user_failed_zeroconf(hass: HomeAssistant) -> None:
"""Test zero configuration failed."""
with _patch_client() as client:
client.return_value = "zeroconf_failed"
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_USER},
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input=CONF_DATA,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"]["base"] == "zeroconf_failed"
async def test_flow_reauth( async def test_flow_reauth(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None: ) -> None:

View File

@ -1,7 +1,7 @@
"""Test Radarr config flow.""" """Test Radarr config flow."""
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from aiopyarr import ArrException from aiopyarr import exceptions
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.radarr.const import DEFAULT_NAME, DOMAIN from homeassistant.components.radarr.const import DEFAULT_NAME, DOMAIN
@ -115,7 +115,7 @@ async def test_wrong_app(hass: HomeAssistant) -> None:
"""Test we show user form on wrong app.""" """Test we show user form on wrong app."""
with patch( with patch(
"homeassistant.components.radarr.config_flow.RadarrClient.async_try_zeroconf", "homeassistant.components.radarr.config_flow.RadarrClient.async_try_zeroconf",
return_value="wrong_app", side_effect=exceptions.ArrWrongAppException,
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -125,14 +125,31 @@ async def test_wrong_app(hass: HomeAssistant) -> None:
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"] == {"base": "wrong_app"} assert result["errors"]["base"] == "wrong_app"
async def test_zero_conf_failure(hass: HomeAssistant) -> None:
"""Test we show user form on api key retrieval failure."""
with patch(
"homeassistant.components.radarr.config_flow.RadarrClient.async_try_zeroconf",
side_effect=exceptions.ArrZeroConfException,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_USER},
data={CONF_URL: URL, CONF_VERIFY_SSL: False},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"]["base"] == "zeroconf_failed"
async def test_unknown_error(hass: HomeAssistant) -> None: async def test_unknown_error(hass: HomeAssistant) -> None:
"""Test we show user form on unknown error.""" """Test we show user form on unknown error."""
with patch( with patch(
"homeassistant.components.radarr.config_flow.RadarrClient.async_get_system_status", "homeassistant.components.radarr.config_flow.RadarrClient.async_get_system_status",
side_effect=ArrException, side_effect=exceptions.ArrException,
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,