-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store notifications in component. Add ws endpoint for fetching. #16503
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. |
@@ -57,6 +75,12 @@ def dismiss(hass, notification_id): | |||
hass.add_job(async_dismiss, hass, notification_id) | |||
|
|||
|
|||
@bind_hass | |||
def mark_read(hass, notification_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not add this. I want to get rid of these functions.
"""Remove a notification.""" | ||
data = {ATTR_NOTIFICATION_ID: notification_id} | ||
|
||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_DISMISS, data)) | ||
|
||
|
||
@callback | ||
@bind_hass | ||
def async_mark_read(hass: HomeAssistant, notification_id: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not add this.
vol.Required('type'): WS_TYPE_GET_NOTIFICATIONS, | ||
}) | ||
|
||
PERSISTENT_NOTIFICATIONS = OrderedDict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All globals should be stored in hass.data
.
@callback | ||
def dismiss_service(call): | ||
"""Handle the dismiss notification service call.""" | ||
notification_id = call.data.get(ATTR_NOTIFICATION_ID) | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices: