Skip to content

Avoid unnecessary reload in apple_tv reauth flow #142079

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

Merged
merged 1 commit into from
Apr 2, 2025
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
5 changes: 4 additions & 1 deletion homeassistant/components/apple_tv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from homeassistant.components import zeroconf
from homeassistant.config_entries import (
SOURCE_IGNORE,
SOURCE_REAUTH,
SOURCE_ZEROCONF,
ConfigEntry,
ConfigFlow,
Expand Down Expand Up @@ -381,7 +382,9 @@ async def async_find_device(self, allow_exist: bool = False) -> None:
CONF_IDENTIFIERS: list(combined_identifiers),
},
)
if entry.source != SOURCE_IGNORE:
# Don't reload ignored entries or in the middle of reauth,
# e.g. if the user is entering a new PIN
if entry.source != SOURCE_IGNORE and self.source != SOURCE_REAUTH:
self.hass.config_entries.async_schedule_reload(entry.entry_id)
if not allow_exist:
raise DeviceAlreadyConfigured
Expand Down
13 changes: 9 additions & 4 deletions tests/components/apple_tv/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def use_mocked_zeroconf(mock_async_zeroconf: MagicMock) -> None:


@pytest.fixture(autouse=True)
def mock_setup_entry() -> Generator[None]:
def mock_setup_entry() -> Generator[Mock]:
"""Mock setting up a config entry."""
with patch(
"homeassistant.components.apple_tv.async_setup_entry", return_value=True
):
yield
) as setup_entry:
yield setup_entry


# User Flows
Expand Down Expand Up @@ -1183,7 +1183,9 @@ async def test_zeroconf_mismatch(hass: HomeAssistant, mock_scan: AsyncMock) -> N


@pytest.mark.usefixtures("mrp_device", "pairing")
async def test_reconfigure_update_credentials(hass: HomeAssistant) -> None:
async def test_reconfigure_update_credentials(
hass: HomeAssistant, mock_setup_entry: Mock
) -> None:
"""Test that reconfigure flow updates config entry."""
config_entry = MockConfigEntry(
domain="apple_tv", unique_id="mrpid", data={"identifiers": ["mrpid"]}
Expand Down Expand Up @@ -1215,6 +1217,9 @@ async def test_reconfigure_update_credentials(hass: HomeAssistant) -> None:
"identifiers": ["mrpid"],
}

await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the change in this PR, the entry is set up twice



# Options

Expand Down