mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Import persistent notification (part 2) (#63899)
This commit is contained in:
parent
bc7624b417
commit
03593aa21b
@ -7,6 +7,7 @@ from typing import Any, Final
|
||||
from aladdin_connect import AladdinConnectClient
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.cover import (
|
||||
PLATFORM_SCHEMA as BASE_PLATFORM_SCHEMA,
|
||||
CoverDeviceClass,
|
||||
@ -55,7 +56,8 @@ def setup_platform(
|
||||
)
|
||||
except (TypeError, KeyError, NameError, ValueError) as ex:
|
||||
_LOGGER.error("%s", ex)
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
"Error: {ex}<br />You will need to restart hass after fixing.",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
|
@ -8,6 +8,7 @@ from alpha_vantage.foreignexchange import ForeignExchange
|
||||
from alpha_vantage.timeseries import TimeSeries
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_CURRENCY, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -79,7 +80,7 @@ def setup_platform(
|
||||
|
||||
if not symbols and not conversions:
|
||||
msg = "No symbols or currencies configured."
|
||||
hass.components.persistent_notification.create(msg, "Sensor alpha_vantage")
|
||||
persistent_notification.create(hass, msg, "Sensor alpha_vantage")
|
||||
_LOGGER.warning(msg)
|
||||
return
|
||||
|
||||
|
@ -17,6 +17,7 @@ from androidtv.constants import APPS, KEYS
|
||||
from androidtv.exceptions import LockNotAcquiredException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
|
||||
from homeassistant.components.media_player.const import (
|
||||
SUPPORT_NEXT_TRACK,
|
||||
@ -534,7 +535,8 @@ class ADBDevice(MediaPlayerEntity):
|
||||
self.async_write_ha_state()
|
||||
|
||||
msg = f"Output from service '{SERVICE_LEARN_SENDEVENT}' from {self.entity_id}: '{output}'"
|
||||
self.hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
self.hass,
|
||||
msg,
|
||||
title="Android TV",
|
||||
)
|
||||
|
@ -8,6 +8,7 @@ from pyarlo import PyArlo
|
||||
from requests.exceptions import ConnectTimeout, HTTPError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
@ -70,7 +71,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
except (ConnectTimeout, HTTPError) as ex:
|
||||
_LOGGER.error("Unable to connect to Netgear Arlo: %s", str(ex))
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
f"Error: {ex}<br />You will need to restart hass after fixing.",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
|
@ -15,6 +15,7 @@ from broadlink.exceptions import (
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.remote import (
|
||||
ATTR_ALTERNATIVE,
|
||||
ATTR_COMMAND_TYPE,
|
||||
@ -317,7 +318,8 @@ class BroadlinkRemote(BroadlinkEntity, RemoteEntity, RestoreEntity):
|
||||
_LOGGER.debug("Failed to enter learning mode: %s", err)
|
||||
raise
|
||||
|
||||
self.hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
self.hass,
|
||||
f"Press the '{command}' button.",
|
||||
title="Learn command",
|
||||
notification_id="learn_command",
|
||||
@ -339,8 +341,8 @@ class BroadlinkRemote(BroadlinkEntity, RemoteEntity, RestoreEntity):
|
||||
)
|
||||
|
||||
finally:
|
||||
self.hass.components.persistent_notification.async_dismiss(
|
||||
notification_id="learn_command"
|
||||
persistent_notification.async_dismiss(
|
||||
self.hass, notification_id="learn_command"
|
||||
)
|
||||
|
||||
async def _async_learn_rf_command(self, command):
|
||||
@ -354,7 +356,8 @@ class BroadlinkRemote(BroadlinkEntity, RemoteEntity, RestoreEntity):
|
||||
_LOGGER.debug("Failed to sweep frequency: %s", err)
|
||||
raise
|
||||
|
||||
self.hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
self.hass,
|
||||
f"Press and hold the '{command}' button.",
|
||||
title="Sweep frequency",
|
||||
notification_id="sweep_frequency",
|
||||
@ -375,8 +378,8 @@ class BroadlinkRemote(BroadlinkEntity, RemoteEntity, RestoreEntity):
|
||||
)
|
||||
|
||||
finally:
|
||||
self.hass.components.persistent_notification.async_dismiss(
|
||||
notification_id="sweep_frequency"
|
||||
persistent_notification.async_dismiss(
|
||||
self.hass, notification_id="sweep_frequency"
|
||||
)
|
||||
|
||||
await asyncio.sleep(1)
|
||||
@ -388,7 +391,8 @@ class BroadlinkRemote(BroadlinkEntity, RemoteEntity, RestoreEntity):
|
||||
_LOGGER.debug("Failed to enter learning mode: %s", err)
|
||||
raise
|
||||
|
||||
self.hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
self.hass,
|
||||
f"Press the '{command}' button again.",
|
||||
title="Learn command",
|
||||
notification_id="learn_command",
|
||||
@ -410,8 +414,8 @@ class BroadlinkRemote(BroadlinkEntity, RemoteEntity, RestoreEntity):
|
||||
)
|
||||
|
||||
finally:
|
||||
self.hass.components.persistent_notification.async_dismiss(
|
||||
notification_id="learn_command"
|
||||
persistent_notification.async_dismiss(
|
||||
self.hass, notification_id="learn_command"
|
||||
)
|
||||
|
||||
async def async_delete_command(self, **kwargs):
|
||||
|
@ -9,6 +9,7 @@ import aiohttp
|
||||
import async_timeout
|
||||
from hass_nabucasa import Cloud, cloud_api
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.alexa import (
|
||||
DOMAIN as ALEXA_DOMAIN,
|
||||
config as alexa_config,
|
||||
@ -158,7 +159,8 @@ class AlexaConfig(alexa_config.AbstractConfig):
|
||||
if body["reason"] in ("RefreshTokenNotFound", "UnknownRegion"):
|
||||
if self.should_report_state:
|
||||
await self._prefs.async_update(alexa_report_state=False)
|
||||
self.hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
self.hass,
|
||||
f"There was an error reporting state to Alexa ({body['reason']}). "
|
||||
"Please re-link your Alexa skill via the Alexa app to "
|
||||
"continue using it.",
|
||||
|
@ -10,6 +10,7 @@ from typing import Any
|
||||
import aiohttp
|
||||
from hass_nabucasa.client import CloudClient as Interface
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.alexa import (
|
||||
errors as alexa_errors,
|
||||
smart_home as alexa_sh,
|
||||
@ -163,9 +164,7 @@ class CloudClient(Interface):
|
||||
@callback
|
||||
def user_message(self, identifier: str, title: str, message: str) -> None:
|
||||
"""Create a message for user to UI."""
|
||||
self._hass.components.persistent_notification.async_create(
|
||||
message, title, identifier
|
||||
)
|
||||
persistent_notification.async_create(self._hass, message, title, identifier)
|
||||
|
||||
@callback
|
||||
def dispatcher_message(self, identifier: str, data: Any = None) -> None:
|
||||
|
@ -10,6 +10,7 @@ from decora_wifi.models.residence import Residence
|
||||
from decora_wifi.models.residential_account import ResidentialAccount
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_TRANSITION,
|
||||
@ -54,8 +55,8 @@ def setup_platform(
|
||||
if success is None:
|
||||
msg = "Failed to log into myLeviton Services. Check credentials."
|
||||
_LOGGER.error(msg)
|
||||
hass.components.persistent_notification.create(
|
||||
msg, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID
|
||||
persistent_notification.create(
|
||||
hass, msg, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -4,6 +4,7 @@ import datetime
|
||||
from random import random
|
||||
|
||||
from homeassistant import bootstrap, config_entries
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.recorder.statistics import (
|
||||
async_add_external_statistics,
|
||||
get_last_statistics,
|
||||
@ -163,8 +164,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
return False
|
||||
|
||||
# Set up example persistent notification
|
||||
hass.components.persistent_notification.async_create(
|
||||
"This is an example of a persistent notification.", title="Example Notification"
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"This is an example of a persistent notification.",
|
||||
title="Example Notification",
|
||||
)
|
||||
|
||||
async def demo_start_listener(_event):
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Demo platform that offers a fake button entity."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
@ -60,6 +61,6 @@ class DemoButton(ButtonEntity):
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Send out a persistent notification."""
|
||||
self.hass.components.persistent_notification.async_create(
|
||||
"Button pressed", title="Button"
|
||||
persistent_notification.async_create(
|
||||
self.hass, "Button pressed", title="Button"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user