openhab-scripting 5.20.0 → 5.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04fb1ca1c7f49ca0f821111edd4c1d178066d6d0c55ce0d574efc7bf1307aa36
4
- data.tar.gz: aa5005277edc1667540d6c87aee158e5dcd02095ce6633303eacaa5343ecc1b1
3
+ metadata.gz: 756e126e160f646932df226702f4174537f335211766d9eba33c2d44cf1c1c70
4
+ data.tar.gz: 6afda8cddcc7a0fd916fe061a2eb2dab4621d46cdcef75138b4c524db05b669d
5
5
  SHA512:
6
- metadata.gz: e3c2c463868f6c9ec8f452bc8d1e0c0a5dc4c0f34243eceb4ad6661d9e52deafc04cddad3a4332c51fe039f246d0133b245f1c885b9e892f79e913f38f6c6619
7
- data.tar.gz: b6e03f118796c8af22d2a6922fba92368954ba3fd15c13029b6d627c5dc9cd5f1f27507f77990545176f8bd67af588e987b780393e76090f3c49b4a663351168
6
+ metadata.gz: c57f40667e47bacb3c2a2cc62f6fce829413cf832502e1f743cb82fbbc0e5a962800907b27261bea5513020612a8f7652378a7817aa6b0d924c88220ccca7328
7
+ data.tar.gz: 769878c8db809e0ed1815605551fc964de147329209e89517cab012a782b84e8a21e46fa445f3167723eea4f2454bd290a767991e39cfdb6495c742c874d295e
@@ -51,31 +51,85 @@ module OpenHAB
51
51
  module_function
52
52
 
53
53
  #
54
- # Send a notification.
54
+ # Send a notification using
55
+ # {https://next.openhab.org/addons/integrations/openhabcloud/#cloud-notification-actions
56
+ # openHAB Cloud Notification Action}.
55
57
  #
56
58
  # @param msg [String] The message to send.
57
- # @param email [String, nil] The email address to send to. If `nil`,
58
- # the message will be broadcast.
59
- # @param icon [String, Symbol, nil]
60
- # @param severity [String, Symbol, nil]
59
+ # @param email [String, nil] The email address to send to. If `nil`, the message will be broadcast.
60
+ # @param icon [String, Symbol, nil] The icon name
61
+ # (as described in {https://next.openhab.org/docs/configuration/items.html#icons Items}).
62
+ # @param severity [String, Symbol, nil] A description of the severity of the incident.
63
+ # @param title [String, nil] The title of the notification.
64
+ # When `nil`, it defaults to `openHAB` inside the Android and iOS apps.
65
+ # @param on_click [String, nil] The action to be performed when the user clicks on the notification.
66
+ # Specified using the {https://next.openhab.org/addons/integrations/openhabcloud/#action-syntax action syntax}.
67
+ # @param attachment [String, nil] The URL of the media attachment to be displayed with the notification.
68
+ # This URL must be reachable by the push notification client.
69
+ # @param buttons [Array<String>, Hash<String, String>, nil] Buttons to include in the notification.
70
+ # - In array form, each element is specified as `Title=$action`, where `$action` follows the
71
+ # {https://next.openhab.org/addons/integrations/openhabcloud/#action-syntax action syntax}.
72
+ # - In hash form, the keys are the button titles and the values are the actions.
73
+ #
74
+ # The maximum number of buttons is 3.
61
75
  # @return [void]
62
76
  #
77
+ # @note The parameters `title`, `on_click`, `attachment`, and `buttons` were added in openHAB 4.2.
78
+ #
79
+ # @see https://www.openhab.org/addons/integrations/openhabcloud/
80
+ #
63
81
  # @example Send a broadcast notification via openHAB Cloud
64
- # rule 'Send an alert' do
82
+ # rule "Send an alert" do
65
83
  # changed Alarm_Triggered, to: ON
66
- # run { notify 'Red Alert!' }
84
+ # run { notify "Red Alert!" }
85
+ # end
86
+ #
87
+ # @example Provide action buttons in a notification
88
+ # rule "Doorbell" do
89
+ # changed Doorbell, to: ON
90
+ # run do
91
+ # notify "Someone pressed the doorbell!",
92
+ # title: "Doorbell",
93
+ # attachment: "http://myserver.local/cameras/frontdoor.jpg",
94
+ # buttons: {
95
+ # "Show Camera" => "ui:/basicui/app?w=0001&sitemap=cameras",
96
+ # "Unlock Door" => "command:FrontDoor_Lock:OFF"
97
+ # }
98
+ # end
67
99
  # end
