Skip to content

Commit

Permalink
Fix Twinkly raise on progress (#133601)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Dec 19, 2024
1 parent 2413fc4 commit 61e5f10
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
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
)
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)

0 comments on commit 61e5f10

Please sign in to comment.