diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 94dfb2bd1c8..49282c70cb0 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -16,8 +16,12 @@ import voluptuous as vol import yarl from . import config as conf_util, config_entries, core, loader -from .components import http -from .const import REQUIRED_NEXT_PYTHON_HA_RELEASE, REQUIRED_NEXT_PYTHON_VER +from .components import http, persistent_notification +from .const import ( + REQUIRED_NEXT_PYTHON_HA_RELEASE, + REQUIRED_NEXT_PYTHON_VER, + SIGNAL_BOOTSTRAP_INTEGRATONS, +) from .exceptions import HomeAssistantError from .helpers import area_registry, device_registry, entity_registry from .helpers.dispatcher import async_dispatcher_send @@ -46,7 +50,6 @@ DATA_LOGGING = "logging" LOG_SLOW_STARTUP_INTERVAL = 60 SLOW_STARTUP_CHECK_INTERVAL = 1 -SIGNAL_BOOTSTRAP_INTEGRATONS = "bootstrap_integrations" STAGE_1_TIMEOUT = 120 STAGE_2_TIMEOUT = 300 @@ -252,8 +255,8 @@ async def async_from_config_dict( f"{'.'.join(str(x) for x in REQUIRED_NEXT_PYTHON_VER[:2])}." ) _LOGGER.warning(msg) - hass.components.persistent_notification.async_create( - msg, "Python version", "python_version" + persistent_notification.async_create( + hass, msg, "Python version", "python_version" ) return hass diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index cbf84cd002e..4020601dc3f 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -9,8 +9,12 @@ from typing import Any import voluptuous as vol from homeassistant.auth.permissions.const import CAT_ENTITIES, POLICY_READ -from homeassistant.bootstrap import SIGNAL_BOOTSTRAP_INTEGRATONS -from homeassistant.const import EVENT_STATE_CHANGED, EVENT_TIME_CHANGED, MATCH_ALL +from homeassistant.const import ( + EVENT_STATE_CHANGED, + EVENT_TIME_CHANGED, + MATCH_ALL, + SIGNAL_BOOTSTRAP_INTEGRATONS, +) from homeassistant.core import Context, Event, HomeAssistant, callback from homeassistant.exceptions import ( HomeAssistantError, diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 7ed0bfb1821..9c1faf8f77a 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -14,6 +14,7 @@ import weakref from . import data_entry_flow, loader from .backports.enum import StrEnum +from .components import persistent_notification from .const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP, Platform from .core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback from .exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady, HomeAssistantError @@ -657,9 +658,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager): # Remove notification if no other discovery config entries in progress if not self._async_has_other_discovery_flows(flow.flow_id): - self.hass.components.persistent_notification.async_dismiss( - DISCOVERY_NOTIFICATION_ID - ) + persistent_notification.async_dismiss(self.hass, DISCOVERY_NOTIFICATION_ID) if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY: return result @@ -757,7 +756,8 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager): # Create notification. if source in DISCOVERY_SOURCES: self.hass.bus.async_fire(EVENT_FLOW_DISCOVERED) - self.hass.components.persistent_notification.async_create( + persistent_notification.async_create( + self.hass, title="New devices discovered", message=( "We have discovered new devices on your network. " @@ -766,7 +766,8 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager): notification_id=DISCOVERY_NOTIFICATION_ID, ) elif source == SOURCE_REAUTH: - self.hass.components.persistent_notification.async_create( + persistent_notification.async_create( + self.hass, title="Integration requires reconfiguration", message=( "At least one of your integrations requires reconfiguration to " @@ -1382,8 +1383,8 @@ class ConfigFlow(data_entry_flow.FlowHandler): ) if ent["flow_id"] != self.flow_id ): - self.hass.components.persistent_notification.async_dismiss( - RECONFIGURE_NOTIFICATION_ID + persistent_notification.async_dismiss( + self.hass, RECONFIGURE_NOTIFICATION_ID ) return super().async_abort( diff --git a/homeassistant/const.py b/homeassistant/const.py index f5032079ca5..8dbde276e4c 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -765,3 +765,5 @@ CAST_APP_ID_HOMEASSISTANT_LOVELACE: Final = "A078F6B0" # User used by Supervisor HASSIO_USER_NAME = "Supervisor" + +SIGNAL_BOOTSTRAP_INTEGRATONS = "bootstrap_integrations" diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 1ad64e58bd7..87d93c1a1ac 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -8,8 +8,8 @@ from unittest.mock import Mock, patch import pytest from homeassistant import bootstrap, core, runner -from homeassistant.bootstrap import SIGNAL_BOOTSTRAP_INTEGRATONS import homeassistant.config as config_util +from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATONS from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.dispatcher import async_dispatcher_connect import homeassistant.util.dt as dt_util