diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index 9c09ccced3d..d38501b9b07 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -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() ]) diff --git a/tests/components/persistent_notification/test_init.py b/tests/components/persistent_notification/test_init.py index 5df106a5327..43b91e2622a 100644 --- a/tests/components/persistent_notification/test_init.py +++ b/tests/components/persistent_notification/test_init.py @@ -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, {