Improve Awair config flow (#76838)
This commit is contained in:
parent
3e1c9f1ac7
commit
c7d46bc719
6 changed files with 130 additions and 19 deletions
|
@ -240,6 +240,12 @@ async def test_create_local_entry(hass: HomeAssistant, local_devices):
|
|||
{"next_step_id": "local"},
|
||||
)
|
||||
|
||||
# We're being shown the local instructions
|
||||
form_step = await hass.config_entries.flow.async_configure(
|
||||
form_step["flow_id"],
|
||||
{},
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
form_step["flow_id"],
|
||||
LOCAL_CONFIG,
|
||||
|
@ -251,6 +257,48 @@ async def test_create_local_entry(hass: HomeAssistant, local_devices):
|
|||
assert result["result"].unique_id == LOCAL_UNIQUE_ID
|
||||
|
||||
|
||||
async def test_create_local_entry_from_discovery(hass: HomeAssistant, local_devices):
|
||||
"""Test local API when device discovered after instructions shown."""
|
||||
|
||||
menu_step = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=LOCAL_CONFIG
|
||||
)
|
||||
|
||||
form_step = await hass.config_entries.flow.async_configure(
|
||||
menu_step["flow_id"],
|
||||
{"next_step_id": "local"},
|
||||
)
|
||||
|
||||
# Create discovered entry in progress
|
||||
with patch("python_awair.AwairClient.query", side_effect=[local_devices]):
|
||||
await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
data=Mock(host=LOCAL_CONFIG[CONF_HOST]),
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
)
|
||||
|
||||
# We're being shown the local instructions
|
||||
form_step = await hass.config_entries.flow.async_configure(
|
||||
form_step["flow_id"],
|
||||
{},
|
||||
)
|
||||
|
||||
with patch("python_awair.AwairClient.query", side_effect=[local_devices]), patch(
|
||||
"homeassistant.components.awair.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
form_step["flow_id"],
|
||||
{"device": LOCAL_CONFIG[CONF_HOST]},
|
||||
)
|
||||
|
||||
print(result)
|
||||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Awair Element (24947)"
|
||||
assert result["data"][CONF_HOST] == LOCAL_CONFIG[CONF_HOST]
|
||||
assert result["result"].unique_id == LOCAL_UNIQUE_ID
|
||||
|
||||
|
||||
async def test_create_local_entry_awair_error(hass: HomeAssistant):
|
||||
"""Test overall flow when using local API and device is returns error."""
|
||||
|
||||
|
@ -267,6 +315,12 @@ async def test_create_local_entry_awair_error(hass: HomeAssistant):
|
|||
{"next_step_id": "local"},
|
||||
)
|
||||
|
||||
# We're being shown the local instructions
|
||||
form_step = await hass.config_entries.flow.async_configure(
|
||||
form_step["flow_id"],
|
||||
{},
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
form_step["flow_id"],
|
||||
LOCAL_CONFIG,
|
||||
|
@ -274,7 +328,7 @@ async def test_create_local_entry_awair_error(hass: HomeAssistant):
|
|||
|
||||
# User is returned to form to try again
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["step_id"] == "local"
|
||||
assert result["step_id"] == "local_pick"
|
||||
|
||||
|
||||
async def test_create_zeroconf_entry(hass: HomeAssistant, local_devices):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue