Roomba cleanups (#45097)
* Roomba cleanups Remove async_step_init backwards compat Move urls to description_placeholders. Fix typos * fix test * fix fallback to manual when roomba is in the wrong state
This commit is contained in:
parent
eebd0d333e
commit
ac60b34d17
4 changed files with 96 additions and 16 deletions
|
@ -65,6 +65,12 @@ def _mocked_failed_getpassword(*_):
|
|||
return roomba_password
|
||||
|
||||
|
||||
def _mocked_connection_refused_on_getpassword(*_):
|
||||
roomba_password = MagicMock()
|
||||
roomba_password.get_password = MagicMock(side_effect=ConnectionRefusedError)
|
||||
return roomba_password
|
||||
|
||||
|
||||
async def test_form_user_discovery_and_password_fetch(hass):
|
||||
"""Test we can discovery and fetch the password."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
@ -84,7 +90,7 @@ async def test_form_user_discovery_and_password_fetch(hass):
|
|||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] is None
|
||||
assert result["step_id"] == "init"
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
|
@ -195,7 +201,7 @@ async def test_form_user_discovery_manual_and_auto_password_fetch(hass):
|
|||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] is None
|
||||
assert result["step_id"] == "init"
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
|
@ -268,7 +274,7 @@ async def test_form_user_discovery_manual_and_auto_password_fetch_but_cannot_con
|
|||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] is None
|
||||
assert result["step_id"] == "init"
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
|
@ -504,3 +510,72 @@ async def test_form_user_discovery_fails_and_password_fetch_fails_and_cannot_con
|
|||
assert result4["errors"] == {"base": "cannot_connect"}
|
||||
assert len(mock_setup.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_form_user_discovery_and_password_fetch_gets_connection_refused(hass):
|
||||
"""Test we can discovery and fetch the password manually."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
mocked_roomba = _create_mocked_roomba(
|
||||
roomba_connected=True,
|
||||
master_state={"state": {"reported": {"name": "myroomba"}}},
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] is None
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: MOCK_IP},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result2["errors"] is None
|
||||
assert result2["step_id"] == "link"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaPassword",
|
||||
_mocked_connection_refused_on_getpassword,
|
||||
):
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.Roomba",
|
||||
return_value=mocked_roomba,
|
||||
), patch(
|
||||
"homeassistant.components.roomba.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.roomba.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result4 = await hass.config_entries.flow.async_configure(
|
||||
result3["flow_id"],
|
||||
{CONF_PASSWORD: "password"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result4["title"] == "myroomba"
|
||||
assert result4["result"].unique_id == "blid"
|
||||
assert result4["data"] == {
|
||||
CONF_BLID: "blid",
|
||||
CONF_CONTINUOUS: True,
|
||||
CONF_DELAY: 1,
|
||||
CONF_HOST: MOCK_IP,
|
||||
CONF_PASSWORD: "password",
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue