mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add persistent notification for reauth config flows (#41811)
* add persistent notification for reauth config flow * remove log * Update homeassistant/config_entries.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/config_entries.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * fix logic for determining when to dismiss notification * add comment * improve tests to ensure notifications only get dismissed when all in progress config flows of a given type are complete * Update homeassistant/config_entries.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * handle context is None when accessing source * add guard to show_advanced_options * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
This commit is contained in:
@@ -78,6 +78,8 @@ DISCOVERY_SOURCES = (
|
||||
SOURCE_UNIGNORE,
|
||||
)
|
||||
|
||||
RECONFIGURE_NOTIFICATION_ID = "config_entry_reconfigure"
|
||||
|
||||
EVENT_FLOW_DISCOVERED = "config_entry_discovered"
|
||||
|
||||
CONN_CLASS_CLOUD_PUSH = "cloud_push"
|
||||
@@ -566,6 +568,15 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager):
|
||||
),
|
||||
notification_id=DISCOVERY_NOTIFICATION_ID,
|
||||
)
|
||||
elif source == SOURCE_REAUTH:
|
||||
self.hass.components.persistent_notification.async_create(
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
class ConfigEntries:
|
||||
@@ -1004,6 +1015,27 @@ class ConfigFlow(data_entry_flow.FlowHandler):
|
||||
await self._async_handle_discovery_without_unique_id()
|
||||
return await self.async_step_user()
|
||||
|
||||
@callback
|
||||
def async_abort(
|
||||
self, *, reason: str, description_placeholders: Optional[Dict] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Abort the config flow."""
|
||||
assert self.hass
|
||||
|
||||
# Remove reauth notification if no reauth flows are in progress
|
||||
if self.source == SOURCE_REAUTH and not any(
|
||||
ent["context"]["source"] == SOURCE_REAUTH
|
||||
for ent in self.hass.config_entries.flow.async_progress()
|
||||
if ent["flow_id"] != self.flow_id
|
||||
):
|
||||
self.hass.components.persistent_notification.async_dismiss(
|
||||
RECONFIGURE_NOTIFICATION_ID
|
||||
)
|
||||
|
||||
return super().async_abort(
|
||||
reason=reason, description_placeholders=description_placeholders
|
||||
)
|
||||
|
||||
async_step_hassio = async_step_discovery
|
||||
async_step_homekit = async_step_discovery
|
||||
async_step_mqtt = async_step_discovery
|
||||
|
||||
Reference in New Issue
Block a user