Import persistent notification (part 4) (#63901)
This commit is contained in:
parent
4b6e196606
commit
a672dc3437
10 changed files with 58 additions and 35 deletions
|
@ -7,7 +7,7 @@ from typing import cast
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.auth import EVENT_USER_REMOVED
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.components import persistent_notification, websocket_api
|
||||
from homeassistant.components.device_tracker import (
|
||||
ATTR_SOURCE_TYPE,
|
||||
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
||||
|
@ -278,7 +278,8 @@ async def filter_yaml_data(hass: HomeAssistant, persons: list[dict]) -> list[dic
|
|||
filtered.append(person_conf)
|
||||
|
||||
if person_invalid_user:
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
f"""
|
||||
The following persons point at invalid users:
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from tesla_powerwall import (
|
|||
PowerwallUnreachableError,
|
||||
)
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -78,7 +79,8 @@ async def _async_handle_api_changed_error(
|
|||
):
|
||||
# The error might include some important information about what exactly changed.
|
||||
_LOGGER.error(str(error))
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"It seems like your powerwall uses an unsupported version. "
|
||||
"Please update the software of your powerwall or if it is "
|
||||
"already the newest consider reporting this issue.\nSee logs for more information",
|
||||
|
|
|
@ -14,6 +14,7 @@ import objgraph
|
|||
from pyprof2calltree import convert
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
|
@ -68,7 +69,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
if LOG_INTERVAL_SUB in domain_data:
|
||||
domain_data[LOG_INTERVAL_SUB]()
|
||||
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"Object growth logging has started. See [the logs](/config/logs) to track the growth of new objects.",
|
||||
title="Object growth logging started",
|
||||
notification_id="profile_object_logging",
|
||||
|
@ -82,7 +84,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
if LOG_INTERVAL_SUB not in domain_data:
|
||||
return
|
||||
|
||||
hass.components.persistent_notification.async_dismiss("profile_object_logging")
|
||||
persistent_notification.async_dismiss(hass, "profile_object_logging")
|
||||
domain_data.pop(LOG_INTERVAL_SUB)()
|
||||
|
||||
def _dump_log_objects(call: ServiceCall) -> None:
|
||||
|
@ -94,7 +96,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
objgraph.by_type(obj_type),
|
||||
)
|
||||
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
f"Objects with type {obj_type} have been dumped to the log. See [the logs](/config/logs) to review the repr of the objects.",
|
||||
title="Object dump completed",
|
||||
notification_id="profile_object_dump",
|
||||
|
@ -206,7 +209,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
async def _async_generate_profile(hass: HomeAssistant, call: ServiceCall):
|
||||
start_time = int(time.time() * 1000000)
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"The profile has started. This notification will be updated when it is complete.",
|
||||
title="Profile Started",
|
||||
notification_id=f"profiler_{start_time}",
|
||||
|
@ -221,7 +225,8 @@ async def _async_generate_profile(hass: HomeAssistant, call: ServiceCall):
|
|||
await hass.async_add_executor_job(
|
||||
_write_profile, profiler, cprofile_path, callgrind_path
|
||||
)
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
f"Wrote cProfile data to {cprofile_path} and callgrind data to {callgrind_path}",
|
||||
title="Profile Complete",
|
||||
notification_id=f"profiler_{start_time}",
|
||||
|
@ -230,7 +235,8 @@ async def _async_generate_profile(hass: HomeAssistant, call: ServiceCall):
|
|||
|
||||
async def _async_generate_memory_profile(hass: HomeAssistant, call: ServiceCall):
|
||||
start_time = int(time.time() * 1000000)
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"The memory profile has started. This notification will be updated when it is complete.",
|
||||
title="Profile Started",
|
||||
notification_id=f"memory_profiler_{start_time}",
|
||||
|
@ -242,7 +248,8 @@ async def _async_generate_memory_profile(hass: HomeAssistant, call: ServiceCall)
|
|||
|
||||
heap_path = hass.config.path(f"heap_profile.{start_time}.hpy")
|
||||
await hass.async_add_executor_job(_write_memory_profile, heap, heap_path)
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
f"Wrote heapy memory profile to {heap_path}",
|
||||
title="Profile Complete",
|
||||
notification_id=f"memory_profiler_{start_time}",
|
||||
|
|
|
@ -6,6 +6,7 @@ from pyps4_2ndscreen.ddp import async_create_ddp_endpoint
|
|||
from pyps4_2ndscreen.media_art import COUNTRIES
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.media_player.const import (
|
||||
ATTR_MEDIA_CONTENT_TYPE,
|
||||
ATTR_MEDIA_TITLE,
|
||||
|
@ -151,7 +152,8 @@ async def async_migrate_entry(hass, entry):
|
|||
Please remove the PS4 Integration and re-configure
|
||||
[here](/config/integrations)."""
|
||||
|
||||
hass.components.persistent_notification.async_create(
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
title="PlayStation 4 Integration Configuration Requires Update",
|
||||
message=msg,
|
||||
notification_id="config_entry_migration",
|
||||
|
|
|
@ -6,6 +6,7 @@ from raincloudy.core import RainCloudy
|
|||
from requests.exceptions import ConnectTimeout, HTTPError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_PASSWORD,
|
||||
|
@ -108,7 +109,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
hass.data[DATA_RAINCLOUD] = RainCloudHub(raincloud)
|
||||
except (ConnectTimeout, HTTPError) as ex:
|
||||
_LOGGER.error("Unable to connect to Rain 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 py17track import Client as SeventeenTrackClient
|
|||
from py17track.errors import SeventeenTrackError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
|
@ -254,8 +255,8 @@ class SeventeenTrackPackageSensor(SensorEntity):
|
|||
title = NOTIFICATION_DELIVERED_TITLE.format(identification)
|
||||
notification_id = NOTIFICATION_DELIVERED_TITLE.format(self._tracking_number)
|
||||
|
||||
self.hass.components.persistent_notification.create(
|
||||
message, title=title, notification_id=notification_id
|
||||
persistent_notification.create(
|
||||
self.hass, message, title=title, notification_id=notification_id
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from requests.exceptions import ConnectTimeout, HTTPError
|
|||
from skybellpy import Skybell
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_PASSWORD,
|
||||
|
@ -61,7 +62,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
hass.data[DOMAIN] = skybell
|
||||
except (ConnectTimeout, HTTPError) as ex:
|
||||
_LOGGER.error("Unable to connect to Skybell service: %s", str(ex))
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
"Error: {}<br />"
|
||||
"You will need to restart hass after fixing."
|
||||
"".format(ex),
|
||||
|
|
|
@ -8,6 +8,7 @@ from travispy import TravisPy
|
|||
from travispy.errors import TravisError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
SensorEntity,
|
||||
|
@ -106,7 +107,8 @@ def setup_platform(
|
|||
|
||||
except TravisError as ex:
|
||||
_LOGGER.error("Unable to connect to Travis CI service: %s", str(ex))
|
||||
hass.components.persistent_notification.create(
|
||||
persistent_notification.create(
|
||||
hass,
|
||||
"Error: {}<br />"
|
||||
"You will need to restart hass after fixing."
|
||||
"".format(ex),
|
||||
|
|
|
@ -158,9 +158,7 @@ async def test_ws_get_notifications(hass, hass_ws_client):
|
|||
assert len(notifications) == 0
|
||||
|
||||
# Create
|
||||
hass.components.persistent_notification.async_create(
|
||||
"test", notification_id="Beer 2"
|
||||
)
|
||||
pn.async_create(hass, "test", notification_id="Beer 2")
|
||||
await client.send_json({"id": 6, "type": "persistent_notification/get"})
|
||||
msg = await client.receive_json()
|
||||
assert msg["id"] == 6
|
||||
|
@ -186,7 +184,7 @@ async def test_ws_get_notifications(hass, hass_ws_client):
|
|||
assert notifications[0]["status"] == pn.STATUS_READ
|
||||
|
||||
# Dismiss
|
||||
hass.components.persistent_notification.async_dismiss("Beer 2")
|
||||
pn.async_dismiss(hass, "Beer 2")
|
||||
await client.send_json({"id": 8, "type": "persistent_notification/get"})
|
||||
msg = await client.receive_json()
|
||||
notifications = msg["result"]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from py17track.package import Package
|
||||
import pytest
|
||||
|
@ -301,12 +301,14 @@ async def test_delivered_not_shown(hass):
|
|||
)
|
||||
ProfileMock.package_list = [package]
|
||||
|
||||
hass.components.persistent_notification = MagicMock()
|
||||
await _setup_seventeentrack(hass, VALID_CONFIG_FULL_NO_DELIVERED)
|
||||
await _goto_future(hass)
|
||||
with patch(
|
||||
"homeassistant.components.seventeentrack.sensor.persistent_notification"
|
||||
) as persistent_notification_mock:
|
||||
await _setup_seventeentrack(hass, VALID_CONFIG_FULL_NO_DELIVERED)
|
||||
await _goto_future(hass)
|
||||
|
||||
assert not hass.states.async_entity_ids()
|
||||
hass.components.persistent_notification.create.assert_called()
|
||||
assert not hass.states.async_entity_ids()
|
||||
persistent_notification_mock.create.assert_called()
|
||||
|
||||
|
||||
async def test_delivered_shown(hass):
|
||||
|
@ -324,12 +326,14 @@ async def test_delivered_shown(hass):
|
|||
)
|
||||
ProfileMock.package_list = [package]
|
||||
|
||||
hass.components.persistent_notification = MagicMock()
|
||||
await _setup_seventeentrack(hass, VALID_CONFIG_FULL)
|
||||
with patch(
|
||||
"homeassistant.components.seventeentrack.sensor.persistent_notification"
|
||||
) as persistent_notification_mock:
|
||||
await _setup_seventeentrack(hass, VALID_CONFIG_FULL)
|
||||
|
||||
assert hass.states.get("sensor.seventeentrack_package_456") is not None
|
||||
assert len(hass.states.async_entity_ids()) == 1
|
||||
hass.components.persistent_notification.create.assert_not_called()
|
||||
assert hass.states.get("sensor.seventeentrack_package_456") is not None
|
||||
assert len(hass.states.async_entity_ids()) == 1
|
||||
persistent_notification_mock.create.assert_not_called()
|
||||
|
||||
|
||||
async def test_becomes_delivered_not_shown_notification(hass):
|
||||
|
@ -364,11 +368,13 @@ async def test_becomes_delivered_not_shown_notification(hass):
|
|||
)
|
||||
ProfileMock.package_list = [package_delivered]
|
||||
|
||||
hass.components.persistent_notification = MagicMock()
|
||||
await _goto_future(hass)
|
||||
with patch(
|
||||
"homeassistant.components.seventeentrack.sensor.persistent_notification"
|
||||
) as persistent_notification_mock:
|
||||
await _goto_future(hass)
|
||||
|
||||
hass.components.persistent_notification.create.assert_called()
|
||||
assert not hass.states.async_entity_ids()
|
||||
persistent_notification_mock.create.assert_called()
|
||||
assert not hass.states.async_entity_ids()
|
||||
|
||||
|
||||
async def test_summary_correctly_updated(hass):
|
||||
|
|
Loading…
Add table
Reference in a new issue