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