Store notifications in component. Add ws endpoint for fetching.#16503
Store notifications in component. Add ws endpoint for fetching.#16503balloob merged 2 commits intohome-assistant:devfrom
Conversation
|
Persistent Notification shall aware user context, it may no be in this pull request although. |
|
I'm not sure what you mean by aware user context. They are created through service calls now so that context should be captured. Do you mean notifications will be created for a specific user and only shown to that user? |
|
I think we should have two (or three) type of notifications
|
|
Ah yes 👍 these are all good ideas. I think once Lovelace is default and we move notifications out of the state machine we can add more of this type of functionality. |
|
|
||
|
|
||
| @bind_hass | ||
| def mark_read(hass, notification_id): |
There was a problem hiding this comment.
Let's not add this. I want to get rid of these functions.
|
|
||
| @callback | ||
| @bind_hass | ||
| def async_mark_read(hass: HomeAssistant, notification_id: str) -> None: |
| vol.Required('type'): WS_TYPE_GET_NOTIFICATIONS, | ||
| }) | ||
|
|
||
| PERSISTENT_NOTIFICATIONS = OrderedDict() |
There was a problem hiding this comment.
All globals should be stored in hass.data.
| entity_id = ENTITY_ID_FORMAT.format(slugify(notification_id)) | ||
|
|
||
| if entity_id not in PERSISTENT_NOTIFICATIONS: | ||
| _LOGGER.error('Dismissing persistent_notification failed: ' |
There was a problem hiding this comment.
I think that it's fine to silently return. The goal is to dismiss a certain notification_id, which has been achieved.
| def websocket_get_notifications( | ||
| hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg): | ||
| """Return a list of persistent_notifications.""" | ||
| connection.send_message_outside( |
There was a problem hiding this comment.
Don't use send_message_outside. You are inside the callback that has to generate the response. Use connection.to_write.put_nowait
Description:
Depends on home-assistant/frontend#1649
This is initial MVP for component storage of persistent notifications. Eventually they will be removed from the state machine, but this leaves them there for now so it is not a breaking change.
Related issue (if applicable): fixes #15071
Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: