mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add time created to persistent notifications. (#17121)
* Add time created to persistent notifications. * UTC
This commit is contained in:
parent
05d8c57212
commit
cc1891ef2b
@ -17,7 +17,9 @@ from homeassistant.loader import bind_hass
|
|||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.entity import async_generate_entity_id
|
from homeassistant.helpers.entity import async_generate_entity_id
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
ATTR_CREATED_AT = 'created_at'
|
||||||
ATTR_MESSAGE = 'message'
|
ATTR_MESSAGE = 'message'
|
||||||
ATTR_NOTIFICATION_ID = 'notification_id'
|
ATTR_NOTIFICATION_ID = 'notification_id'
|
||||||
ATTR_TITLE = 'title'
|
ATTR_TITLE = 'title'
|
||||||
@ -147,6 +149,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> Awaitable[bool]:
|
|||||||
ATTR_NOTIFICATION_ID: notification_id,
|
ATTR_NOTIFICATION_ID: notification_id,
|
||||||
ATTR_STATUS: STATUS_UNREAD,
|
ATTR_STATUS: STATUS_UNREAD,
|
||||||
ATTR_TITLE: title,
|
ATTR_TITLE: title,
|
||||||
|
ATTR_CREATED_AT: dt_util.utcnow(),
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_PERSISTENT_NOTIFICATIONS_UPDATED)
|
hass.bus.async_fire(EVENT_PERSISTENT_NOTIFICATIONS_UPDATED)
|
||||||
@ -203,8 +206,9 @@ def websocket_get_notifications(
|
|||||||
connection.send_message(
|
connection.send_message(
|
||||||
websocket_api.result_message(msg['id'], [
|
websocket_api.result_message(msg['id'], [
|
||||||
{
|
{
|
||||||
key: data[key] for key in (ATTR_NOTIFICATION_ID, ATTR_MESSAGE,
|
key: data[key] for key in (ATTR_NOTIFICATION_ID,
|
||||||
ATTR_STATUS, ATTR_TITLE)
|
ATTR_MESSAGE, ATTR_STATUS,
|
||||||
|
ATTR_TITLE, ATTR_CREATED_AT)
|
||||||
}
|
}
|
||||||
for data in hass.data[DOMAIN]['notifications'].values()
|
for data in hass.data[DOMAIN]['notifications'].values()
|
||||||
])
|
])
|
||||||
|
@ -41,6 +41,7 @@ class TestPersistentNotification:
|
|||||||
assert notification['status'] == pn.STATUS_UNREAD
|
assert notification['status'] == pn.STATUS_UNREAD
|
||||||
assert notification['message'] == 'Hello World 2'
|
assert notification['message'] == 'Hello World 2'
|
||||||
assert notification['title'] == '2 beers'
|
assert notification['title'] == '2 beers'
|
||||||
|
assert notification['created_at'] is not None
|
||||||
notifications.clear()
|
notifications.clear()
|
||||||
|
|
||||||
def test_create_notification_id(self):
|
def test_create_notification_id(self):
|
||||||
@ -174,6 +175,7 @@ async def test_ws_get_notifications(hass, hass_ws_client):
|
|||||||
assert notification['message'] == 'test'
|
assert notification['message'] == 'test'
|
||||||
assert notification['title'] is None
|
assert notification['title'] is None
|
||||||
assert notification['status'] == pn.STATUS_UNREAD
|
assert notification['status'] == pn.STATUS_UNREAD
|
||||||
|
assert notification['created_at'] is not None
|
||||||
|
|
||||||
# Mark Read
|
# Mark Read
|
||||||
await hass.services.async_call(pn.DOMAIN, pn.SERVICE_MARK_READ, {
|
await hass.services.async_call(pn.DOMAIN, pn.SERVICE_MARK_READ, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user