Skip to content

Commit ab9d29b

Browse files
authored
Remove reauth persistent notification (#140932)
* Remove persistent notification created when starting reauth * Update netatmo tests
1 parent 12e001c commit ab9d29b

File tree

3 files changed

+6
-122
lines changed

3 files changed

+6
-122
lines changed

homeassistant/config_entries.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ def recoverable(self) -> bool:
195195
SOURCE_ZEROCONF,
196196
}
197197

198-
RECONFIGURE_NOTIFICATION_ID = "config_entry_reconfigure"
199-
200198
EVENT_FLOW_DISCOVERED = "config_entry_discovered"
201199

202200
SIGNAL_CONFIG_ENTRY_CHANGED = SignalType["ConfigEntryChange", "ConfigEntry"](
@@ -1714,16 +1712,6 @@ async def async_post_init(
17141712
# Create notification.
17151713
if source in DISCOVERY_SOURCES:
17161714
await self._discovery_debouncer.async_call()
1717-
elif source == SOURCE_REAUTH:
1718-
persistent_notification.async_create(
1719-
self.hass,
1720-
title="Integration requires reconfiguration",
1721-
message=(
1722-
"At least one of your integrations requires reconfiguration to "
1723-
"continue functioning. [Check it out](/config/integrations)."
1724-
),
1725-
notification_id=RECONFIGURE_NOTIFICATION_ID,
1726-
)
17271715

17281716
@callback
17291717
def _async_discovery(self) -> None:
@@ -3119,29 +3107,6 @@ async def async_step_discovery(
31193107
"""Handle a flow initialized by discovery."""
31203108
return await self._async_step_discovery_without_unique_id()
31213109

3122-
@callback
3123-
def async_abort(
3124-
self,
3125-
*,
3126-
reason: str,
3127-
description_placeholders: Mapping[str, str] | None = None,
3128-
) -> ConfigFlowResult:
3129-
"""Abort the config flow."""
3130-
# Remove reauth notification if no reauth flows are in progress
3131-
if self.source == SOURCE_REAUTH and not any(
3132-
ent["flow_id"] != self.flow_id
3133-
for ent in self.hass.config_entries.flow.async_progress_by_handler(
3134-
self.handler, match_context={"source": SOURCE_REAUTH}
3135-
)
3136-
):
3137-
persistent_notification.async_dismiss(
3138-
self.hass, RECONFIGURE_NOTIFICATION_ID
3139-
)
3140-
3141-
return super().async_abort(
3142-
reason=reason, description_placeholders=description_placeholders
3143-
)
3144-
31453110
async def async_step_bluetooth(
31463111
self, discovery_info: BluetoothServiceInfoBleak
31473112
) -> ConfigFlowResult:

tests/components/netatmo/test_init.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@
2525
simulate_webhook,
2626
)
2727

28-
from tests.common import (
29-
MockConfigEntry,
30-
async_fire_time_changed,
31-
async_get_persistent_notifications,
32-
)
28+
from tests.common import MockConfigEntry, async_fire_time_changed
3329
from tests.components.cloud import mock_cloud
3430
from tests.typing import WebSocketGenerator
3531

@@ -423,9 +419,8 @@ async def test_setup_component_invalid_token_scope(hass: HomeAssistant) -> None:
423419
assert config_entry.state is ConfigEntryState.SETUP_ERROR
424420
assert hass.config_entries.async_entries(DOMAIN)
425421

426-
notifications = async_get_persistent_notifications(hass)
427-
428-
assert len(notifications) > 0
422+
# Test a reauth flow is initiated
423+
assert len(list(config_entry.async_get_active_flows(hass, {"reauth"}))) == 1
429424

430425
for config_entry in hass.config_entries.async_entries("netatmo"):
431426
await hass.config_entries.async_remove(config_entry.entry_id)
@@ -476,8 +471,9 @@ async def fake_ensure_valid_token(*args, **kwargs):
476471

477472
assert config_entry.state is ConfigEntryState.SETUP_ERROR
478473
assert hass.config_entries.async_entries(DOMAIN)
479-
notifications = async_get_persistent_notifications(hass)
480-
assert len(notifications) > 0
474+
475+
# Test a reauth flow is initiated
476+
assert len(list(config_entry.async_get_active_flows(hass, {"reauth"}))) == 1
481477

482478
for entry in hass.config_entries.async_entries("netatmo"):
483479
await hass.config_entries.async_remove(entry.entry_id)

tests/test_config_entries.py

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,83 +1421,6 @@ async def async_step_discovery_confirm(self, discovery_info):
14211421
assert "config_entry_discovery" not in notifications
14221422

14231423

1424-
async def test_reauth_notification(hass: HomeAssistant) -> None:
1425-
"""Test that we create/dismiss a notification when source is reauth."""
1426-
mock_integration(hass, MockModule("test"))
1427-
mock_platform(hass, "test.config_flow", None)
1428-
1429-
entry = MockConfigEntry(title="test_title", domain="test")
1430-
entry.add_to_hass(hass)
1431-
1432-
class TestFlow(config_entries.ConfigFlow):
1433-
"""Test flow."""
1434-
1435-
VERSION = 5
1436-
1437-
async def async_step_user(self, user_input):
1438-
"""Test user step."""
1439-
return self.async_show_form(step_id="user_confirm")
1440-
1441-
async def async_step_user_confirm(self, user_input):
1442-
"""Test user confirm step."""
1443-
return self.async_show_form(step_id="user_confirm")
1444-
1445-
async def async_step_reauth(self, user_input):
1446-
"""Test reauth step."""
1447-
return self.async_show_form(step_id="reauth_confirm")
1448-
1449-
async def async_step_reauth_confirm(self, user_input):
1450-
"""Test reauth confirm step."""
1451-
return self.async_abort(reason="test")
1452-
1453-
with mock_config_flow("test", TestFlow):
1454-
# Start user flow to assert that reconfigure notification doesn't fire
1455-
await hass.config_entries.flow.async_init(
1456-
"test", context={"source": config_entries.SOURCE_USER}
1457-
)
1458-
1459-
await hass.async_block_till_done()
1460-
notifications = async_get_persistent_notifications(hass)
1461-
assert "config_entry_reconfigure" not in notifications
1462-
1463-
# Start first reauth flow to assert that reconfigure notification fires
1464-
flow1 = await hass.config_entries.flow.async_init(
1465-
"test",
1466-
context={
1467-
"source": config_entries.SOURCE_REAUTH,
1468-
"entry_id": entry.entry_id,
1469-
},
1470-
)
1471-
1472-
await hass.async_block_till_done()
1473-
notifications = async_get_persistent_notifications(hass)
1474-
assert "config_entry_reconfigure" in notifications
1475-
1476-
# Start a second reauth flow so we can finish the first and assert that
1477-
# the reconfigure notification persists until the second one is complete
1478-
flow2 = await hass.config_entries.flow.async_init(
1479-
"test",
1480-
context={
1481-
"source": config_entries.SOURCE_REAUTH,
1482-
"entry_id": entry.entry_id,
1483-
},
1484-
)
1485-
1486-
flow1 = await hass.config_entries.flow.async_configure(flow1["flow_id"], {})
1487-
assert flow1["type"] == data_entry_flow.FlowResultType.ABORT
1488-
1489-
await hass.async_block_till_done()
1490-
notifications = async_get_persistent_notifications(hass)
1491-
assert "config_entry_reconfigure" in notifications
1492-
1493-
flow2 = await hass.config_entries.flow.async_configure(flow2["flow_id"], {})
1494-
assert flow2["type"] == data_entry_flow.FlowResultType.ABORT
1495-
1496-
await hass.async_block_till_done()
1497-
notifications = async_get_persistent_notifications(hass)
1498-
assert "config_entry_reconfigure" not in notifications
1499-
1500-
15011424
async def test_reauth_issue(
15021425
hass: HomeAssistant,
15031426
manager: config_entries.ConfigEntries,

0 commit comments

Comments
 (0)