Remove mark_read
service from persistent_notification (#94122)
* Remove mark_read from persistent_notification Nothing on the frontend uses this, and the service is not documented There is not much point in keeping this as the notifications are no longer stored in the state machine * adjust * adjust
This commit is contained in:
parent
2b39550e55
commit
6a573b507e
3 changed files with 0 additions and 105 deletions
|
@ -29,8 +29,6 @@ ATTR_NOTIFICATION_ID: Final = "notification_id"
|
|||
ATTR_TITLE: Final = "title"
|
||||
ATTR_STATUS: Final = "status"
|
||||
|
||||
STATUS_UNREAD = "unread"
|
||||
STATUS_READ = "read"
|
||||
|
||||
# Remove EVENT_PERSISTENT_NOTIFICATIONS_UPDATED in Home Assistant 2023.9
|
||||
EVENT_PERSISTENT_NOTIFICATIONS_UPDATED = "persistent_notifications_updated"
|
||||
|
@ -43,7 +41,6 @@ class Notification(TypedDict):
|
|||
message: str
|
||||
notification_id: str
|
||||
title: str | None
|
||||
status: str
|
||||
|
||||
|
||||
class UpdateType(StrEnum):
|
||||
|
@ -98,7 +95,6 @@ def async_create(
|
|||
notifications[notification_id] = {
|
||||
ATTR_MESSAGE: message,
|
||||
ATTR_NOTIFICATION_ID: notification_id,
|
||||
ATTR_STATUS: STATUS_UNREAD,
|
||||
ATTR_TITLE: title,
|
||||
ATTR_CREATED_AT: dt_util.utcnow(),
|
||||
}
|
||||
|
@ -135,7 +131,6 @@ def async_dismiss(hass: HomeAssistant, notification_id: str) -> None:
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the persistent notification component."""
|
||||
notifications = _async_get_or_create_notifications(hass)
|
||||
|
||||
@callback
|
||||
def create_service(call: ServiceCall) -> None:
|
||||
|
@ -152,29 +147,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
"""Handle the dismiss notification service call."""
|
||||
async_dismiss(hass, call.data[ATTR_NOTIFICATION_ID])
|
||||
|
||||
@callback
|
||||
def mark_read_service(call: ServiceCall) -> None:
|
||||
"""Handle the mark_read notification service call."""
|
||||
notification_id = call.data.get(ATTR_NOTIFICATION_ID)
|
||||
if notification_id not in notifications:
|
||||
_LOGGER.error(
|
||||
(
|
||||
"Marking persistent_notification read failed: "
|
||||
"Notification ID %s not found"
|
||||
),
|
||||
notification_id,
|
||||
)
|
||||
return
|
||||
|
||||
notification = notifications[notification_id]
|
||||
notification[ATTR_STATUS] = STATUS_READ
|
||||
async_dispatcher_send(
|
||||
hass,
|
||||
SIGNAL_PERSISTENT_NOTIFICATIONS_UPDATED,
|
||||
UpdateType.UPDATED,
|
||||
{notification_id: notification},
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
"create",
|
||||
|
@ -192,10 +164,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
DOMAIN, "dismiss", dismiss_service, SCHEMA_SERVICE_NOTIFICATION
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, "mark_read", mark_read_service, SCHEMA_SERVICE_NOTIFICATION
|
||||
)
|
||||
|
||||
websocket_api.async_register_command(hass, websocket_get_notifications)
|
||||
websocket_api.async_register_command(hass, websocket_subscribe_notifications)
|
||||
|
||||
|
|
|
@ -33,15 +33,3 @@ dismiss:
|
|||
example: 1234
|
||||
selector:
|
||||
text:
|
||||
|
||||
mark_read:
|
||||
name: Mark read
|
||||
description: Mark a notification read.
|
||||
fields:
|
||||
notification_id:
|
||||
name: Notification ID
|
||||
description: Target ID of the notification, which should be mark read.
|
||||
required: true
|
||||
example: 1234
|
||||
selector:
|
||||
text:
|
||||
|
|
|
@ -25,7 +25,6 @@ async def test_create(hass: HomeAssistant) -> None:
|
|||
assert len(notifications) == 1
|
||||
|
||||
notification = notifications[list(notifications)[0]]
|
||||
assert notification["status"] == pn.STATUS_UNREAD
|
||||
assert notification["message"] == "Hello World 2"
|
||||
assert notification["title"] == "2 beers"
|
||||
assert notification["created_at"] is not None
|
||||
|
@ -66,39 +65,6 @@ async def test_dismiss_notification(hass: HomeAssistant) -> None:
|
|||
assert len(notifications) == 0
|
||||
|
||||
|
||||
async def test_mark_read(hass: HomeAssistant) -> None:
|
||||
"""Ensure notification is marked as Read."""
|
||||
notifications = pn._async_get_or_create_notifications(hass)
|
||||
assert len(notifications) == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
pn.DOMAIN,
|
||||
"create",
|
||||
{"notification_id": "Beer 2", "message": "test"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(notifications) == 1
|
||||
notification = notifications[list(notifications)[0]]
|
||||
assert notification["status"] == pn.STATUS_UNREAD
|
||||
|
||||
await hass.services.async_call(
|
||||
pn.DOMAIN, "mark_read", {"notification_id": "Beer 2"}, blocking=True
|
||||
)
|
||||
|
||||
assert len(notifications) == 1
|
||||
notification = notifications[list(notifications)[0]]
|
||||
assert notification["status"] == pn.STATUS_READ
|
||||
|
||||
await hass.services.async_call(
|
||||
pn.DOMAIN,
|
||||
"dismiss",
|
||||
{"notification_id": "Beer 2"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(notifications) == 0
|
||||
|
||||
|
||||
async def test_ws_get_notifications(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
|
@ -128,19 +94,8 @@ async def test_ws_get_notifications(
|
|||
assert notification["notification_id"] == "Beer 2"
|
||||
assert notification["message"] == "test"
|
||||
assert notification["title"] is None
|
||||
assert notification["status"] == pn.STATUS_UNREAD
|
||||
assert notification["created_at"] is not None
|
||||
|
||||
# Mark Read
|
||||
await hass.services.async_call(
|
||||
pn.DOMAIN, "mark_read", {"notification_id": "Beer 2"}
|
||||
)
|
||||
await client.send_json({"id": 7, "type": "persistent_notification/get"})
|
||||
msg = await client.receive_json()
|
||||
notifications = msg["result"]
|
||||
assert len(notifications) == 1
|
||||
assert notifications[0]["status"] == pn.STATUS_READ
|
||||
|
||||
# Dismiss
|
||||
pn.async_dismiss(hass, "Beer 2")
|
||||
await client.send_json({"id": 8, "type": "persistent_notification/get"})
|
||||
|
@ -186,24 +141,8 @@ async def test_ws_get_subscribe(
|
|||
assert notification["notification_id"] == "Beer 2"
|
||||
assert notification["message"] == "test"
|
||||
assert notification["title"] is None
|
||||
assert notification["status"] == pn.STATUS_UNREAD
|
||||
assert notification["created_at"] is not None
|
||||
|
||||
# Mark Read
|
||||
await hass.services.async_call(
|
||||
pn.DOMAIN, "mark_read", {"notification_id": "Beer 2"}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert msg["id"] == 5
|
||||
assert msg["type"] == "event"
|
||||
assert msg["event"]
|
||||
event = msg["event"]
|
||||
assert event["type"] == "updated"
|
||||
notifications = event["notifications"]
|
||||
assert len(notifications) == 1
|
||||
notification = notifications[list(notifications)[0]]
|
||||
assert notification["status"] == pn.STATUS_READ
|
||||
|
||||
# Dismiss
|
||||
pn.async_dismiss(hass, "Beer 2")
|
||||
msg = await client.receive_json()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue