From 2eab3c8de1fd80a8f1456fd97389ca687c11ecb7 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 11 Jan 2022 18:51:16 +0100 Subject: [PATCH] Import persistent notification (part 3) (#63900) --- homeassistant/components/doorbird/__init__.py | 4 +++- homeassistant/components/google/__init__.py | 13 +++++++++---- homeassistant/components/hassio/__init__.py | 4 +++- homeassistant/components/homeassistant/__init__.py | 4 +++- homeassistant/components/homekit/util.py | 13 ++++++++----- homeassistant/components/http/ban.py | 8 +++++--- homeassistant/components/hydrawise/__init__.py | 4 +++- homeassistant/components/logi_circle/__init__.py | 13 +++++++++---- homeassistant/components/lupusec/__init__.py | 4 +++- homeassistant/components/maxcube/__init__.py | 4 +++- 10 files changed, 49 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/doorbird/__init__.py b/homeassistant/components/doorbird/__init__.py index 1e15f481dda..0bd34d1a724 100644 --- a/homeassistant/components/doorbird/__init__.py +++ b/homeassistant/components/doorbird/__init__.py @@ -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 " diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index b76b59afba2..0dfacb13e74 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -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}
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: {dev_flow.verification_url} 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" diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index 0ac512d0034..a0e19943bb9 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -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", diff --git a/homeassistant/components/homeassistant/__init__.py b/homeassistant/components/homeassistant/__init__.py index 5747fe4463e..c2d855d3135 100644 --- a/homeassistant/components/homeassistant/__init__.py +++ b/homeassistant/components/homeassistant/__init__.py @@ -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", diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index 945578dab3b..3165280a37b 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -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): diff --git a/homeassistant/components/http/ban.py b/homeassistant/components/http/ban.py index a1d50dbdcb5..576cb348ac8 100644 --- a/homeassistant/components/http/ban.py +++ b/homeassistant/components/http/ban.py @@ -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, diff --git a/homeassistant/components/hydrawise/__init__.py b/homeassistant/components/hydrawise/__init__.py index 12afcd7ff80..d92d785fadf 100644 --- a/homeassistant/components/hydrawise/__init__.py +++ b/homeassistant/components/hydrawise/__init__.py @@ -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}
You will need to restart hass after fixing.", title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID, diff --git a/homeassistant/components/logi_circle/__init__.py b/homeassistant/components/logi_circle/__init__.py index 1b193c33554..fff086b6c4e 100644 --- a/homeassistant/components/logi_circle/__init__.py +++ b/homeassistant/components/logi_circle/__init__.py @@ -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}.
" 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.
" "Token may have expired or been revoked.
" @@ -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}
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}
You will need to restart hass after fixing.", title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID, diff --git a/homeassistant/components/lupusec/__init__.py b/homeassistant/components/lupusec/__init__.py index fd55f0b4d9a..9beeb0f20ee 100644 --- a/homeassistant/components/lupusec/__init__.py +++ b/homeassistant/components/lupusec/__init__.py @@ -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}
You will need to restart hass after fixing.", title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID, diff --git a/homeassistant/components/maxcube/__init__.py b/homeassistant/components/maxcube/__init__.py index fe217d851e9..04a5ee97935 100644 --- a/homeassistant/components/maxcube/__init__.py +++ b/homeassistant/components/maxcube/__init__.py @@ -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}
You will need to restart Home Assistant after fixing.", title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID,