Fix manual setup when roomba is on different subnet (#54639)

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Franck Nijhof <git@frenck.dev>
pull/55006/head
Jørgen Rørvik 2021-08-22 03:01:41 +02:00 committed by GitHub
parent 45baf88862
commit b942454312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 70 deletions

View File

@ -175,17 +175,20 @@ class RoombaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
step_id="manual",
description_placeholders={AUTH_HELP_URL_KEY: AUTH_HELP_URL_VALUE},
data_schema=vol.Schema(
{
vol.Required(CONF_HOST, default=self.host): str,
vol.Required(CONF_BLID, default=self.blid): str,
}
{vol.Required(CONF_HOST, default=self.host): str}
),
)
self._async_abort_entries_match({CONF_HOST: user_input["host"]})
self.host = user_input[CONF_HOST]
self.blid = user_input[CONF_BLID].upper()
devices = await _async_discover_roombas(self.hass, self.host)
if not devices:
return self.async_abort(reason="cannot_connect")
self.blid = devices[0].blid
self.name = devices[0].robot_name
await self.async_set_unique_id(self.blid, raise_on_progress=False)
self._abort_if_unique_id_configured()
return await self.async_step_link()

View File

@ -11,10 +11,9 @@
},
"manual": {
"title": "Manually connect to the device",
"description": "No Roomba or Braava have been discovered on your network. The BLID is the portion of the device hostname after `iRobot-` or `Roomba-`. Please follow the steps outlined in the documentation at: {auth_help_url}",
"description": "No Roomba or Braava have been discovered on your network.",
"data": {
"host": "[%key:common::config_flow::data::host%]",
"blid": "BLID"
"host": "[%key:common::config_flow::data::host%]"
}
},
"link": {

View File

@ -31,10 +31,9 @@
},
"manual": {
"data": {
"blid": "BLID",
"host": "Host"
},
"description": "No Roomba or Braava have been discovered on your network. The BLID is the portion of the device hostname after `iRobot-` or `Roomba-`. Please follow the steps outlined in the documentation at: {auth_help_url}",
"description": "No Roomba or Braava have been discovered on your network.",
"title": "Manually connect to the device"
},
"user": {

View File

@ -213,7 +213,7 @@ async def test_form_user_no_devices_found_discovery_aborts_already_configured(ha
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT
@ -250,10 +250,14 @@ async def test_form_user_discovery_manual_and_auto_password_fetch(hass):
assert result2["errors"] is None
assert result2["step_id"] == "manual"
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
):
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result3["errors"] is None
@ -275,7 +279,7 @@ async def test_form_user_discovery_manual_and_auto_password_fetch(hass):
await hass.async_block_till_done()
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result4["title"] == "myroomba"
assert result4["title"] == "robot_name"
assert result4["result"].unique_id == "BLID"
assert result4["data"] == {
CONF_BLID: "BLID",
@ -309,7 +313,7 @@ async def test_form_user_discover_fails_aborts_already_configured(hass):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT
@ -322,12 +326,6 @@ async def test_form_user_discovery_manual_and_auto_password_fetch_but_cannot_con
"""Test discovery skipped and we can auto fetch the password then we fail to connect."""
await setup.async_setup_component(hass, "persistent_notification", {})
mocked_roomba = _create_mocked_roomba(
connect=RoombaConnectionError,
roomba_connected=True,
master_state={"state": {"reported": {"name": "myroomba"}}},
)
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
):
@ -349,33 +347,18 @@ async def test_form_user_discovery_manual_and_auto_password_fetch_but_cannot_con
assert result2["errors"] is None
assert result2["step_id"] == "manual"
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery",
_mocked_no_devices_found_discovery,
):
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
)
await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result3["errors"] is None
with patch(
"homeassistant.components.roomba.config_flow.RoombaFactory.create_roomba",
return_value=mocked_roomba,
), patch(
"homeassistant.components.roomba.config_flow.RoombaPassword",
_mocked_getpassword,
), 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_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result4["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result4["reason"] == "cannot_connect"
assert len(mock_setup_entry.mock_calls) == 0
assert result3["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result3["reason"] == "cannot_connect"
async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(hass):
@ -400,9 +383,12 @@ async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(hass
assert result["errors"] is None
assert result["step_id"] == "manual"
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -425,7 +411,7 @@ async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(hass
await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["title"] == "myroomba"
assert result3["title"] == "robot_name"
assert result3["result"].unique_id == "BLID"
assert result3["data"] == {
CONF_BLID: "BLID",
@ -459,9 +445,12 @@ async def test_form_user_discovery_no_devices_found_and_password_fetch_fails(has
assert result["errors"] is None
assert result["step_id"] == "manual"
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -528,9 +517,12 @@ async def test_form_user_discovery_not_devices_found_and_password_fetch_fails_an
assert result["errors"] is None
assert result["step_id"] == "manual"
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -717,9 +709,12 @@ async def test_dhcp_discovery_falls_back_to_manual(hass, discovery_data):
assert result2["errors"] is None
assert result2["step_id"] == "manual"
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
):
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -742,7 +737,7 @@ async def test_dhcp_discovery_falls_back_to_manual(hass, discovery_data):
await hass.async_block_till_done()
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result4["title"] == "myroomba"
assert result4["title"] == "robot_name"
assert result4["result"].unique_id == "BLID"
assert result4["data"] == {
CONF_BLID: "BLID",
@ -779,9 +774,12 @@ async def test_dhcp_discovery_no_devices_falls_back_to_manual(hass, discovery_da
assert result["errors"] is None
assert result["step_id"] == "manual"
with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"},
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -804,7 +802,7 @@ async def test_dhcp_discovery_no_devices_falls_back_to_manual(hass, discovery_da
await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["title"] == "myroomba"
assert result3["title"] == "robot_name"
assert result3["result"].unique_id == "BLID"
assert result3["data"] == {
CONF_BLID: "BLID",