Class: OpenHAB::Core::Actions::Notification
- Inherits:
-
Object
- Object
- OpenHAB::Core::Actions::Notification
- Defined in:
- lib/openhab/core/actions/notification.rb
Overview
Provides methods for openHAB Cloud Notification Actions.
Class Method Summary collapse
-
.hide(email: nil, id: nil, tag: nil) ⇒ void
Hide a notification by ID or tag.
-
.log(msg, icon: nil, tag: nil) ⇒ void
Sends a log notification.
-
.send(msg, email: nil, icon: nil, tag: nil, severity: nil, id: nil, title: nil, on_click: nil, attachment: nil, buttons: nil) ⇒ void
Send a notification using openHAB Cloud Notification Action.
Class Method Details
.hide(email: nil, id: nil, tag: nil) ⇒ void
This method returns an undefined value.
Hide a notification by ID or tag.
Either the ‘id` or `tag` parameter must be provided. When both are provided, two calls will be made to the NotificationAction:
-
Notifications matching the ‘id` will be hidden, and
-
Notifications matching the ‘tag` will be hidden, independently from the given tag.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/openhab/core/actions/notification.rb', line 128 def hide(email: nil, id: nil, tag: nil) unless Actions.const_defined?(:NotificationAction) raise NotImplementedError, "NotificationAction is not available. Please install the openHAB Cloud addon." end raise ArgumentError, "Either id or tag must be provided." unless id || tag args = [] if email args.push(email) notification = :notification else notification = :broadcast_notification end NotificationAction.__send__(:"hide_#{notification}_by_reference_id", *args, id) if id NotificationAction.__send__(:"hide_#{notification}_by_tag", *args, tag) if tag end |
.log(msg, icon: nil, tag: nil) ⇒ void
This method returns an undefined value.
Sends a log notification.
Log notifications do not trigger a notification on the device.
157 158 159 |
# File 'lib/openhab/core/actions/notification.rb', line 157 def log(msg, icon: nil, tag: nil) NotificationAction.send_log_notification(msg.to_s, icon&.to_s, tag&.to_s) end |
.send(msg, email: nil, icon: nil, tag: nil, severity: nil, id: nil, title: nil, on_click: nil, attachment: nil, buttons: nil) ⇒ void
The parameters ‘title`, `id`, `on_click`, `attachment`, and `buttons` were added in openHAB 4.2.
This method returns an undefined value.
Send a notification using openHAB Cloud Notification Action.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/openhab/core/actions/notification.rb', line 69 def send( msg, email: nil, icon: nil, tag: nil, severity: nil, id: nil, title: nil, on_click: nil, attachment: nil, buttons: nil ) unless Actions.const_defined?(:NotificationAction) raise NotImplementedError, "NotificationAction is not available. Please install the openHAB Cloud addon." end args = [] if email args.push(:send_notification, email) else args.push(:send_broadcast_notification) end tag ||= severity args.push(msg.to_s, icon&.to_s, tag&.to_s) # @deprecated OH 4.1 if Core.version >= Core::V4_2 ||= [] = .map { |title, action| "#{title}=#{action}" } if .is_a?(Hash) raise ArgumentError, "buttons must contain (0..3) elements." unless (0..3).cover?(.size) = "item:#{.name}" if .is_a?(Item) && .image_item? args.push(title&.to_s, id&.to_s, on_click&.to_s, &.to_s, [0]&.to_s, [1]&.to_s, [2]&.to_s) end NotificationAction.__send__(*args) end |