mirror of
https://github.com/home-assistant/core.git
synced 2026-04-19 00:10:21 +01:00
Add reconfigure flow to Airgradient (#136324)
* Add reconfigure flow to Airgradient * Update homeassistant/components/airgradient/strings.json --------- Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
committed by
GitHub
parent
093c41cd83
commit
132f418f92
@@ -296,3 +296,99 @@ async def test_user_flow_works_discovery(
|
||||
|
||||
# Verify the discovery flow was aborted
|
||||
assert not hass.config_entries.flow.async_progress(DOMAIN)
|
||||
|
||||
|
||||
async def test_reconfigure_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_new_airgradient_client: AsyncMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reconfigure flow."""
|
||||
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"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "10.0.0.131"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert mock_config_entry.data == {
|
||||
CONF_HOST: "10.0.0.131",
|
||||
}
|
||||
|
||||
|
||||
async def test_reconfigure_flow_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_new_airgradient_client: AsyncMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reconfigure flow."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
mock_new_airgradient_client.get_current_measures.side_effect = (
|
||||
AirGradientConnectionError()
|
||||
)
|
||||
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "10.0.0.132"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
mock_new_airgradient_client.get_current_measures.side_effect = None
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "10.0.0.132"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert mock_config_entry.data == {
|
||||
CONF_HOST: "10.0.0.132",
|
||||
}
|
||||
|
||||
|
||||
async def test_reconfigure_flow_unique_id_mismatch(
|
||||
hass: HomeAssistant,
|
||||
mock_new_airgradient_client: AsyncMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test reconfigure flow aborts with unique id mismatch."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
mock_new_airgradient_client.get_current_measures.return_value.serial_number = (
|
||||
"84fce612f5b9"
|
||||
)
|
||||
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "10.0.0.132"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "unique_id_mismatch"
|
||||
assert mock_config_entry.data == {
|
||||
CONF_HOST: "10.0.0.131",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user