diff --git a/homeassistant/components/satel_integra/config_flow.py b/homeassistant/components/satel_integra/config_flow.py index b70beaf6ba9..59c91ec5f8d 100644 --- a/homeassistant/components/satel_integra/config_flow.py +++ b/homeassistant/components/satel_integra/config_flow.py @@ -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 {}), diff --git a/tests/components/satel_integra/test_config_flow.py b/tests/components/satel_integra/test_config_flow.py index e5f48cbaea4..e43c05a88cc 100644 --- a/tests/components/satel_integra/test_config_flow.py +++ b/tests/components/satel_integra/test_config_flow.py @@ -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,