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", step_id="manual",
description_placeholders={AUTH_HELP_URL_KEY: AUTH_HELP_URL_VALUE}, description_placeholders={AUTH_HELP_URL_KEY: AUTH_HELP_URL_VALUE},
data_schema=vol.Schema( data_schema=vol.Schema(
{ {vol.Required(CONF_HOST, default=self.host): str}
vol.Required(CONF_HOST, default=self.host): str,
vol.Required(CONF_BLID, default=self.blid): str,
}
), ),
) )
self._async_abort_entries_match({CONF_HOST: user_input["host"]}) self._async_abort_entries_match({CONF_HOST: user_input["host"]})
self.host = user_input[CONF_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) await self.async_set_unique_id(self.blid, raise_on_progress=False)
self._abort_if_unique_id_configured() self._abort_if_unique_id_configured()
return await self.async_step_link() return await self.async_step_link()

View File

@ -11,10 +11,9 @@
}, },
"manual": { "manual": {
"title": "Manually connect to the device", "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": { "data": {
"host": "[%key:common::config_flow::data::host%]", "host": "[%key:common::config_flow::data::host%]"
"blid": "BLID"
} }
}, },
"link": { "link": {

View File

@ -31,10 +31,9 @@
}, },
"manual": { "manual": {
"data": { "data": {
"blid": "BLID",
"host": "Host" "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" "title": "Manually connect to the device"
}, },
"user": { "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( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, {CONF_HOST: MOCK_IP},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT 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["errors"] is None
assert result2["step_id"] == "manual" assert result2["step_id"] == "manual"
result3 = await hass.config_entries.flow.async_configure( with patch(
result2["flow_id"], "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, ):
) result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done() await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result3["errors"] is None 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() await hass.async_block_till_done()
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY 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["result"].unique_id == "BLID"
assert result4["data"] == { assert result4["data"] == {
CONF_BLID: "BLID", 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( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, {CONF_HOST: MOCK_IP},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT 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.""" """Test discovery skipped and we can auto fetch the password then we fail to connect."""
await setup.async_setup_component(hass, "persistent_notification", {}) 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( with patch(
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery "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["errors"] is None
assert result2["step_id"] == "manual" assert result2["step_id"] == "manual"
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( with patch(
"homeassistant.components.roomba.config_flow.RoombaFactory.create_roomba", "homeassistant.components.roomba.config_flow.RoombaDiscovery",
return_value=mocked_roomba, _mocked_no_devices_found_discovery,
), patch( ):
"homeassistant.components.roomba.config_flow.RoombaPassword", result3 = await hass.config_entries.flow.async_configure(
_mocked_getpassword, result2["flow_id"],
), patch( {CONF_HOST: MOCK_IP},
"homeassistant.components.roomba.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result4 = await hass.config_entries.flow.async_configure(
result3["flow_id"],
{},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert result4["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result3["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result4["reason"] == "cannot_connect" assert result3["reason"] == "cannot_connect"
assert len(mock_setup_entry.mock_calls) == 0
async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(hass): async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(hass):
@ -400,10 +383,13 @@ async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(hass
assert result["errors"] is None assert result["errors"] is None
assert result["step_id"] == "manual" assert result["step_id"] == "manual"
result2 = await hass.config_entries.flow.async_configure( with patch(
result["flow_id"], "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, ):
) result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done() await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] is None assert result2["errors"] is None
@ -425,7 +411,7 @@ async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(hass
await hass.async_block_till_done() await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY 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["result"].unique_id == "BLID"
assert result3["data"] == { assert result3["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
@ -459,10 +445,13 @@ async def test_form_user_discovery_no_devices_found_and_password_fetch_fails(has
assert result["errors"] is None assert result["errors"] is None
assert result["step_id"] == "manual" assert result["step_id"] == "manual"
result2 = await hass.config_entries.flow.async_configure( with patch(
result["flow_id"], "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, ):
) result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done() await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] is None assert result2["errors"] is None
@ -528,10 +517,13 @@ async def test_form_user_discovery_not_devices_found_and_password_fetch_fails_an
assert result["errors"] is None assert result["errors"] is None
assert result["step_id"] == "manual" assert result["step_id"] == "manual"
result2 = await hass.config_entries.flow.async_configure( with patch(
result["flow_id"], "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, ):
) result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done() await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] is None assert result2["errors"] is None
@ -717,10 +709,13 @@ async def test_dhcp_discovery_falls_back_to_manual(hass, discovery_data):
assert result2["errors"] is None assert result2["errors"] is None
assert result2["step_id"] == "manual" assert result2["step_id"] == "manual"
result3 = await hass.config_entries.flow.async_configure( with patch(
result2["flow_id"], "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, ):
) result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done() await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result3["errors"] is None assert result3["errors"] is None
@ -742,7 +737,7 @@ async def test_dhcp_discovery_falls_back_to_manual(hass, discovery_data):
await hass.async_block_till_done() await hass.async_block_till_done()
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY 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["result"].unique_id == "BLID"
assert result4["data"] == { assert result4["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
@ -779,10 +774,13 @@ async def test_dhcp_discovery_no_devices_falls_back_to_manual(hass, discovery_da
assert result["errors"] is None assert result["errors"] is None
assert result["step_id"] == "manual" assert result["step_id"] == "manual"
result2 = await hass.config_entries.flow.async_configure( with patch(
result["flow_id"], "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
{CONF_HOST: MOCK_IP, CONF_BLID: "blid"}, ):
) result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: MOCK_IP},
)
await hass.async_block_till_done() await hass.async_block_till_done()
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] is None assert result2["errors"] is None
@ -804,7 +802,7 @@ async def test_dhcp_discovery_no_devices_falls_back_to_manual(hass, discovery_da
await hass.async_block_till_done() await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY 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["result"].unique_id == "BLID"
assert result3["data"] == { assert result3["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",