mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Remove reauth persistent notification (#140932)
* Remove persistent notification created when starting reauth * Update netatmo tests
This commit is contained in:
parent
12e001cf2b
commit
ab9d29bf9d
@ -195,8 +195,6 @@ DISCOVERY_SOURCES = {
|
||||
SOURCE_ZEROCONF,
|
||||
}
|
||||
|
||||
RECONFIGURE_NOTIFICATION_ID = "config_entry_reconfigure"
|
||||
|
||||
EVENT_FLOW_DISCOVERED = "config_entry_discovered"
|
||||
|
||||
SIGNAL_CONFIG_ENTRY_CHANGED = SignalType["ConfigEntryChange", "ConfigEntry"](
|
||||
@ -1714,16 +1712,6 @@ class ConfigEntriesFlowManager(
|
||||
# Create notification.
|
||||
if source in DISCOVERY_SOURCES:
|
||||
await self._discovery_debouncer.async_call()
|
||||
elif source == SOURCE_REAUTH:
|
||||
persistent_notification.async_create(
|
||||
self.hass,
|
||||
title="Integration requires reconfiguration",
|
||||
message=(
|
||||
"At least one of your integrations requires reconfiguration to "
|
||||
"continue functioning. [Check it out](/config/integrations)."
|
||||
),
|
||||
notification_id=RECONFIGURE_NOTIFICATION_ID,
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_discovery(self) -> None:
|
||||
@ -3119,29 +3107,6 @@ class ConfigFlow(ConfigEntryBaseFlow):
|
||||
"""Handle a flow initialized by discovery."""
|
||||
return await self._async_step_discovery_without_unique_id()
|
||||
|
||||
@callback
|
||||
def async_abort(
|
||||
self,
|
||||
*,
|
||||
reason: str,
|
||||
description_placeholders: Mapping[str, str] | None = None,
|
||||
) -> ConfigFlowResult:
|
||||
"""Abort the config flow."""
|
||||
# Remove reauth notification if no reauth flows are in progress
|
||||
if self.source == SOURCE_REAUTH and not any(
|
||||
ent["flow_id"] != self.flow_id
|
||||
for ent in self.hass.config_entries.flow.async_progress_by_handler(
|
||||
self.handler, match_context={"source": SOURCE_REAUTH}
|
||||
)
|
||||
):
|
||||
persistent_notification.async_dismiss(
|
||||
self.hass, RECONFIGURE_NOTIFICATION_ID
|
||||
)
|
||||
|
||||
return super().async_abort(
|
||||
reason=reason, description_placeholders=description_placeholders
|
||||
)
|
||||
|
||||
async def async_step_bluetooth(
|
||||
self, discovery_info: BluetoothServiceInfoBleak
|
||||
) -> ConfigFlowResult:
|
||||
|
@ -25,11 +25,7 @@ from .common import (
|
||||
simulate_webhook,
|
||||
)
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
async_fire_time_changed,
|
||||
async_get_persistent_notifications,
|
||||
)
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
from tests.components.cloud import mock_cloud
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
@ -423,9 +419,8 @@ async def test_setup_component_invalid_token_scope(hass: HomeAssistant) -> None:
|
||||
assert config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
assert hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
notifications = async_get_persistent_notifications(hass)
|
||||
|
||||
assert len(notifications) > 0
|
||||
# Test a reauth flow is initiated
|
||||
assert len(list(config_entry.async_get_active_flows(hass, {"reauth"}))) == 1
|
||||
|
||||
for config_entry in hass.config_entries.async_entries("netatmo"):
|
||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
@ -476,8 +471,9 @@ async def test_setup_component_invalid_token(
|
||||
|
||||
assert config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
assert hass.config_entries.async_entries(DOMAIN)
|
||||
notifications = async_get_persistent_notifications(hass)
|
||||
assert len(notifications) > 0
|
||||
|
||||
# Test a reauth flow is initiated
|
||||
assert len(list(config_entry.async_get_active_flows(hass, {"reauth"}))) == 1
|
||||
|
||||
for entry in hass.config_entries.async_entries("netatmo"):
|
||||
await hass.config_entries.async_remove(entry.entry_id)
|
||||
|
@ -1421,83 +1421,6 @@ async def test_discovery_notification(
|
||||
assert "config_entry_discovery" not in notifications
|
||||
|
||||
|
||||
async def test_reauth_notification(hass: HomeAssistant) -> None:
|
||||
"""Test that we create/dismiss a notification when source is reauth."""
|
||||
mock_integration(hass, MockModule("test"))
|
||||
mock_platform(hass, "test.config_flow", None)
|
||||
|
||||
entry = MockConfigEntry(title="test_title", domain="test")
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 5
|
||||
|
||||
async def async_step_user(self, user_input):
|
||||
"""Test user step."""
|
||||
return self.async_show_form(step_id="user_confirm")
|
||||
|
||||
async def async_step_user_confirm(self, user_input):
|
||||
"""Test user confirm step."""
|
||||
return self.async_show_form(step_id="user_confirm")
|
||||
|
||||
async def async_step_reauth(self, user_input):
|
||||
"""Test reauth step."""
|
||||
return self.async_show_form(step_id="reauth_confirm")
|
||||
|
||||
async def async_step_reauth_confirm(self, user_input):
|
||||
"""Test reauth confirm step."""
|
||||
return self.async_abort(reason="test")
|
||||
|
||||
with mock_config_flow("test", TestFlow):
|
||||
# Start user flow to assert that reconfigure notification doesn't fire
|
||||
await hass.config_entries.flow.async_init(
|
||||
"test", context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
notifications = async_get_persistent_notifications(hass)
|
||||
assert "config_entry_reconfigure" not in notifications
|
||||
|
||||
# Start first reauth flow to assert that reconfigure notification fires
|
||||
flow1 = await hass.config_entries.flow.async_init(
|
||||
"test",
|
||||
context={
|
||||
"source": config_entries.SOURCE_REAUTH,
|
||||
"entry_id": entry.entry_id,
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
notifications = async_get_persistent_notifications(hass)
|
||||
assert "config_entry_reconfigure" in notifications
|
||||
|
||||
# Start a second reauth flow so we can finish the first and assert that
|
||||
# the reconfigure notification persists until the second one is complete
|
||||
flow2 = await hass.config_entries.flow.async_init(
|
||||
"test",
|
||||
context={
|
||||
"source": config_entries.SOURCE_REAUTH,
|
||||
"entry_id": entry.entry_id,
|
||||
},
|
||||
)
|
||||
|
||||
flow1 = await hass.config_entries.flow.async_configure(flow1["flow_id"], {})
|
||||
assert flow1["type"] == data_entry_flow.FlowResultType.ABORT
|
||||
|
||||
await hass.async_block_till_done()
|
||||
notifications = async_get_persistent_notifications(hass)
|
||||
assert "config_entry_reconfigure" in notifications
|
||||
|
||||
flow2 = await hass.config_entries.flow.async_configure(flow2["flow_id"], {})
|
||||
assert flow2["type"] == data_entry_flow.FlowResultType.ABORT
|
||||
|
||||
await hass.async_block_till_done()
|
||||
notifications = async_get_persistent_notifications(hass)
|
||||
assert "config_entry_reconfigure" not in notifications
|
||||
|
||||
|
||||
async def test_reauth_issue(
|
||||
hass: HomeAssistant,
|
||||
manager: config_entries.ConfigEntries,
|
||||
|
Loading…
x
Reference in New Issue
Block a user