Import persistent notification (part 3) (#63900)
parent
9c9dc4cb8c
commit
2eab3c8de1
|
@ -7,6 +7,7 @@ from doorbirdpy import DoorBird
|
|||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -167,7 +168,8 @@ async def _async_register_events(hass, doorstation):
|
|||
try:
|
||||
await hass.async_add_executor_job(doorstation.register_events, hass)
|
||||
except requests.exceptions.HTTPError:
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"Doorbird configuration failed. Please verify that API "
|
||||
"Operator permission is enabled for the Doorbird user. "
|
||||
"A restart will be required once permissions have been "
|
||||
|
|
|
@ -16,6 +16,7 @@ import voluptuous as vol
|
|||
from voluptuous.error import Error as VoluptuousError
|
||||
import yaml
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import (
|
||||
CONF_CLIENT_ID,
|
||||
CONF_CLIENT_SECRET,
|
||||
|
@ -172,14 +173,16 @@ def do_authentication(hass, hass_config, config):
|
|||
try:
|
||||
dev_flow = oauth.step1_get_device_and_user_codes()
|
||||
except OAuth2DeviceCodeError as err:
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
f"Error: {err}<br />You will need to restart hass after fixing." "",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
)
|
||||
return False
|
||||
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
(
|
||||
f"In order to authorize Home-Assistant to view your calendars "
|
||||
f'you must visit: <a href="{dev_flow.verification_url}" target="_blank">{dev_flow.verification_url}</a> and enter '
|
||||
|
@ -197,7 +200,8 @@ def do_authentication(hass, hass_config, config):
|
|||
user_code_expiry = dev_flow.user_code_expiry.replace(tzinfo=timezone.utc)
|
||||
|
||||
if now >= user_code_expiry:
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
"Authentication code expired, please restart "
|
||||
"Home-Assistant and try again",
|
||||
title=NOTIFICATION_TITLE,
|
||||
|
@ -215,7 +219,8 @@ def do_authentication(hass, hass_config, config):
|
|||
storage.put(credentials)
|
||||
do_setup(hass, hass_config, config)
|
||||
listener()
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
(
|
||||
f"We are all setup now. Check {YAML_DEVICES} for calendars that have "
|
||||
f"been found"
|
||||
|
|
|
@ -10,6 +10,7 @@ from typing import Any, NamedTuple
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.auth.const import GROUP_ID_ADMIN
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.homeassistant import (
|
||||
SERVICE_CHECK_CONFIG,
|
||||
SHUTDOWN_SERVICES,
|
||||
|
@ -598,7 +599,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
|||
call.service,
|
||||
errors,
|
||||
)
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"Config error. See [the logs](/config/logs) for details.",
|
||||
"Config validating",
|
||||
f"{HASS_DOMAIN}.check_config",
|
||||
|
|
|
@ -6,6 +6,7 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.auth.permissions.const import CAT_ENTITIES, POLICY_CONTROL
|
||||
from homeassistant.components import persistent_notification
|
||||
import homeassistant.config as conf_util
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -162,7 +163,8 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no
|
|||
call.service,
|
||||
errors,
|
||||
)
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"Config error. See [the logs](/config/logs) for details.",
|
||||
"Config validating",
|
||||
f"{ha.DOMAIN}.check_config",
|
||||
|
|
|
@ -12,7 +12,12 @@ import socket
|
|||
import pyqrcode
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import binary_sensor, media_player, sensor
|
||||
from homeassistant.components import (
|
||||
binary_sensor,
|
||||
media_player,
|
||||
persistent_notification,
|
||||
sensor,
|
||||
)
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
|
||||
from homeassistant.components.media_player import (
|
||||
|
@ -342,14 +347,12 @@ def async_show_setup_message(hass, entry_id, bridge_name, pincode, uri):
|
|||
f"### {pin}\n"
|
||||
f"![image](/api/homekit/pairingqr?{entry_id}-{pairing_secret})"
|
||||
)
|
||||
hass.components.persistent_notification.async_create(
|
||||
message, "HomeKit Pairing", entry_id
|
||||
)
|
||||
persistent_notification.async_create(hass, message, "HomeKit Pairing", entry_id)
|
||||
|
||||
|
||||
def async_dismiss_setup_message(hass, entry_id):
|
||||
"""Dismiss persistent notification and remove QR code."""
|
||||
hass.components.persistent_notification.async_dismiss(entry_id)
|
||||
persistent_notification.async_dismiss(hass, entry_id)
|
||||
|
||||
|
||||
def convert_to_float(state):
|
||||
|
|
|
@ -15,6 +15,7 @@ from aiohttp.web import Application, Request, StreamResponse, middleware
|
|||
from aiohttp.web_exceptions import HTTPForbidden, HTTPUnauthorized
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
@ -123,8 +124,8 @@ async def process_wrong_login(request: Request) -> None:
|
|||
|
||||
_LOGGER.warning(log_msg)
|
||||
|
||||
hass.components.persistent_notification.async_create(
|
||||
notification_msg, "Login attempt failed", NOTIFICATION_ID_LOGIN
|
||||
persistent_notification.async_create(
|
||||
hass, notification_msg, "Login attempt failed", NOTIFICATION_ID_LOGIN
|
||||
)
|
||||
|
||||
# Check if ban middleware is loaded
|
||||
|
@ -153,7 +154,8 @@ async def process_wrong_login(request: Request) -> None:
|
|||
|
||||
_LOGGER.warning("Banned IP %s for too many login attempts", remote_addr)
|
||||
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
f"Too many login attempts from {remote_addr}",
|
||||
"Banning IP address",
|
||||
NOTIFICATION_ID_BAN,
|
||||
|
|
|
@ -6,6 +6,7 @@ from hydrawiser.core import Hydrawiser
|
|||
from requests.exceptions import ConnectTimeout, HTTPError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -57,7 +58,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
hass.data[DATA_HYDRAWISE] = HydrawiseHub(hydrawise)
|
||||
except (ConnectTimeout, HTTPError) as ex:
|
||||
_LOGGER.error("Unable to connect to Hydrawise cloud service: %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,
|
||||
|
|
|
@ -8,6 +8,7 @@ from logi_circle.exception import AuthorizationFailed
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.camera import ATTR_FILENAME
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -140,7 +141,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
)
|
||||
|
||||
if not logi_circle.authorized:
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
(
|
||||
f"Error: The cached access tokens are missing from {DEFAULT_CACHEDB}.<br />"
|
||||
f"Please unload then re-add the Logi Circle integration to resolve."
|
||||
|
@ -156,7 +158,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
# all devices. Performs implicit login and session validation.
|
||||
await logi_circle.synchronize_cameras()
|
||||
except AuthorizationFailed:
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
"Error: Failed to obtain an access token from the cached "
|
||||
"refresh token.<br />"
|
||||
"Token may have expired or been revoked.<br />"
|
||||
|
@ -169,14 +172,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
# The TimeoutError exception object returns nothing when casted to a
|
||||
# string, so we'll handle it separately.
|
||||
err = f"{_TIMEOUT}s timeout exceeded when connecting to Logi Circle API"
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
f"Error: {err}<br />You will need to restart hass after fixing.",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
)
|
||||
return False
|
||||
except ClientResponseError as 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,
|
||||
|
|
|
@ -5,6 +5,7 @@ import lupupy
|
|||
from lupupy.exceptions import LupusecException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import (
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_NAME,
|
||||
|
@ -58,7 +59,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
except LupusecException as ex:
|
||||
_LOGGER.error(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,
|
||||
|
|
|
@ -7,6 +7,7 @@ import time
|
|||
from maxcube.cube import MaxCube
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SCAN_INTERVAL, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -66,7 +67,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
hass.data[DATA_KEY][host] = MaxCubeHandle(cube, scan_interval)
|
||||
except timeout as ex:
|
||||
_LOGGER.error("Unable to connect to Max!Cube gateway: %s", str(ex))
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
f"Error: {ex}<br />You will need to restart Home Assistant after fixing.",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
|
|
Loading…
Reference in New Issue