From 6e6f10c0853dc998eb48b3243058be36a7b602f8 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 31 Mar 2025 14:42:58 +0200 Subject: [PATCH] Don't create persistent notification when starting discovery flow (#141546) Co-authored-by: Martin Hjelmare Co-authored-by: Franck Nijhof --- homeassistant/config_entries.py | 23 --------- tests/test_config_entries.py | 86 --------------------------------- 2 files changed, 109 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index d3e681ecca1..81df30210e1 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -30,7 +30,6 @@ from propcache.api import cached_property import voluptuous as vol from . import data_entry_flow, loader -from .components import persistent_notification from .const import ( CONF_NAME, EVENT_HOMEASSISTANT_STARTED, @@ -178,7 +177,6 @@ class ConfigEntryState(Enum): DEFAULT_DISCOVERY_UNIQUE_ID = "default_discovery_unique_id" -DISCOVERY_NOTIFICATION_ID = "config_entry_discovery" DISCOVERY_SOURCES = { SOURCE_BLUETOOTH, SOURCE_DHCP, @@ -1385,14 +1383,6 @@ class ConfigEntriesFlowManager( await asyncio.wait(current.values()) - @callback - def _async_has_other_discovery_flows(self, flow_id: str) -> bool: - """Check if there are any other discovery flows in progress.""" - for flow in self._progress.values(): - if flow.flow_id != flow_id and flow.context["source"] in DISCOVERY_SOURCES: - return True - return False - async def async_init( self, handler: str, @@ -1527,10 +1517,6 @@ class ConfigEntriesFlowManager( # init to be done. self._set_pending_import_done(flow) - # Remove notification if no other discovery config entries in progress - if not self._async_has_other_discovery_flows(flow.flow_id): - persistent_notification.async_dismiss(self.hass, DISCOVERY_NOTIFICATION_ID) - # Clean up issue if this is a reauth flow if flow.context["source"] == SOURCE_REAUTH: if (entry_id := flow.context.get("entry_id")) is not None and ( @@ -1719,15 +1705,6 @@ class ConfigEntriesFlowManager( # async_fire_internal is used here because this is only # called from the Debouncer so we know the usage is safe self.hass.bus.async_fire_internal(EVENT_FLOW_DISCOVERED) - persistent_notification.async_create( - self.hass, - title="New devices discovered", - message=( - "We have discovered new devices on your network. " - "[Check it out](/config/integrations)." - ), - notification_id=DISCOVERY_NOTIFICATION_ID, - ) @callback def async_has_matching_discovery_flow( diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index e3b80ecc03f..6147102f68f 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -57,7 +57,6 @@ from .common import ( MockPlatform, async_capture_events, async_fire_time_changed, - async_get_persistent_notifications, flush_store, mock_config_flow, mock_integration, @@ -1368,59 +1367,6 @@ async def test_async_forward_entry_setup_deprecated( ) in caplog.text -async def test_discovery_notification( - hass: HomeAssistant, manager: config_entries.ConfigEntries -) -> None: - """Test that we create/dismiss a notification when source is discovery.""" - mock_integration(hass, MockModule("test")) - mock_platform(hass, "test.config_flow", None) - - class TestFlow(config_entries.ConfigFlow): - """Test flow.""" - - VERSION = 5 - - async def async_step_discovery(self, discovery_info): - """Test discovery step.""" - return self.async_show_form(step_id="discovery_confirm") - - async def async_step_discovery_confirm(self, discovery_info): - """Test discovery confirm step.""" - return self.async_create_entry(title="Test Title", data={"token": "abcd"}) - - with mock_config_flow("test", TestFlow): - notifications = async_get_persistent_notifications(hass) - assert "config_entry_discovery" not in notifications - - # Start first discovery flow to assert that discovery notification fires - flow1 = await hass.config_entries.flow.async_init( - "test", context={"source": config_entries.SOURCE_DISCOVERY} - ) - await hass.async_block_till_done() - notifications = async_get_persistent_notifications(hass) - assert "config_entry_discovery" in notifications - - # Start a second discovery flow so we can finish the first and assert that - # the discovery notification persists until the second one is complete - flow2 = await hass.config_entries.flow.async_init( - "test", context={"source": config_entries.SOURCE_DISCOVERY} - ) - - flow1 = await hass.config_entries.flow.async_configure(flow1["flow_id"], {}) - assert flow1["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY - - await hass.async_block_till_done() - notifications = async_get_persistent_notifications(hass) - assert "config_entry_discovery" in notifications - - flow2 = await hass.config_entries.flow.async_configure(flow2["flow_id"], {}) - assert flow2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY - - await hass.async_block_till_done() - notifications = async_get_persistent_notifications(hass) - assert "config_entry_discovery" not in notifications - - async def test_reauth_issue( hass: HomeAssistant, manager: config_entries.ConfigEntries, @@ -1467,30 +1413,6 @@ async def test_reauth_issue( assert len(issue_registry.issues) == 0 -async def test_discovery_notification_not_created(hass: HomeAssistant) -> None: - """Test that we not create a notification when discovery is aborted.""" - mock_integration(hass, MockModule("test")) - mock_platform(hass, "test.config_flow", None) - - class TestFlow(config_entries.ConfigFlow): - """Test flow.""" - - VERSION = 5 - - async def async_step_discovery(self, discovery_info): - """Test discovery step.""" - return self.async_abort(reason="test") - - with mock_config_flow("test", TestFlow): - await hass.config_entries.flow.async_init( - "test", context={"source": config_entries.SOURCE_DISCOVERY} - ) - - await hass.async_block_till_done() - state = hass.states.get("persistent_notification.config_entry_discovery") - assert state is None - - async def test_loading_default_config(hass: HomeAssistant) -> None: """Test loading the default config.""" manager = config_entries.ConfigEntries(hass, {}) @@ -4188,10 +4110,6 @@ async def test_partial_flows_hidden( # While it's blocked it shouldn't be visible or trigger discovery notifications assert len(hass.config_entries.flow.async_progress()) == 0 - await hass.async_block_till_done() - notifications = async_get_persistent_notifications(hass) - assert "config_entry_discovery" not in notifications - # Let the flow init complete pause_discovery.set() @@ -4201,10 +4119,6 @@ async def test_partial_flows_hidden( assert result["type"] == data_entry_flow.FlowResultType.FORM assert len(hass.config_entries.flow.async_progress()) == 1 - await hass.async_block_till_done() - notifications = async_get_persistent_notifications(hass) - assert "config_entry_discovery" in notifications - async def test_async_setup_init_entry( hass: HomeAssistant, manager: config_entries.ConfigEntries