Add time created to persistent notifications. (#17121)
* Add time created to persistent notifications. * UTCpull/16935/head
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.entity import async_generate_entity_id
|
||||
from homeassistant.util import slugify
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
ATTR_CREATED_AT = 'created_at'
|
||||
ATTR_MESSAGE = 'message'
|
||||
ATTR_NOTIFICATION_ID = 'notification_id'
|
||||
ATTR_TITLE = 'title'
|
||||
|
@ -147,6 +149,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> Awaitable[bool]:
|
|||
ATTR_NOTIFICATION_ID: notification_id,
|
||||
ATTR_STATUS: STATUS_UNREAD,
|
||||
ATTR_TITLE: title,
|
||||
ATTR_CREATED_AT: dt_util.utcnow(),
|
||||
}
|
||||
|
||||
hass.bus.async_fire(EVENT_PERSISTENT_NOTIFICATIONS_UPDATED)
|
||||
|
@ -203,8 +206,9 @@ def websocket_get_notifications(
|
|||
connection.send_message(
|
||||
websocket_api.result_message(msg['id'], [
|
||||
{
|
||||
key: data[key] for key in (ATTR_NOTIFICATION_ID, ATTR_MESSAGE,
|
||||
ATTR_STATUS, ATTR_TITLE)
|
||||
key: data[key] for key in (ATTR_NOTIFICATION_ID,
|
||||
ATTR_MESSAGE, ATTR_STATUS,
|
||||
ATTR_TITLE, ATTR_CREATED_AT)
|
||||
}
|
||||
for data in hass.data[DOMAIN]['notifications'].values()
|
||||
])
|
||||
|
|
|
@ -41,6 +41,7 @@ class TestPersistentNotification:
|
|||
assert notification['status'] == pn.STATUS_UNREAD
|
||||
assert notification['message'] == 'Hello World 2'
|
||||
assert notification['title'] == '2 beers'
|
||||
assert notification['created_at'] is not None
|
||||
notifications.clear()
|
||||
|
||||
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['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, pn.SERVICE_MARK_READ, {
|
||||
|
|
Loading…
Reference in New Issue