mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Don't create persistent notification when starting discovery flow (#141546)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
1c0768dd78
commit
6e6f10c085
@ -30,7 +30,6 @@ from propcache.api import cached_property
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from . import data_entry_flow, loader
|
from . import data_entry_flow, loader
|
||||||
from .components import persistent_notification
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
@ -178,7 +177,6 @@ class ConfigEntryState(Enum):
|
|||||||
|
|
||||||
|
|
||||||
DEFAULT_DISCOVERY_UNIQUE_ID = "default_discovery_unique_id"
|
DEFAULT_DISCOVERY_UNIQUE_ID = "default_discovery_unique_id"
|
||||||
DISCOVERY_NOTIFICATION_ID = "config_entry_discovery"
|
|
||||||
DISCOVERY_SOURCES = {
|
DISCOVERY_SOURCES = {
|
||||||
SOURCE_BLUETOOTH,
|
SOURCE_BLUETOOTH,
|
||||||
SOURCE_DHCP,
|
SOURCE_DHCP,
|
||||||
@ -1385,14 +1383,6 @@ class ConfigEntriesFlowManager(
|
|||||||
|
|
||||||
await asyncio.wait(current.values())
|
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(
|
async def async_init(
|
||||||
self,
|
self,
|
||||||
handler: str,
|
handler: str,
|
||||||
@ -1527,10 +1517,6 @@ class ConfigEntriesFlowManager(
|
|||||||
# init to be done.
|
# init to be done.
|
||||||
self._set_pending_import_done(flow)
|
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
|
# Clean up issue if this is a reauth flow
|
||||||
if flow.context["source"] == SOURCE_REAUTH:
|
if flow.context["source"] == SOURCE_REAUTH:
|
||||||
if (entry_id := flow.context.get("entry_id")) is not None and (
|
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
|
# async_fire_internal is used here because this is only
|
||||||
# called from the Debouncer so we know the usage is safe
|
# called from the Debouncer so we know the usage is safe
|
||||||
self.hass.bus.async_fire_internal(EVENT_FLOW_DISCOVERED)
|
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
|
@callback
|
||||||
def async_has_matching_discovery_flow(
|
def async_has_matching_discovery_flow(
|
||||||
|
@ -57,7 +57,6 @@ from .common import (
|
|||||||
MockPlatform,
|
MockPlatform,
|
||||||
async_capture_events,
|
async_capture_events,
|
||||||
async_fire_time_changed,
|
async_fire_time_changed,
|
||||||
async_get_persistent_notifications,
|
|
||||||
flush_store,
|
flush_store,
|
||||||
mock_config_flow,
|
mock_config_flow,
|
||||||
mock_integration,
|
mock_integration,
|
||||||
@ -1368,59 +1367,6 @@ async def test_async_forward_entry_setup_deprecated(
|
|||||||
) in caplog.text
|
) 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(
|
async def test_reauth_issue(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
manager: config_entries.ConfigEntries,
|
manager: config_entries.ConfigEntries,
|
||||||
@ -1467,30 +1413,6 @@ async def test_reauth_issue(
|
|||||||
assert len(issue_registry.issues) == 0
|
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:
|
async def test_loading_default_config(hass: HomeAssistant) -> None:
|
||||||
"""Test loading the default config."""
|
"""Test loading the default config."""
|
||||||
manager = config_entries.ConfigEntries(hass, {})
|
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
|
# While it's blocked it shouldn't be visible or trigger discovery notifications
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
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
|
# Let the flow init complete
|
||||||
pause_discovery.set()
|
pause_discovery.set()
|
||||||
|
|
||||||
@ -4201,10 +4119,6 @@ async def test_partial_flows_hidden(
|
|||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
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(
|
async def test_async_setup_init_entry(
|
||||||
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
||||||
|
Loading…
x
Reference in New Issue
Block a user