mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 00:20:30 +01:00
Skip unchanged connection check on reconfigure flow for Satel Integra (#166695)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import voluptuous as vol
|
||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from homeassistant.config_entries import (
|
||||
ConfigEntry,
|
||||
ConfigEntryState,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
ConfigSubentryFlow,
|
||||
@@ -163,7 +164,16 @@ class SatelConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
|
||||
|
||||
if await self.test_connection(user_input[CONF_HOST], user_input[CONF_PORT]):
|
||||
if (
|
||||
reconfigure_entry.state is not ConfigEntryState.LOADED
|
||||
or reconfigure_entry.data != user_input
|
||||
):
|
||||
if not await self.test_connection(
|
||||
user_input[CONF_HOST], user_input[CONF_PORT]
|
||||
):
|
||||
errors["base"] = "cannot_connect"
|
||||
|
||||
if not errors:
|
||||
return self.async_update_reload_and_abort(
|
||||
reconfigure_entry,
|
||||
data_updates={
|
||||
@@ -171,11 +181,8 @@ class SatelConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
CONF_PORT: user_input[CONF_PORT],
|
||||
},
|
||||
title=user_input[CONF_HOST],
|
||||
reload_even_if_entry_is_unchanged=False,
|
||||
)
|
||||
|
||||
errors["base"] = "cannot_connect"
|
||||
|
||||
suggested_values: dict[str, Any] = {
|
||||
**reconfigure_entry.data,
|
||||
**(user_input or {}),
|
||||
|
||||
@@ -16,7 +16,12 @@ from homeassistant.components.satel_integra.const import (
|
||||
DEFAULT_PORT,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_RECONFIGURE, SOURCE_USER, ConfigSubentry
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_RECONFIGURE,
|
||||
SOURCE_USER,
|
||||
ConfigEntryState,
|
||||
ConfigSubentry,
|
||||
)
|
||||
from homeassistant.const import CONF_CODE, CONF_HOST, CONF_NAME, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
@@ -363,6 +368,60 @@ async def test_reconfigure_flow_success(
|
||||
assert mock_setup_entry.call_count == 1
|
||||
|
||||
|
||||
async def test_reconfigure_flow_config_unchanged_loaded(
|
||||
hass: HomeAssistant,
|
||||
mock_satel: AsyncMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reconfigure skips connection testing if loaded config is unchanged."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reconfigure"
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], dict(mock_config_entry.data)
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert mock_config_entry.data == MOCK_CONFIG_DATA
|
||||
assert mock_satel.connect.call_count == 0
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert mock_setup_entry.call_count == 1
|
||||
|
||||
|
||||
async def test_reconfigure_flow_config_unchanged_not_loaded(
|
||||
hass: HomeAssistant,
|
||||
mock_satel: AsyncMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reconfigure validates unchanged config if the entry is not loaded."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reconfigure"
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], dict(mock_config_entry.data)
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert mock_config_entry.data == MOCK_CONFIG_DATA
|
||||
assert mock_satel.connect.call_count == 1
|
||||
assert mock_setup_entry.call_count == 1
|
||||
|
||||
|
||||
async def test_reconfigure_connection_failed(
|
||||
hass: HomeAssistant,
|
||||
mock_satel: AsyncMock,
|
||||
|
||||
Reference in New Issue
Block a user