From f3bdc013de461994e66c9a67087e8c7fa77cf290 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 7 Oct 2026 07:10:07 +0200 Subject: [PATCH] Create an Apple TV entry for a device that was ignored before (#184580) --- .../components/apple_tv/config_flow.py | 5 ++-- tests/components/apple_tv/test_config_flow.py | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/apple_tv/config_flow.py b/homeassistant/components/apple_tv/config_flow.py index 06a7443ad324..6ad8d1512f31 100644 --- a/homeassistant/components/apple_tv/config_flow.py +++ b/homeassistant/components/apple_tv/config_flow.py @@ -619,8 +619,9 @@ class AppleTVConfigFlow(ConfigFlow, domain=DOMAIN): self.device_identifier, raise_on_progress=False ) - # If an existing config entry is updated, then this was a re-auth - if existing_entry: + # If an existing config entry is updated, then this was a re-auth. An + # ignored entry is replaced by the new entry instead. + if existing_entry and existing_entry.source != SOURCE_IGNORE: return self.async_update_reload_and_abort( existing_entry, data=data, unique_id=self.unique_id ) diff --git a/tests/components/apple_tv/test_config_flow.py b/tests/components/apple_tv/test_config_flow.py index d896cd59f3ab..edf47df63497 100644 --- a/tests/components/apple_tv/test_config_flow.py +++ b/tests/components/apple_tv/test_config_flow.py @@ -178,6 +178,33 @@ async def test_user_pair_leading_zero_pin( assert result["type"] is FlowResultType.CREATE_ENTRY +@pytest.mark.usefixtures("mrp_device", "pairing") +async def test_user_adds_previously_ignored_device(hass: HomeAssistant) -> None: + """Test adding a device that was ignored before creates an entry.""" + MockConfigEntry( + domain=DOMAIN, + unique_id="mrpid", + source=config_entries.SOURCE_IGNORE, + ).add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + await hass.config_entries.flow.async_configure( + result["flow_id"], + {"device_input": "MRP Device"}, + ) + result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) + result = await hass.config_entries.flow.async_configure( + result["flow_id"], {"pin": "1111"} + ) + assert result["type"] is FlowResultType.CREATE_ENTRY + + entries = hass.config_entries.async_entries(DOMAIN, include_ignore=True) + assert len(entries) == 1 + assert entries[0].source == config_entries.SOURCE_USER + + @pytest.mark.usefixtures("mrp_device") @pytest.mark.parametrize("invalid_pin", ["abcd", "12ab", "١٢٣٤", "123\n"]) async def test_user_pair_non_numeric_pin(