Hello developers,
I have the following proposal for a notification infrastructure (excerpt from the bundle readme):
Notifications
This bundle defines multiple interfaces for the notification infrastructure.
Notifications are runtime events and are not stored / restored on startup.
They always have a maximum life-time and a priority level.
Most notifications are just streamed events, they appear once on each interested
notification consumer and are gone after the life-time is over or a user
has dismissed them.
Other notifications express an urgency, and need to be user dismissed and may
even re-appear after a time. For example a “short on storage” notification.
A notification consists of:
- a unique ID
- an integer priority level with certain values predefined,
- a maximum life-time before the notification is auto-dismissed,
- a list of scopes (a scope may be “binding”, “system:storage” etc),
- an urgent flag: If that is set, the notification need to be actively,
dismissed by the user and may even re-appear after a time, - a notification label
- a notification html message
- an optional image url
- optional rule action UIDs.
The general flow is that notification providers push notifications to a registry
and notification consumers are notified. The notification stays in the registry
until the maximum life-time has been reached or is dismissed by the user.
Notification consumers
A notification consumer listens to incoming notifications and expose those.
The user can restrict a consumer to specific notification scopes
(via regex patterns). So that only urgent system notifications
reach your mail-box for instance. A minimum notification priority can be configured.
An example for a consumer is the org.openhab.core.notification.rest bundle
which allows a web-user to list the last x notifications or get notifications
in real-time via websockets.
Another example is the org.openhab.core.notifications.gcm bundle which exposes
notifications via the google cloud messaging service, especially useful for
Android phones.
A consumer is not allowed to cache any notifications.
If a new session to a consumer is opened (a phone registered to the
google cloud messaging service or a REST call happens), all still valid
notifications from the registry are (re)exposed.
Notification provider
A provider adds new notifications to the notification registry.
It can overwrite existing notifications by using the same unique id.
Some notification scopes like “system” can only be set by system services.
An example for a notification provider is the
org.openhab.core.storage.notifications bundle which pushes urgent notifications
when the runtime state could not be synched to disk (low disk space, write errors).
Another example is the org.openhab.core.notification bundle which pushes
all “warning” and “error” log messages.
Notification registry
The registry accepts a few configuration parameters:
- A block list: A user can block certain notification scopes. Useful if a binding
is abusing notifications to call for attention. - a reappearance time value for urgent notifications that are not yet dismissed.
Would be interested in feedback and suggestions.
(I’m not interested in taking over the old PR, I’m happy with this proposal so far)
@wborn @maggu2810 @hilbrand @martinvw @kai
Cheers, David