mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Remove advanced mode dependency from sonarr config flow (#170487)
This commit is contained in:
@@ -19,9 +19,11 @@ from homeassistant.config_entries import (
|
||||
)
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import SectionConfig, section
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import (
|
||||
CONF_MORE_OPTIONS,
|
||||
CONF_UPCOMING_DAYS,
|
||||
CONF_WANTED_MAX_ITEMS,
|
||||
DEFAULT_UPCOMING_DAYS,
|
||||
@@ -91,6 +93,11 @@ class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors = {}
|
||||
|
||||
if user_input is not None:
|
||||
more_options = user_input.pop(CONF_MORE_OPTIONS, {})
|
||||
user_input[CONF_VERIFY_SSL] = more_options.get(
|
||||
CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL
|
||||
)
|
||||
|
||||
# aiopyarr defaults to the service port if one isn't given
|
||||
# this is counter to standard practice where http = 80
|
||||
# and https = 443.
|
||||
@@ -101,9 +108,6 @@ class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if self.source == SOURCE_REAUTH:
|
||||
user_input = {**self._get_reauth_entry().data, **user_input}
|
||||
|
||||
if CONF_VERIFY_SSL not in user_input:
|
||||
user_input[CONF_VERIFY_SSL] = DEFAULT_VERIFY_SSL
|
||||
|
||||
try:
|
||||
await _validate_input(self.hass, user_input)
|
||||
except ArrAuthenticationException:
|
||||
@@ -125,29 +129,33 @@ class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
title=parsed.host or "Sonarr", data=user_input
|
||||
)
|
||||
|
||||
data_schema = self._get_user_data_schema()
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(data_schema),
|
||||
data_schema=self._get_user_data_schema(),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
def _get_user_data_schema(self) -> dict[vol.Marker, type]:
|
||||
def _get_user_data_schema(self) -> vol.Schema:
|
||||
"""Get the data schema to display user form."""
|
||||
if self.source == SOURCE_REAUTH:
|
||||
return {vol.Required(CONF_API_KEY): str}
|
||||
return vol.Schema({vol.Required(CONF_API_KEY): str})
|
||||
|
||||
data_schema: dict[vol.Marker, type] = {
|
||||
vol.Required(CONF_URL): str,
|
||||
vol.Required(CONF_API_KEY): str,
|
||||
}
|
||||
|
||||
if self.show_advanced_options:
|
||||
data_schema[vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL)] = (
|
||||
bool
|
||||
)
|
||||
|
||||
return data_schema
|
||||
return vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_URL): str,
|
||||
vol.Required(CONF_API_KEY): str,
|
||||
vol.Required(CONF_MORE_OPTIONS): section(
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(
|
||||
CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL
|
||||
): bool,
|
||||
}
|
||||
),
|
||||
SectionConfig(collapsed=True),
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class SonarrOptionsFlowHandler(OptionsFlowWithReload):
|
||||
|
||||
@@ -9,6 +9,7 @@ DOMAIN: Final = "sonarr"
|
||||
CONF_BASE_PATH = "base_path"
|
||||
CONF_DAYS = "days"
|
||||
CONF_INCLUDED = "include_paths"
|
||||
CONF_MORE_OPTIONS = "more_options"
|
||||
CONF_UNIT = "unit"
|
||||
CONF_UPCOMING_DAYS = "upcoming_days"
|
||||
CONF_WANTED_MAX_ITEMS = "wanted_max_items"
|
||||
|
||||
@@ -18,8 +18,15 @@
|
||||
"user": {
|
||||
"data": {
|
||||
"api_key": "[%key:common::config_flow::data::api_key%]",
|
||||
"url": "[%key:common::config_flow::data::url%]",
|
||||
"verify_ssl": "[%key:common::config_flow::data::verify_ssl%]"
|
||||
"url": "[%key:common::config_flow::data::url%]"
|
||||
},
|
||||
"sections": {
|
||||
"more_options": {
|
||||
"data": {
|
||||
"verify_ssl": "[%key:common::config_flow::data::verify_ssl%]"
|
||||
},
|
||||
"name": "More options"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Tests for the Sonarr component."""
|
||||
|
||||
from homeassistant.components.sonarr.const import CONF_MORE_OPTIONS
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL
|
||||
|
||||
MOCK_REAUTH_INPUT = {CONF_API_KEY: "test-api-key-reauth"}
|
||||
@@ -7,4 +8,5 @@ MOCK_REAUTH_INPUT = {CONF_API_KEY: "test-api-key-reauth"}
|
||||
MOCK_USER_INPUT = {
|
||||
CONF_URL: "http://192.168.1.189:8989/",
|
||||
CONF_API_KEY: "MOCK_API_KEY",
|
||||
CONF_MORE_OPTIONS: {},
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ from unittest.mock import MagicMock, patch
|
||||
from aiopyarr import ArrAuthenticationException, ArrException
|
||||
|
||||
from homeassistant.components.sonarr.const import (
|
||||
CONF_MORE_OPTIONS,
|
||||
CONF_UPCOMING_DAYS,
|
||||
CONF_WANTED_MAX_ITEMS,
|
||||
DEFAULT_UPCOMING_DAYS,
|
||||
@@ -176,27 +177,25 @@ async def test_full_user_flow_implementation(
|
||||
assert result["data"][CONF_URL] == "http://192.168.1.189:8989/"
|
||||
|
||||
|
||||
async def test_full_user_flow_advanced_options(
|
||||
async def test_full_user_flow_with_verify_ssl(
|
||||
hass: HomeAssistant,
|
||||
mock_sonarr_config_flow: MagicMock,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test the full manual user flow with advanced options."""
|
||||
"""Test the full manual user flow with verify SSL option."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_USER, "show_advanced_options": True}
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
user_input = {
|
||||
**MOCK_USER_INPUT,
|
||||
CONF_VERIFY_SSL: True,
|
||||
}
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=user_input,
|
||||
user_input={
|
||||
**MOCK_USER_INPUT,
|
||||
CONF_MORE_OPTIONS: {CONF_VERIFY_SSL: True},
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
Reference in New Issue
Block a user