openhab-scripting 5.36.2 → 5.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dca6625d5d2a4ac13a8012df40e3d0a0ebdefced290c5cff076465c6f759757
4
- data.tar.gz: 25f336aa6c3cd7c7a0e47f5e237fd19ac73f6f1ea989ff18d911e2a66a22048b
3
+ metadata.gz: dcf7591d994378fb216137014e04dae3321ba891e11f201336e1afc6f1b7226b
4
+ data.tar.gz: d9917f8c8f5ead81623e39b3c606ab0f4efe7da519f654b081498bd743ebc721
5
5
  SHA512:
6
- metadata.gz: 2df6953fce517e82fda1fc8e3a5098c63af45333c1637639f6488597230d2634c18a666eb4bc3ae1302abb0d19fdd64eb9c256b7bb263b6f7d6852b9bead6600
7
- data.tar.gz: bfb62aca10a6a2b3bff00adf94f39d1b30f806fc55cc34f503102d6c2c349ad938c1a8f5c71f17d60164eaeb810141f38ca0120a5357feec9f69af7aa71866e2
6
+ metadata.gz: 78aa38c7c90b81ead46d438543077abb55bf06db1476f6e73cf36577f4df10c3b305e5169de2df2580f7d1d963fd8e5a998521764d9377305f87717ff216fff5
7
+ data.tar.gz: 9a410509dc518a5019c3885d5123c8a1840a0a70c6abb99df85cdbc11897eb7d5367d6014c71ff16759baebe03083a409f8f254606f0fab22a51ef50f2cdcdc6
@@ -13,6 +13,14 @@ module OpenHAB
13
13
  class ItemStateChangedEvent < ItemEvent
14
14
  include ItemState
15
15
 
16
+ # @!attribute [r] last_state_update
17
+ # @return [ZonedDateTime] the time the previous state update occurred
18
+ # @since openHAB 5.0
19
+
20
+ # @!attribute [r] last_state_change
21
+ # @return [ZonedDateTime] the time the previous state change occurred
22
+ # @since openHAB 5.0
23
+
16
24
  # @!method was_undef?
17
25
  # Check if {#was} is {UNDEF}
18
26
  # @return [true, false]
@@ -74,6 +82,9 @@ module OpenHAB
74
82
  def inspect
75
83
  s = "#<OpenHAB::Core::Events::ItemStateChangedEvent item=#{item_name} " \
76
84
  "state=#{item_state.inspect} was=#{old_item_state.inspect}"
85
+ # @deprecated OH4.3 remove respond_to? checks in the next two lines when dropping OH 4.3
86
+ s += " last_state_update=#{last_state_update}" if respond_to?(:last_state_update) && last_state_update
87
+ s += " last_state_change=#{last_state_change}" if respond_to?(:last_state_change) && last_state_change
77
88
  s += " source=#{source.inspect}" if source
78
89
  "#{s}>"
79
90
  end
@@ -14,6 +14,19 @@ module OpenHAB
14
14
  #
15
15
  class ItemStateUpdatedEvent < ItemEvent
16
16
  include ItemState
17
+
18
+ # @!attribute [r] last_state_update
19
+ # @return [ZonedDateTime] the time the previous state update occurred
20
+ # @since openHAB 5.0
21
+
22
+ # @return [String]
23
+ def inspect
24
+ s = "#<OpenHAB::Core::Events::ItemStateUpdatedEvent item=#{item_name} state=#{item_state.inspect}"
25
+ # @deprecated OH4.3 remove respond_to? check when dropping OH 4.3
26
+ s += " last_state_update=#{last_state_update}" if respond_to?(:last_state_update) && last_state_update
27
+ s += " source=#{source.inspect}" if source
28
+ "#{s}>"
29
+ end
17
30
  end
18
31
  end
19
32
  end
@@ -13,6 +13,10 @@ module OpenHAB
13
13
  # @!attribute [r] state
14
14
  # @return [StringListType, nil]
15
15
  #
16
+ # @!attribute [r] was
17
+ # @return [StringListType, nil]
18
+ # @since openHAB 5.0
19
+ #
16
20
  class CallItem < GenericItem
17
21
  # @!visibility private
18
22
  def format_type(command)
@@ -35,6 +35,10 @@ module OpenHAB
35
35
  # @!attribute [r] state
36
36
  # @return [HSBType, nil]
37
37
  #
