From b1960645401fec60efb7cdf8975985243cf05d34 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 13 Jan 2022 08:45:30 +0100 Subject: [PATCH] Import persistent notification (part 5) (#63902) --- homeassistant/components/vultr/__init__.py | 4 +++- homeassistant/components/waterfurnace/__init__.py | 4 +++- homeassistant/components/wirelesstag/__init__.py | 4 +++- homeassistant/components/xiaomi_aqara/__init__.py | 4 +++- homeassistant/components/xiaomi_miio/remote.py | 9 +++++---- tests/components/websocket_api/test_commands.py | 2 +- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/vultr/__init__.py b/homeassistant/components/vultr/__init__.py index 4813f8c7f65..4e27e77ac86 100644 --- a/homeassistant/components/vultr/__init__.py +++ b/homeassistant/components/vultr/__init__.py @@ -5,6 +5,7 @@ import logging import voluptuous as vol from vultr import Vultr as VultrAPI +from homeassistant.components import persistent_notification from homeassistant.const import CONF_API_KEY, Platform from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -56,7 +57,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: vultr.update() except RuntimeError as ex: _LOGGER.error("Failed to make update API request because: %s", ex) - hass.components.persistent_notification.create( + persistent_notification.create( + hass, "Error: {}" "".format(ex), title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID, diff --git a/homeassistant/components/waterfurnace/__init__.py b/homeassistant/components/waterfurnace/__init__.py index b74fea3c97d..1da170f2b75 100644 --- a/homeassistant/components/waterfurnace/__init__.py +++ b/homeassistant/components/waterfurnace/__init__.py @@ -7,6 +7,7 @@ import time import voluptuous as vol from waterfurnace.waterfurnace import WaterFurnace, WFCredentialError, WFException +from homeassistant.components import persistent_notification from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, @@ -92,7 +93,8 @@ class WaterFurnaceData(threading.Thread): self._fails += 1 if self._fails > MAX_FAILS: _LOGGER.error("Failed to refresh login credentials. Thread stopped") - self.hass.components.persistent_notification.create( + persistent_notification.create( + self.hass, "Error:
Connection to waterfurnace website failed " "the maximum number of times. Thread has stopped", title=NOTIFICATION_TITLE, diff --git a/homeassistant/components/wirelesstag/__init__.py b/homeassistant/components/wirelesstag/__init__.py index b2a232c769e..c94c518709d 100644 --- a/homeassistant/components/wirelesstag/__init__.py +++ b/homeassistant/components/wirelesstag/__init__.py @@ -6,6 +6,7 @@ import voluptuous as vol from wirelesstagpy import WirelessTags from wirelesstagpy.exceptions import WirelessTagsException +from homeassistant.components import persistent_notification from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_VOLTAGE, @@ -141,7 +142,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.data[DOMAIN] = platform except (ConnectTimeout, HTTPError, WirelessTagsException) as ex: _LOGGER.error("Unable to connect to wirelesstag.net service: %s", str(ex)) - hass.components.persistent_notification.create( + persistent_notification.create( + hass, f"Error: {ex}
Please restart hass after fixing this.", title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID, diff --git a/homeassistant/components/xiaomi_aqara/__init__.py b/homeassistant/components/xiaomi_aqara/__init__.py index d1b9b58f215..0ce7b6c4d0f 100644 --- a/homeassistant/components/xiaomi_aqara/__init__.py +++ b/homeassistant/components/xiaomi_aqara/__init__.py @@ -6,6 +6,7 @@ import voluptuous as vol from xiaomi_gateway import XiaomiGateway, XiaomiGatewayDiscovery from homeassistant import config_entries, core +from homeassistant.components import persistent_notification from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_DEVICE_ID, @@ -99,7 +100,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Service to add a new sub-device within the next 30 seconds.""" gateway = call.data.get(ATTR_GW_MAC) gateway.write_to_hub(gateway.sid, join_permission="yes") - hass.components.persistent_notification.async_create( + persistent_notification.async_create( + hass, "Join permission enabled for 30 seconds! " "Please press the pairing button of the new device once.", title="Xiaomi Aqara Gateway", diff --git a/homeassistant/components/xiaomi_miio/remote.py b/homeassistant/components/xiaomi_miio/remote.py index 890adc8fcde..199f5dd6c5d 100644 --- a/homeassistant/components/xiaomi_miio/remote.py +++ b/homeassistant/components/xiaomi_miio/remote.py @@ -9,6 +9,7 @@ import time from miio import ChuangmiIr, DeviceException import voluptuous as vol +from homeassistant.components import persistent_notification from homeassistant.components.remote import ( ATTR_DELAY_SECS, ATTR_NUM_REPEATS, @@ -138,8 +139,8 @@ async def async_setup_platform( if "code" in message and message["code"]: log_msg = "Received command is: {}".format(message["code"]) _LOGGER.info(log_msg) - hass.components.persistent_notification.async_create( - log_msg, title="Xiaomi Miio Remote" + persistent_notification.async_create( + hass, log_msg, title="Xiaomi Miio Remote" ) return @@ -149,8 +150,8 @@ async def async_setup_platform( await asyncio.sleep(1) _LOGGER.error("Timeout. No infrared command captured") - hass.components.persistent_notification.async_create( - "Timeout. No infrared command captured", title="Xiaomi Miio Remote" + persistent_notification.async_create( + hass, "Timeout. No infrared command captured", title="Xiaomi Miio Remote" ) platform = entity_platform.async_get_current_platform() diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index e1606561890..58c9b414d5a 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -6,7 +6,6 @@ from async_timeout import timeout import pytest import voluptuous as vol -from homeassistant.bootstrap import SIGNAL_BOOTSTRAP_INTEGRATONS from homeassistant.components.websocket_api import const from homeassistant.components.websocket_api.auth import ( TYPE_AUTH, @@ -14,6 +13,7 @@ from homeassistant.components.websocket_api.auth import ( TYPE_AUTH_REQUIRED, ) from homeassistant.components.websocket_api.const import URL +from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATONS from homeassistant.core import Context, HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity