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