38
+ # @!attribute [r] was
39
+ # @return [HSBType, nil]
40
+ # @since openHAB 5.0
41
+ #
38
42
  class ColorItem < DimmerItem
39
43
  # Make sure to do the String => HSBType conversion in Ruby,
40
44
  # where we add support for hex
@@ -8,7 +8,7 @@ module OpenHAB
8
8
  java_import org.openhab.core.library.items.ContactItem
9
9
 
10
10
  #
11
- # A {ContactItem} can be used for sensors that return an "open" or
11
+ # A {ContactItem} can be used for sensors that return an "open" or
12
12
  # "closed" as a state.
13
13
  #
14
14
  # This is useful for doors, windows, etc.
@@ -16,6 +16,10 @@ module OpenHAB
16
16
  # @!attribute [r] state
17
17
  # @return [OpenClosedType, nil]
18
18
  #
19
+ # @!attribute [r] was
20
+ # @return [OpenClosedType, nil]
21
+ # @since openHAB 5.0
22
+ #
19
23
  # @example
20
24
  # rule 'Log state of all doors on system startup' do
21
25
  # on_load
@@ -30,20 +34,29 @@ module OpenHAB
30
34
  # end
31
35
  # end
32
36
  #
37
+ # @!method open?
38
+ # Check if the item state == {OPEN}
39
+ # @return [true,false]
40
+ #
41
+ # @example Log open contacts
42
+ # Contacts.select(&:open?).each { |contact| logger.info("Contact #{contact.name} is open")}
43
+ #
44
+ # @!method closed?
45
+ # Check if the item state == {CLOSED}
46
+ # @return [true,false]
47
+ #
48
+ # @example Log closed contacts
49
+ # Contacts.select(&:closed?).each { |contact| logger.info("Contact #{contact.name} is closed")}
50
+ #
51
+ # @!method was_open?
52
+ # Check if {#was} is {OPEN}
53
+ # @return [true, false]
54
+ #
55
+ # @!method was_closed?
56
+ # Check if {#was} is {CLOSED}
57
+ # @return [true, false]
58
+ #
33
59
  class ContactItem < GenericItem
34
- # @!method open?
35
- # Check if the item state == {OPEN}
36
- # @return [true,false]
37
- #
38
- # @example Log open contacts
39
- # Contacts.select(&:open?).each { |contact| logger.info("Contact #{contact.name} is open")}
40
-
41
- # @!method closed?
42
- # Check if the item state == {CLOSED}
43
- # @return [true,false]
44
- #
45
- # @example Log closed contacts
46
- # Contacts.select(&:closed?).each { |contact| logger.info("Contact #{contact.name} is closed")}
47
60
  end
48
61
  end
49
62
  end
@@ -13,6 +13,10 @@ module OpenHAB
13
13
  # @!attribute [r] state
14
14
  # @return [DateTimeType, nil]
15
15
  #
16
+ # @!attribute [r] was
17
+ # @return [DateTimeType, nil]
18
+ # @since openHAB 5.0
19
+ #
16
20
  # @example DateTime items can be updated and commanded with Ruby Time objects or Java ZonedDateTime objects
17
21
  # Example_DateTimeItem << Time.now
18
22
  # Example_DateTimeItem << ZonedDateTime.now
@@ -15,6 +15,10 @@ module OpenHAB
15
15
  # @!attribute [r] state
16
16
  # @return [PercentType, nil]
17
17
  #
18
+ # @!attribute [r] was
19
+ # @return [PercentType, nil]
20
+ # @since openHAB 5.0
21
+ #
18
22
  # @example
19
23
  # DimmerOne << DimmerOne.state - 5
20
24
  # DimmerOne << 100 - DimmerOne.state
@@ -79,10 +79,45 @@ module OpenHAB
79
79
  # [Ruby safe navigation operator `&.`](https://docs.ruby-lang.org/en/master/syntax/calling_methods_rdoc.html#label-Safe+Navigation+Operator)
80
80
  # Use {#undef?} or {#null?} to check for those states.
81
81
  #
82
+ # @see was
83
+ #
82
84
  def state
83
85
  raw_state if state?
84
86
  end
85
87
 
88
+ # @!method was_undef?
89
+ # Check if {#was} is {UNDEF}
90
+ # @return [true, false]
91
+
92
+ # @!method was_null?
93
+ # Check if {#was} is {NULL}
94
+ # @return [true, false]
95
+
96
+ #
97
+ # Check if the item's previous state was not `nil`, {UNDEF} or {NULL}
98
+ #
99
+ # @return [true, false]
100
+ #
101
+ # @since openHAB 5.0
102
+ #
103
+ def was?
104
+ !last_state.nil? && !last_state.is_a?(Types::UnDefType)
105
+ end
106
+
107
+ #
108
+ # @!attribute [r] was
109
+ #
110
+ # @return [State] The previous state of the item. nil if the item was never updated, or
111
+ # if the item was updated to {NULL} or {UNDEF}.
112
+ # @since openHAB 5.0
113
+ #
114
+ # @see state
115
+ # @see Item#last_state
116
+ #
117
+ def was
118
+ last_state if was?
119
+ end
120
+
86
121
  # @!method null?
87
122
  # Check if the item state == {NULL}
88
123
  # @return [true,false]
@@ -18,7 +18,11 @@ module OpenHAB
18
18
  # @!attribute [r] state
19
19
  # @return [RawType, nil]
20
20
  #
21
- # @example Update from a base 64 encode image string
21
+ # @!attribute [r] was
22
+ # @return [RawType, nil]
23
+ # @since openHAB 5.0
24
+ #
25
+ # @example Update from a base 64 encoded image string
22
26
  # Image.update("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=")
23
27
  #
24
28
  # @example Update from image bytes and mime type
@@ -70,6 +70,18 @@ module OpenHAB
70
70
  # @!attribute [r] command_description
71
71
  # @return [Types::CommandDescription, nil]
72
72
 
73
+ # @!attribute [r] last_state
74
+ # @return [State] The previous state of the item.
75
+ # @since openHAB 5.0
76
+
77
+ # @!attribute [r] last_state_change
78
+ # @return [ZonedDateTime] The time of the last state change.
79
+ # @since openHAB 5.0
80
+
81
+ # @!attribute [r] last_state_update
82
+ # @return [ZonedDateTime] The time of the last state update.
83
+ # @since openHAB 5.0
84
+
73
85
  #
74
86
  # The item's {GenericItem#label label} if one is defined, otherwise its {#name}.
75
87
  #
@@ -550,6 +562,12 @@ module OpenHAB
550
562
  # @return [String]
551
563
  def inspect
552
564
  s = "#<OpenHAB::Core::Items::#{type}Item#{type_details} #{name} #{label.inspect} state=#{raw_state.inspect}"
565
+ # @deprecated OH 4.3 Remove if guard when dropping support for OH 4.3
566
+ if respond_to?(:last_state)
567
+ s += " last_state=#{last_state.inspect}" if last_state
568
+ s += " last_state_update=#{last_state_update}" if last_state_update
569
+ s += " last_state_change=#{last_state_change}" if last_state_change
570
+ end
553
571
  s += " category=#{category.inspect}" if category
554
572
  s += " tags=#{tags.to_a.inspect}" unless tags.empty?
555
573
  s += " groups=#{group_names}" unless group_names.empty?
@@ -16,6 +16,10 @@ module OpenHAB
16
16
  # @!attribute [r] state
17
17
  # @return [PointType, nil]
18
18
  #
19
+ # @!attribute [r] was
20
+ # @return [PointType, nil]
21
+ # @since openHAB 5.0
22
+ #
19
23
  # @example Send point commands
20
24
  # Location << '30,20' # latitude of 30, longitude of 20
21
25
  # Location << '30,20,80' # latitude of 30, longitude of 20, altitude of 80
@@ -25,6 +25,9 @@ module OpenHAB
25
25
  # @return [javax.measure.Unit, nil]
26
26
  # @!attribute [r] state
27
27
  # @return [DecimalType, QuantityType, nil]
28
+ # @!attribute [r] was
29
+ # @return [DecimalType, QuantityType, nil]
30
+ # @since openHAB 5.0
28
31
  #
29
32
  # @example Number Items can be selected in an enumerable with grep.
30
33
  # # Get all NumberItems
@@ -111,28 +111,37 @@ module OpenHAB
111
111
  # @deprecated Use {PersistedState} instead
112
112
  HistoricState = PersistedState
113
113
 
114
- # @!method average_since(timestamp, service = nil)
114
+ # @!method average_since(timestamp, service = nil, riemann_type: nil)
115
115
  # Returns the average value of the item's state since the given time
116
116
  # @param [#to_zoned_date_time] timestamp The point in time from which to search
117
117
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
118
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
119
+ # If nil, :left is used.
118
120
  # @return [DecimalType, QuantityType, nil] The average value since `timestamp`,
119
121
  # or nil if no previous states could be found.
122
+ # @since openHAB 5.0 riemann_type parameter added
120
123
 
121
- # @!method average_until(timestamp, service = nil)
124
+ # @!method average_until(timestamp, service = nil, riemann_type: nil)
122
125
  # Returns the average value of the item's state between now until the given time
123
126
  # @param [#to_zoned_date_time] timestamp The point in time until which to search
124
127
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
128
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
129
+ # If nil, :left is used.
125
130
  # @return [DecimalType, QuantityType, nil] The average value until `timestamp`,
126
131
  # or nil if no future states could be found.
127
132
  # @since openHAB 4.2
133
+ # @since openHAB 5.0 riemann_type parameter added
128
134
 
129
- # @!method average_between(start, finish, service = nil)
135
+ # @!method average_between(start, finish, service = nil, riemann_type: nil)
130
136
  # Returns the average value of the item's state between two points in time
131
137
  # @param [#to_zoned_date_time] start The point in time from which to search
132
138
  # @param [#to_zoned_date_time] finish The point in time to which to search
133
139
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
140
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
141
+ # If nil, :left is used.
134
142
  # @return [DecimalType, QuantityType, nil] The average value between `start` and `finish`,
135
143
  # or nil if no states could be found.
144
+ # @since openHAB 5.0 riemann_type parameter added
136
145
 
137
146
  # @!method delta_since(timestamp, service = nil)
138
147
  # Returns the difference value of the item's state since the given time
@@ -157,28 +166,37 @@ module OpenHAB
157
166
  # @return [DecimalType, QuantityType, nil] The difference value between `start` and `finish`,
158
167
  # or nil if no states could be found.
159
168
 
160
- # @!method deviation_since(timestamp, service = nil)
169
+ # @!method deviation_since(timestamp, service = nil, riemann_type: nil)
161
170
  # Returns the standard deviation of the item's state since the given time
162
171
  # @param [#to_zoned_date_time] timestamp The point in time from which to search
163
172
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
173
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
174
+ # If nil, :left is used.
164
175
  # @return [DecimalType, QuantityType, nil] The standard deviation since `timestamp`,
165
176
  # or nil if no previous states could be found.
177
+ # @since openHAB 5.0 riemann_type parameter added
166
178
 
167
- # @!method deviation_until(timestamp, service = nil)
179
+ # @!method deviation_until(timestamp, service = nil, riemann_type: nil)
168
180
  # Returns the standard deviation of the item's state beetween now until the given time
169
181
  # @param [#to_zoned_date_time] timestamp The point in time until which to search
170
182
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
183
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
184
+ # If nil, :left is used.
171
185
  # @return [DecimalType, QuantityType, nil] The standard deviation until `timestamp`,
172
186
  # or nil if no future states could be found.
173
187
  # @since openHAB 4.2
188
+ # @since openHAB 5.0 riemann_type parameter added
174
189
 
175
- # @!method deviation_between(start, finish, service = nil)
190
+ # @!method deviation_between(start, finish, service = nil, riemann_type: nil)
176
191
  # Returns the standard deviation of the item's state between two points in time
177
192
  # @param [#to_zoned_date_time] start The point in time from which to search
178
193
  # @param [#to_zoned_date_time] finish The point in time to which to search
179
194
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
195
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
196
+ # If nil, :left is used.
180
197
  # @return [DecimalType, QuantityType, nil] The standard deviation between `start` and `finish`,
181
198
  # or nil if no states could be found.
199
+ # @since openHAB 5.0 riemann_type parameter added
182
200
 
183
201
  # @!method median_since(timestamp, service = nil)
184
202
  # Returns the median of the item's state since the given time
@@ -228,28 +246,37 @@ module OpenHAB
228
246
  # @return [DecimalType, QuantityType, nil] The sum between `start` and `finish`,
229
247
  # or nil if no states could be found.
230
248
 
231
- # @!method variance_since(timestamp, service = nil)
249
+ # @!method variance_since(timestamp, service = nil, riemann_type: nil)
232
250
  # Returns the variance of the item's state since the given time
233
251
  # @param [#to_zoned_date_time] timestamp The point in time from which to search
234
252
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
253
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
254
+ # If nil, :left is used.
235
255
  # @return [DecimalType, QuantityType, nil] The variance since `timestamp`,
236
256
  # or nil if no previous states could be found.
257
+ # @since openHAB 5.0 riemann_type parameter added
237
258
 
238
- # @!method variance_until(timestamp, service = nil)
259
+ # @!method variance_until(timestamp, service = nil, riemann_type: nil)
239
260
  # Returns the variance of the item's state between now until the given time
240
261
  # @param [#to_zoned_date_time] timestamp The point in time until which to search
241
262
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
263
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
264
+ # If nil, :left is used.
242
265
  # @return [DecimalType, QuantityType, nil] The variance until `timestamp`,
243
266
  # or nil if no future states could be found.
244
267
  # @since openHAB 4.2
268
+ # @since openHAB 5.0 riemann_type parameter added
245
269
 
246
- # @!method variance_between(start, finish, service = nil)
270
+ # @!method variance_between(start, finish, service = nil, riemann_type: nil)
247
271
  # Returns the variance of the item's state between two points in time
248
272
  # @param [#to_zoned_date_time] start The point in time from which to search
249
273
  # @param [#to_zoned_date_time] finish The point in time to which to search
250
274
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
275
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
276
+ # If nil, :left is used.
251
277
  # @return [DecimalType, QuantityType, nil] The variance between `start` and `finish`,
252
278
  # or nil if no states could be found.
279
+ # @since openHAB 5.0 riemann_type parameter added
253
280
 
254
281
  # @!method changed_since?(timestamp, service = nil)
255
282
  # Whether the item's state has changed since the given time
@@ -461,6 +488,37 @@ module OpenHAB
461
488
  # @return [Array<PersistedState>] An array of {PersistedState} persisted for this item.
462
489
  # @since openHAB 4.0
463
490
 
491
+ # @!method riemann_sum_since(timestamp, service = nil, riemann_type: nil)
492
+ # Returns the Riemann sum of the states since a certain point in time.
493
+ # @param [#to_zoned_date_time] timestamp The point in time from which to search
494
+ # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
495
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
496
+ # If nil, :left is used.
497
+ # @return [DecimalType, QuantityType, nil] The riemann sum since `timestamp`,
498
+ # or nil if no previous states could be found.
499
+ # @since openHAB 5.0
500
+
501
+ # @!method riemann_sum_until(timestamp, service = nil, riemann_type: nil)
502
+ # Returns the Riemann sum of the states between now until a certain point in time.
503
+ # @param [#to_zoned_date_time] timestamp The point in time until which to search
504
+ # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
505
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
506
+ # If nil, :left is used.
507
+ # @return [DecimalType, QuantityType, nil] The riemann sum until `timestamp`,
508
+ # or nil if no previous states could be found.
509
+ # @since openHAB 5.0
510
+
511
+ # @!method riemann_sum_between(start, finish, service = nil, riemann_type: nil)
512
+ # Returns the Riemann sum of the states between two points in time.
513
+ # @param [#to_zoned_date_time] start The point in time from which to search
514
+ # @param [#to_zoned_date_time] finish The point in time to which to search
515
+ # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
516
+ # @param [:left, :midpoint, :right, :trapezoidal] riemann_type An optional approximation type for Riemann sum.
517
+ # If nil, :left is used.
518
+ # @return [DecimalType, QuantityType, nil] The riemann sum between `start` and `finish`,
519
+ # or nil if no previous states could be found.
520
+ # @since openHAB 5.0
521
+
464
522
  # @!method remove_all_states_since(timestamp, service = nil)
465
523
  # Removes persisted data points since a certain point in time.
466
524
  # @param [#to_zoned_date_time] timestamp The point in time from which to remove
@@ -565,6 +623,7 @@ module OpenHAB
565
623
  # Returns the time the item was last updated.
566
624
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
567
625
  # @return [ZonedDateTime, nil] The timestamp of the last update
626
+ # @see Item#last_state_update
568
627
 
569
628
  # @!method next_update(service = nil)
570
629
  # Returns the first future update time of the item.
@@ -578,6 +637,7 @@ module OpenHAB
578
637
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
579
638
  # @return [ZonedDateTime, nil] The timestamp of the last update
580
639
  # @since openHAB 4.2
640
+ # @see Item#last_state_change
581
641
 
582
642
  # @!method next_change(service = nil)
583
643
  # Returns the first future change time of the item.
@@ -612,6 +672,8 @@ module OpenHAB
612
672
  # @return [PersistedState, nil] the previous state or nil if no previous state could be found,
613
673
  # or if the default persistence service is not configured or
614
674
  # does not refer to a valid service
675
+ #
676
+ # @see Item#last_state
615
677
 
616
678
  # @!method next_state(service = nil, skip_equal: false)
617
679
  # Return the next state of the item
@@ -645,76 +707,103 @@ module OpenHAB
645
707
 
646
708
  class << self
647
709
  # @!visibility private
648
- def def_persistence_method(method, quantify: false)
710
+ def def_persistence_method(method, quantify: false, riemann_param: nil)
649
711
  method = method.to_s.dup
650
712
  suffix = method.delete_suffix!("?") && "?"
713
+ riemann_arg = nil
714
+
715
+ if riemann_param
716
+ riemann_param = ", riemann_type: nil"
717
+ # @deprecated OH4.3 remove if guard when dropping OH 4.3
718
+ if Actions::PersistenceExtensions.const_defined?(:RiemannType)
719
+ riemann_arg = "to_riemann_type(riemann_type),"
720
+ end
721
+ end
651
722
 
652
723
  class_eval <<~RUBY, __FILE__, __LINE__ + 1
653
- def #{method}#{suffix}(timestamp, service = nil) # def changed_since?(timestamp, service = nil)
654
- service ||= persistence_service # service ||= persistence_service
655
- result = Actions::PersistenceExtensions.#{method}( # result = Actions::PersistenceExtensions.changed_since(
656
- self, # self,
657
- timestamp.to_zoned_date_time, # timestamp.to_zoned_date_time,
658
- service&.to_s # service&.to_s
659
- ) # )
660
- wrap_result(result, quantify: #{quantify}) # wrap_result(result, quantify: false)
661
- end # end
724
+ def #{method}#{suffix}(timestamp, service = nil#{riemann_param}) # def changed_since?(timestamp, service = nil, riemann_type: nil)
725
+ service ||= persistence_service # service ||= persistence_service
726
+ result = Actions::PersistenceExtensions.#{method}( # result = Actions::PersistenceExtensions.average_since(
727
+ self, # self,
728
+ timestamp.to_zoned_date_time, # timestamp.to_zoned_date_time,
729
+ #{riemann_arg} # to_riemann_type(riemann_type),
730
+ service&.to_s # service&.to_s
731
+ ) # )
732
+ wrap_result(result, quantify: #{quantify}) # wrap_result(result, quantify: false)
733
+ end # end
662
734
  RUBY
663
735
  end
664
736
 
665
737
  # @!visibility private
666
- def def_persistence_methods(method, quantify: false)
738
+ def def_persistence_methods(method, quantify: false, riemann_param: nil)
667
739
  method = method.to_s.dup
668
740
  suffix = method.delete_suffix!("?") && "?"
741
+ riemann_arg = nil
669
742
 
670
- def_persistence_method("#{method}_since#{suffix}", quantify:)
743
+ def_persistence_method("#{method}_since#{suffix}", quantify:, riemann_param:)
671
744
  # @deprecated OH 4.1 remove if guard, keeping the content, when dropping OH 4.1
672
745
  if OpenHAB::Core.version >= OpenHAB::Core::V4_2
673
- def_persistence_method("#{method}_until#{suffix}", quantify:)
746
+ def_persistence_method("#{method}_until#{suffix}", quantify:, riemann_param:)
747
+ end
748
+
749
+ if riemann_param
750
+ riemann_param = ", riemann_type: nil"
751
+ # @deprecated OH4.3 remove if guard when dropping OH 4.3
752
+ if Actions::PersistenceExtensions.const_defined?(:RiemannType)
753
+ riemann_arg = "to_riemann_type(riemann_type),"
754
+ end
674
755
  end
675
756
 
676
757
  method = "#{method}_between"
677
758
  class_eval <<~RUBY, __FILE__, __LINE__ + 1
678
- def #{method}#{suffix}(start, finish, service = nil) # def changed_between?(start, finish, service = nil)
679
- service ||= persistence_service # service ||= persistence_service
680
- result = Actions::PersistenceExtensions.#{method}( # result = Actions::PersistenceExtensions.changed_between?(
681
- self, # self,
682
- start.to_zoned_date_time, # start.to_zoned_date_time,
683
- finish.to_zoned_date_time, # finish.to_zoned_date_time,
684
- service&.to_s # service&.to_s
685
- ) # )
686
- wrap_result(result, quantify: #{quantify}) # wrap_result(result, quantify: false)
687
- end # end
759
+ def #{method}#{suffix}(start, finish, service = nil#{riemann_param}) # def changed_between?(start, finish, service = nil, riemann_type: nil)
760
+ service ||= persistence_service # service ||= persistence_service
761
+ result = Actions::PersistenceExtensions.#{method}( # result = Actions::PersistenceExtensions.average_between(
762
+ self, # self,
763
+ start.to_zoned_date_time, # start.to_zoned_date_time,
764
+ finish.to_zoned_date_time, # finish.to_zoned_date_time,
765
+ #{riemann_arg} # to_riemann_type(riemann_type),
766
+ service&.to_s # service&.to_s
767
+ ) # )
768
+ wrap_result(result, quantify: #{quantify}) # wrap_result(result, quantify: false)
769
+ end # end
688
770
  RUBY
689
771
  end
690
772
  end
691
773
 
692
- def_persistence_methods(:average, quantify: true)
693
- def_persistence_methods(:median, quantify: true) if OpenHAB::Core.version >= OpenHAB::Core::V4_3
694
- def_persistence_methods(:delta, quantify: true)
695
- def_persistence_methods(:deviation, quantify: true)
696
- def_persistence_methods(:sum, quantify: true)
697
- def_persistence_methods(:variance, quantify: true)
698
-
774
+ # arranged in alphabetical order
775
+ def_persistence_methods(:average, quantify: true, riemann_param: true)
699
776
  def_persistence_methods(:changed?)
700
777
  def_persistence_methods(:count)
778
+
701
779
  def_persistence_methods(:count_state_changes)
702
780
  alias_method :state_changes_since, :count_state_changes_since
703
781
  alias_method :state_changes_until, :count_state_changes_until if OpenHAB::Core.version >= OpenHAB::Core::V4_2
704
782
  alias_method :state_changes_between, :count_state_changes_between
705
783
 
784
+ def_persistence_methods(:delta, quantify: true)
785
+ def_persistence_methods(:deviation, quantify: true, riemann_param: true)
786
+
706
787
  # @deprecated OH 4.2 - this still exists in OH 4.2 but logs a deprecation warning
707
788
  def_persistence_method(:historic_state, quantify: true)
708
789
 
709
- def_persistence_methods(:maximum, quantify: true)
710
- def_persistence_methods(:minimum, quantify: true)
711
- def_persistence_methods(:updated?)
712
-
713
790
  def_persistence_methods(:get_all_states, quantify: true)
714
791
  alias_method :all_states_since, :get_all_states_since
715
792
  alias_method :all_states_until, :get_all_states_until if OpenHAB::Core.version >= OpenHAB::Core::V4_2
716
793
  alias_method :all_states_between, :get_all_states_between
717
794
 
795
+ def_persistence_methods(:maximum, quantify: true)
796
+ def_persistence_methods(:minimum, quantify: true)
797
+ def_persistence_methods(:median, quantify: true) if OpenHAB::Core.version >= OpenHAB::Core::V4_3
798
+ # @deprecated OH4.3 remove if guard when dropping OH 4.3
799
+ if Actions::PersistenceExtensions.const_defined?(:RiemannType)
800
+ # riemann_sum methods were added in OH 5.0 which already quantifies the result in core
801
+ def_persistence_methods(:riemann_sum, riemann_param: true)
802
+ end
803
+ def_persistence_methods(:sum, quantify: true)
804
+ def_persistence_methods(:updated?)
805
+ def_persistence_methods(:variance, quantify: true, riemann_param: true)
806
+
718
807
  if OpenHAB::Core.version >= OpenHAB::Core::V4_2
719
808
  def_persistence_method(:persisted_state) # already quantified in core
720
809
 
@@ -805,6 +894,15 @@ module OpenHAB
805
894
  def persistence_service
806
895
  Thread.current[:openhab_persistence_service]
807
896
  end
897
+
898
+ #
899
+ # Convert a symbol to a RiemannType enum value
900
+ # @param [Symbol] sym the symbol to convert
901
+ # @return [RiemannType] the RiemannType enum value, or nil if sym is nil
902
+ #
903
+ def to_riemann_type(sym)
904
+ Actions::PersistenceExtensions::RiemannType.value_of(sym.to_s.upcase) if sym
905
+ end
808
906
  end
809
907
  end
810
908
  end