Address post-merge review comments from Vallox reconfigure support PR (#118903)
Address late review comments from Vallox reconfigure support PRpull/118969/head
parent
622a69447d
commit
a5959cfb83
|
@ -69,6 +69,26 @@ async def test_form_invalid_ip(hass: HomeAssistant) -> None:
|
|||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"host": "invalid_host"}
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.vallox.config_flow.Vallox.fetch_metric_data",
|
||||
return_value=None,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.vallox.async_setup_entry",
|
||||
return_value=True,
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
init["flow_id"],
|
||||
{"host": "1.2.3.4"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Vallox"
|
||||
assert result["data"] == {"host": "1.2.3.4", "name": "Vallox"}
|
||||
|
||||
|
||||
async def test_form_vallox_api_exception_cannot_connect(hass: HomeAssistant) -> None:
|
||||
"""Test that cannot connect error is handled."""
|
||||
|
@ -89,6 +109,26 @@ async def test_form_vallox_api_exception_cannot_connect(hass: HomeAssistant) ->
|
|||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"host": "cannot_connect"}
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.vallox.config_flow.Vallox.fetch_metric_data",
|
||||
return_value=None,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.vallox.async_setup_entry",
|
||||
return_value=True,
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
init["flow_id"],
|
||||
{"host": "1.2.3.4"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Vallox"
|
||||
assert result["data"] == {"host": "1.2.3.4", "name": "Vallox"}
|
||||
|
||||
|
||||
async def test_form_os_error_cannot_connect(hass: HomeAssistant) -> None:
|
||||
"""Test that cannot connect error is handled."""
|
||||
|
@ -109,6 +149,26 @@ async def test_form_os_error_cannot_connect(hass: HomeAssistant) -> None:
|
|||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"host": "cannot_connect"}
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.vallox.config_flow.Vallox.fetch_metric_data",
|
||||
return_value=None,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.vallox.async_setup_entry",
|
||||
return_value=True,
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
init["flow_id"],
|
||||
{"host": "1.2.3.4"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Vallox"
|
||||
assert result["data"] == {"host": "1.2.3.4", "name": "Vallox"}
|
||||
|
||||
|
||||
async def test_form_unknown_exception(hass: HomeAssistant) -> None:
|
||||
"""Test that unknown exceptions are handled."""
|
||||
|
@ -129,6 +189,26 @@ async def test_form_unknown_exception(hass: HomeAssistant) -> None:
|
|||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"host": "unknown"}
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.vallox.config_flow.Vallox.fetch_metric_data",
|
||||
return_value=None,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.vallox.async_setup_entry",
|
||||
return_value=True,
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
init["flow_id"],
|
||||
{"host": "1.2.3.4"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Vallox"
|
||||
assert result["data"] == {"host": "1.2.3.4", "name": "Vallox"}
|
||||
|
||||
|
||||
async def test_form_already_configured(hass: HomeAssistant) -> None:
|
||||
"""Test that already configured error is handled."""
|
||||
|
@ -209,6 +289,20 @@ async def test_reconfigure_host_to_invalid_ip_fails(
|
|||
# entry not changed
|
||||
assert entry.data["host"] == "192.168.100.50"
|
||||
|
||||
# makes sure we can recover and continue
|
||||
reconfigure_result = await hass.config_entries.flow.async_configure(
|
||||
init_flow_result["flow_id"],
|
||||
{
|
||||
"host": "192.168.100.60",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert reconfigure_result["type"] is FlowResultType.ABORT
|
||||
assert reconfigure_result["reason"] == "reconfigure_successful"
|
||||
|
||||
# changed entry
|
||||
assert entry.data["host"] == "192.168.100.60"
|
||||
|
||||
|
||||
async def test_reconfigure_host_vallox_api_exception_cannot_connect(
|
||||
hass: HomeAssistant, init_reconfigure_flow
|
||||
|
@ -234,6 +328,20 @@ async def test_reconfigure_host_vallox_api_exception_cannot_connect(
|
|||
# entry not changed
|
||||
assert entry.data["host"] == "192.168.100.50"
|
||||
|
||||
# makes sure we can recover and continue
|
||||
reconfigure_result = await hass.config_entries.flow.async_configure(
|
||||
init_flow_result["flow_id"],
|
||||
{
|
||||
"host": "192.168.100.60",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert reconfigure_result["type"] is FlowResultType.ABORT
|
||||
assert reconfigure_result["reason"] == "reconfigure_successful"
|
||||
|
||||
# changed entry
|
||||
assert entry.data["host"] == "192.168.100.60"
|
||||
|
||||
|
||||
async def test_reconfigure_host_unknown_exception(
|
||||
hass: HomeAssistant, init_reconfigure_flow
|
||||
|
@ -258,3 +366,17 @@ async def test_reconfigure_host_unknown_exception(
|
|||
|
||||
# entry not changed
|
||||
assert entry.data["host"] == "192.168.100.50"
|
||||
|
||||
# makes sure we can recover and continue
|
||||
reconfigure_result = await hass.config_entries.flow.async_configure(
|
||||
init_flow_result["flow_id"],
|
||||
{
|
||||
"host": "192.168.100.60",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert reconfigure_result["type"] is FlowResultType.ABORT
|
||||
assert reconfigure_result["reason"] == "reconfigure_successful"
|
||||
|
||||
# changed entry
|
||||
assert entry.data["host"] == "192.168.100.60"
|
||||
|
|
Loading…
Reference in New Issue