mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 06:15:47 -04:00
Reload Transmission on config options changing (#182847)
This commit is contained in:
@@ -14,7 +14,7 @@ from homeassistant.config_entries import (
|
||||
ConfigEntry,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlow,
|
||||
OptionsFlowWithReload,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
@@ -79,7 +79,10 @@ class TransmissionFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
if user_input is not None:
|
||||
self._async_abort_entries_match(
|
||||
{CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
|
||||
{
|
||||
CONF_HOST: user_input[CONF_HOST],
|
||||
CONF_PORT: user_input[CONF_PORT],
|
||||
}
|
||||
)
|
||||
try:
|
||||
api = await get_api(self.hass, user_input)
|
||||
@@ -151,7 +154,7 @@ class TransmissionFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
|
||||
|
||||
class TransmissionOptionsFlowHandler(OptionsFlow):
|
||||
class TransmissionOptionsFlowHandler(OptionsFlowWithReload):
|
||||
"""Handle Transmission client options."""
|
||||
|
||||
async def async_step_init(
|
||||
|
||||
@@ -12,6 +12,7 @@ from transmission_rpc.error import (
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import transmission
|
||||
from homeassistant.components.transmission.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
@@ -64,9 +65,9 @@ async def test_device_already_configured(
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_transmission_client")
|
||||
async def test_options(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test updating options."""
|
||||
entry = MockConfigEntry(
|
||||
@@ -74,23 +75,20 @@ async def test_options(
|
||||
data=MOCK_CONFIG_DATA,
|
||||
options={"limit": 10, "order": "oldest_first"},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.transmission.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await setup_integration(hass, entry)
|
||||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={"limit": 20}
|
||||
)
|
||||
with patch.object(hass.config_entries, "async_reload") as mock_reload:
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={"limit": 20}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mock_reload.assert_awaited_once_with(entry.entry_id)
|
||||
|
||||
assert result["data"]["limit"] == 20
|
||||
assert result["data"]["order"] == "oldest_first"
|
||||
@@ -232,6 +230,50 @@ async def test_reauth_success(
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
|
||||
|
||||
async def test_reauth_success_after_setup_error(
|
||||
hass: HomeAssistant,
|
||||
mock_transmission_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reauth retries an entry that failed during setup."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
mock_transmission_client.side_effect = TransmissionAuthError()
|
||||
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
mock_transmission_client.side_effect = None
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
with patch.object(hass.config_entries, "async_schedule_reload") as mock_reload:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"password": "test-password"}
|
||||
)
|
||||
|
||||
mock_reload.assert_called_once_with(mock_config_entry.entry_id)
|
||||
assert result["reason"] == "reauth_successful"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
|
||||
|
||||
async def test_reauth_success_when_credentials_are_unchanged(
|
||||
hass: HomeAssistant,
|
||||
mock_transmission_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reauth reloads when the credentials are unchanged."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
with patch.object(hass.config_entries, "async_schedule_reload") as mock_reload:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"password": "pass"}
|
||||
)
|
||||
|
||||
mock_reload.assert_called_once_with(mock_config_entry.entry_id)
|
||||
assert result["reason"] == "reauth_successful"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("exception", "field", "error"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user