Fix timeout issue on Roomba integration when adding a new device (#129230)

* Update const.py

DEFAULT_DELAY = 1 to DEFAULT_DELAY = 100 to fix timeout when adding a new device

* Update config_flow.py

continuous=False to continuous=True to fix timeout when adding a new device

* Update homeassistant/components/roomba/const.py

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>

* Update test_config_flow.py

Change CONF_DELAY to match DEFAULT_DELAY (30 sec instead of 1)

* Update tests/components/roomba/test_config_flow.py

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>

* Use constant for DEFAULT_DELAY in tests

---------

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
Co-authored-by: jbouwh <jan@jbsoft.nl>
This commit is contained in:
Aurore 2024-10-30 18:41:10 +01:00 committed by GitHub
parent a4f210379d
commit 94f906b34c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 14 deletions

View File

@ -57,7 +57,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
address=data[CONF_HOST], address=data[CONF_HOST],
blid=data[CONF_BLID], blid=data[CONF_BLID],
password=data[CONF_PASSWORD], password=data[CONF_PASSWORD],
continuous=False, continuous=True,
delay=data[CONF_DELAY], delay=data[CONF_DELAY],
) )
) )

View File

@ -9,5 +9,5 @@ CONF_CONTINUOUS = "continuous"
CONF_BLID = "blid" CONF_BLID = "blid"
DEFAULT_CERT = "/etc/ssl/certs/ca-certificates.crt" DEFAULT_CERT = "/etc/ssl/certs/ca-certificates.crt"
DEFAULT_CONTINUOUS = True DEFAULT_CONTINUOUS = True
DEFAULT_DELAY = 1 DEFAULT_DELAY = 30
ROOMBA_SESSION = "roomba_session" ROOMBA_SESSION = "roomba_session"

View File

@ -8,7 +8,12 @@ from roombapy import RoombaConnectionError, RoombaInfo
from homeassistant.components import dhcp, zeroconf from homeassistant.components import dhcp, zeroconf
from homeassistant.components.roomba import config_flow from homeassistant.components.roomba import config_flow
from homeassistant.components.roomba.const import CONF_BLID, CONF_CONTINUOUS, DOMAIN from homeassistant.components.roomba.const import (
CONF_BLID,
CONF_CONTINUOUS,
DEFAULT_DELAY,
DOMAIN,
)
from homeassistant.config_entries import ( from homeassistant.config_entries import (
SOURCE_DHCP, SOURCE_DHCP,
SOURCE_IGNORE, SOURCE_IGNORE,
@ -206,7 +211,7 @@ async def test_form_user_discovery_and_password_fetch(hass: HomeAssistant) -> No
assert result3["data"] == { assert result3["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -331,7 +336,7 @@ async def test_form_user_discovery_manual_and_auto_password_fetch(
assert result4["data"] == { assert result4["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -468,7 +473,7 @@ async def test_form_user_discovery_no_devices_found_and_auto_password_fetch(
assert result3["data"] == { assert result3["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -541,7 +546,7 @@ async def test_form_user_discovery_no_devices_found_and_password_fetch_fails(
assert result4["data"] == { assert result4["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -677,7 +682,7 @@ async def test_form_user_discovery_and_password_fetch_gets_connection_refused(
assert result4["data"] == { assert result4["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -738,7 +743,7 @@ async def test_dhcp_discovery_and_roomba_discovery_finds(
assert result2["data"] == { assert result2["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -816,7 +821,7 @@ async def test_dhcp_discovery_falls_back_to_manual(
assert result4["data"] == { assert result4["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -886,7 +891,7 @@ async def test_dhcp_discovery_no_devices_falls_back_to_manual(
assert result3["data"] == { assert result3["data"] == {
CONF_BLID: "BLID", CONF_BLID: "BLID",
CONF_CONTINUOUS: True, CONF_CONTINUOUS: True,
CONF_DELAY: 1, CONF_DELAY: DEFAULT_DELAY,
CONF_HOST: MOCK_IP, CONF_HOST: MOCK_IP,
CONF_PASSWORD: "password", CONF_PASSWORD: "password",
} }
@ -1119,10 +1124,10 @@ async def test_options_flow(
result = await hass.config_entries.options.async_configure( result = await hass.config_entries.options.async_configure(
result["flow_id"], result["flow_id"],
user_input={CONF_CONTINUOUS: True, CONF_DELAY: 1}, user_input={CONF_CONTINUOUS: True, CONF_DELAY: DEFAULT_DELAY},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == {CONF_CONTINUOUS: True, CONF_DELAY: 1} assert result["data"] == {CONF_CONTINUOUS: True, CONF_DELAY: DEFAULT_DELAY}
assert config_entry.options == {CONF_CONTINUOUS: True, CONF_DELAY: 1} assert config_entry.options == {CONF_CONTINUOUS: True, CONF_DELAY: DEFAULT_DELAY}