Add support for discovering individual roombas (#45200)
* Add support for discovering individual roombas * add missing translation string * Update homeassistant/components/roomba/strings.json Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
5e01b828af
commit
233f923cd7
4 changed files with 318 additions and 13 deletions
|
@ -5,6 +5,7 @@ from roombapy import RoombaConnectionError
|
|||
from roombapy.roomba import RoombaInfo
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
||||
from homeassistant.components.roomba.const import (
|
||||
CONF_BLID,
|
||||
CONF_CONTINUOUS,
|
||||
|
@ -579,3 +580,242 @@ async def test_form_user_discovery_and_password_fetch_gets_connection_refused(ha
|
|||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_dhcp_discovery_and_roomba_discovery_finds(hass):
|
||||
"""Test we can process the discovery from dhcp and roomba discovery matches the device."""
|
||||
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_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: MOCK_IP,
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "iRobot-blid",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] is None
|
||||
assert result["step_id"] == "link"
|
||||
assert result["description_placeholders"] == {"name": "robot_name"}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.Roomba",
|
||||
return_value=mocked_roomba,
|
||||
), patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaPassword",
|
||||
_mocked_getpassword,
|
||||
), 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:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result2["title"] == "robot_name"
|
||||
assert result2["result"].unique_id == "blid"
|
||||
assert result2["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
|
||||
|
||||
|
||||
async def test_dhcp_discovery_falls_back_to_manual(hass):
|
||||
"""Test we can process the discovery from dhcp but roomba discovery cannot find the device."""
|
||||
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_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "iRobot-blid",
|
||||
},
|
||||
)
|
||||
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"],
|
||||
{},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result2["errors"] is None
|
||||
assert result2["step_id"] == "manual"
|
||||
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{CONF_HOST: "1.1.1.1", 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.Roomba",
|
||||
return_value=mocked_roomba,
|
||||
), patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaPassword",
|
||||
_mocked_getpassword,
|
||||
), 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"],
|
||||
{},
|
||||
)
|
||||
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: "1.1.1.1",
|
||||
CONF_PASSWORD: "password",
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_dhcp_discovery_with_ignored(hass):
|
||||
"""Test ignored entries do not break checking for existing entries."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, source="ignore")
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "iRobot-blid",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "form"
|
||||
|
||||
|
||||
async def test_dhcp_discovery_already_configured_host(hass):
|
||||
"""Test we abort if the host is already configured."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_HOST: "1.1.1.1"})
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "iRobot-blid",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_dhcp_discovery_already_configured_blid(hass):
|
||||
"""Test we abort if the blid is already configured."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_BLID: "blid"}, unique_id="blid"
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "iRobot-blid",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_dhcp_discovery_not_irobot(hass):
|
||||
"""Test we abort if the discovered device is not an irobot device."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_BLID: "blid"}, unique_id="blid"
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "NotiRobot-blid",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_irobot_device"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue