Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Twinkly raise on progress #133601

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/twinkly/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ async def async_step_user(
except (TimeoutError, ClientError):
errors[CONF_HOST] = "cannot_connect"
else:
await self.async_set_unique_id(device_info[DEV_ID])
await self.async_set_unique_id(
device_info[DEV_ID], raise_on_progress=False
Copy link
Member

@bdraco bdraco Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably could use a test for a competing discovery

)
self._abort_if_unique_id_configured()

return self._create_entry_from_device(device_info, host)
Expand Down
37 changes: 37 additions & 0 deletions tests/components/twinkly/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from homeassistant import config_entries
from homeassistant.components import dhcp
from homeassistant.components.twinkly.const import DOMAIN as TWINKLY_DOMAIN
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_HOST, CONF_ID, CONF_MODEL, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -157,3 +158,39 @@ async def test_dhcp_already_exists(hass: HomeAssistant) -> None:

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"


async def test_user_flow_works_discovery(hass: HomeAssistant) -> None:
"""Test user flow can continue after discovery happened."""
client = ClientMock()
with (
patch(
"homeassistant.components.twinkly.config_flow.Twinkly", return_value=client
),
patch("homeassistant.components.twinkly.async_setup_entry", return_value=True),
):
await hass.config_entries.flow.async_init(
TWINKLY_DOMAIN,
context={"source": config_entries.SOURCE_DHCP},
data=dhcp.DhcpServiceInfo(
hostname="Twinkly_XYZ",
ip="1.2.3.4",
macaddress="aabbccddeeff",
),
)
result = await hass.config_entries.flow.async_init(
TWINKLY_DOMAIN,
context={"source": SOURCE_USER},
)
assert len(hass.config_entries.flow.async_progress(TWINKLY_DOMAIN)) == 2
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: "10.0.0.131"},
)
assert result["type"] is FlowResultType.CREATE_ENTRY

# Verify the discovery flow was aborted
assert not hass.config_entries.flow.async_progress(TWINKLY_DOMAIN)