68
100
  #
69
- def notify(msg, email: nil, icon: nil, severity: nil)
101
+ def notify(
102
+ msg,
103
+ email: nil,
104
+ icon: nil,
105
+ severity: nil,
106
+ title: nil,
107
+ on_click: nil,
108
+ attachment: nil,
109
+ buttons: nil
110
+ )
70
111
  unless Actions.const_defined?(:NotificationAction)
71
112
  raise NotImplementedError, "NotificationAction is not available. Please install the openHAB Cloud addon."
72
113
  end
73
114
 
115
+ args = []
74
116
  if email
75
- NotificationAction.send_notification(email.to_s, msg.to_s, icon&.to_s, severity&.to_s)
117
+ args.push(:send_notification, email)
76
118
  else
77
- NotificationAction.send_broadcast_notification(msg.to_s, icon&.to_s, severity&.to_s)
119
+ args.push(:send_broadcast_notification)
78
120
  end
121
+ args.push(msg.to_s, icon&.to_s, severity&.to_s)
122
+
123
+ # @!deprecated OH 4.1
124
+ if Core.version >= Core::V4_2
125
+ buttons ||= []
126
+ buttons = buttons.map { |title, action| "#{title}=#{action}" } if buttons.is_a?(Hash)
127
+ raise ArgumentError, "buttons must contain (0..3) elements." unless (0..3).cover?(buttons.size)
128
+
129
+ args.push(title&.to_s, on_click&.to_s, attachment&.to_s, buttons[0]&.to_s, buttons[1]&.to_s, buttons[2]&.to_s)
130
+ end
131
+
132
+ NotificationAction.__send__(*args)
79
133
  end
80
134
  end
81
135
  end
@@ -56,8 +56,7 @@ module OpenHAB
56
56
  #
57
57
  # Coerce object to a StringType
58
58
  #
59
- # @param [String] other object to coerce to a
60
- # DateTimeType
59
+ # @param [String] other object to coerce to a StringType
61
60
  #
62
61
  # @return [[StringType, StringType], nil]
63
62
  #
@@ -92,6 +92,11 @@ class Time
92
92
  to_java(java.time.ZonedDateTime)
93
93
  end
94
94
 
95
+ # @return [java.time.Instant]
96
+ def to_instant
97
+ to_java(java.time.Instant)
98
+ end
99
+
95
100
  #
96
101
  # Converts to a {ZonedDateTime} if `other`
97
102
  # is also convertible to a ZonedDateTime.
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.20.0"
7
+ VERSION = "5.21.0"
8
8
  end
9
9
  end
@@ -5,10 +5,37 @@ module OpenHAB
5
5
  module Actions
6
6
  # redefine these to do nothing so that rules won't fail
7
7
 
8
- module_function
8
+ class NotificationAction
9
+ class << self
10
+ def send_notification(
11
+ email,
12
+ msg,
13
+ icon,
14
+ severity,
15
+ title = nil,
16
+ on_click = nil,
17
+ attachment = nil,
18
+ button1 = nil,
19
+ button2 = nil,
20
+ button3 = nil
21
+ )
22
+ logger.debug("send_notification: #{email}, #{msg}, #{icon}, #{severity}, #{title}, #{on_click}, #{attachment}, #{button1}, #{button2}, #{button3}") # rubocop:disable Layout/LineLength
23
+ end
9
24
 
10
- def notify(msg, email: nil)
11
- logger.debug("notify: #{msg}")
25
+ def send_broadcast_notification(
26
+ msg,
27
+ icon,
28
+ severity,
29
+ title = nil,
30
+ on_click = nil,
31
+ attachment = nil,
32
+ button1 = nil,
33
+ button2 = nil,
34
+ button3 = nil
35
+ )
36
+ logger.debug("send_broadcast_notification: #{msg}, #{icon}, #{severity}, #{title}, #{on_click}, #{attachment}, #{button1}, #{button2}, #{button3}") # rubocop:disable Layout/LineLength
37
+ end
38
+ end
12
39
  end
13
40
 
14
41
  class Voice
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.20.0
4
+ version: 5.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-06-27 00:00:00.000000000 Z
13
+ date: 2024-06-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler