Skip to content

Commit 8d6e2ae

Browse files
authored
Import persistent notification part 1 (home-assistant#63898)
1 parent 65deaa1 commit 8d6e2ae

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

homeassistant/bootstrap.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
import yarl
1717

1818
from . import config as conf_util, config_entries, core, loader
19-
from .components import http
20-
from .const import REQUIRED_NEXT_PYTHON_HA_RELEASE, REQUIRED_NEXT_PYTHON_VER
19+
from .components import http, persistent_notification
20+
from .const import (
21+
REQUIRED_NEXT_PYTHON_HA_RELEASE,
22+
REQUIRED_NEXT_PYTHON_VER,
23+
SIGNAL_BOOTSTRAP_INTEGRATONS,
24+
)
2125
from .exceptions import HomeAssistantError
2226
from .helpers import area_registry, device_registry, entity_registry
2327
from .helpers.dispatcher import async_dispatcher_send
@@ -46,7 +50,6 @@
4650

4751
LOG_SLOW_STARTUP_INTERVAL = 60
4852
SLOW_STARTUP_CHECK_INTERVAL = 1
49-
SIGNAL_BOOTSTRAP_INTEGRATONS = "bootstrap_integrations"
5053

5154
STAGE_1_TIMEOUT = 120
5255
STAGE_2_TIMEOUT = 300
@@ -252,8 +255,8 @@ async def async_from_config_dict(
252255
f"{'.'.join(str(x) for x in REQUIRED_NEXT_PYTHON_VER[:2])}."
253256
)
254257
_LOGGER.warning(msg)
255-
hass.components.persistent_notification.async_create(
256-
msg, "Python version", "python_version"
258+
persistent_notification.async_create(
259+
hass, msg, "Python version", "python_version"
257260
)
258261

259262
return hass

homeassistant/components/websocket_api/commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
import voluptuous as vol
1010

1111
from homeassistant.auth.permissions.const import CAT_ENTITIES, POLICY_READ
12-
from homeassistant.bootstrap import SIGNAL_BOOTSTRAP_INTEGRATONS
13-
from homeassistant.const import EVENT_STATE_CHANGED, EVENT_TIME_CHANGED, MATCH_ALL
12+
from homeassistant.const import (
13+
EVENT_STATE_CHANGED,
14+
EVENT_TIME_CHANGED,
15+
MATCH_ALL,
16+
SIGNAL_BOOTSTRAP_INTEGRATONS,
17+
)
1418
from homeassistant.core import Context, Event, HomeAssistant, callback
1519
from homeassistant.exceptions import (
1620
HomeAssistantError,

homeassistant/config_entries.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from . import data_entry_flow, loader
1616
from .backports.enum import StrEnum
17+
from .components import persistent_notification
1718
from .const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP, Platform
1819
from .core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback
1920
from .exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady, HomeAssistantError
@@ -657,9 +658,7 @@ async def async_finish_flow(
657658

658659
# Remove notification if no other discovery config entries in progress
659660
if not self._async_has_other_discovery_flows(flow.flow_id):
660-
self.hass.components.persistent_notification.async_dismiss(
661-
DISCOVERY_NOTIFICATION_ID
662-
)
661+
persistent_notification.async_dismiss(self.hass, DISCOVERY_NOTIFICATION_ID)
663662

664663
if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
665664
return result
@@ -757,7 +756,8 @@ async def async_post_init(
757756
# Create notification.
758757
if source in DISCOVERY_SOURCES:
759758
self.hass.bus.async_fire(EVENT_FLOW_DISCOVERED)
760-
self.hass.components.persistent_notification.async_create(
759+
persistent_notification.async_create(
760+
self.hass,
761761
title="New devices discovered",
762762
message=(
763763
"We have discovered new devices on your network. "
@@ -766,7 +766,8 @@ async def async_post_init(
766766
notification_id=DISCOVERY_NOTIFICATION_ID,
767767
)
768768
elif source == SOURCE_REAUTH:
769-
self.hass.components.persistent_notification.async_create(
769+
persistent_notification.async_create(
770+
self.hass,
770771
title="Integration requires reconfiguration",
771772
message=(
772773
"At least one of your integrations requires reconfiguration to "
@@ -1382,8 +1383,8 @@ def async_abort(
13821383
)
13831384
if ent["flow_id"] != self.flow_id
13841385
):
1385-
self.hass.components.persistent_notification.async_dismiss(
1386-
RECONFIGURE_NOTIFICATION_ID
1386+
persistent_notification.async_dismiss(
1387+
self.hass, RECONFIGURE_NOTIFICATION_ID
13871388
)
13881389

13891390
return super().async_abort(

homeassistant/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,3 +765,5 @@ class Platform(StrEnum):
765765

766766
# User used by Supervisor
767767
HASSIO_USER_NAME = "Supervisor"
768+
769+
SIGNAL_BOOTSTRAP_INTEGRATONS = "bootstrap_integrations"

tests/test_bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import pytest
99

1010
from homeassistant import bootstrap, core, runner
11-
from homeassistant.bootstrap import SIGNAL_BOOTSTRAP_INTEGRATONS
1211
import homeassistant.config as config_util
12+
from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATONS
1313
from homeassistant.exceptions import HomeAssistantError
1414
from homeassistant.helpers.dispatcher import async_dispatcher_connect
1515
import homeassistant.util.dt as dt_util

0 commit comments

Comments
 (0)