openhab-scripting 4.41.0 → 4.42.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08c9201c21983751d80e9c2e4df683c39cef20763a5321fd2f8fdcd355cdb6c5'
|
4
|
+
data.tar.gz: f0b2c25837d2396e70d11ba503920ff443992bd9cf007b18a2003f6857a17929
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bff012a5dc7caf0e06fb9d0f3aede99afc9ad067004390ae606d392c34fe3662b017395fa3c200e759c2023e4801fb775ee097a29f0b90554f721d8fbbf9cf47
|
7
|
+
data.tar.gz: b862f6f69383d86e1a230d2c702c440c0b6dd465ed22ec16ad03a47166bd319004a8f82147eed2da514b301523f99c917c9d93de56f6ea7b9907ab5713f9d61d
|
@@ -37,7 +37,7 @@ module OpenHAB
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# if we're NULL or UNDEF, implement special logic
|
40
|
-
return nil_comparison unless state?
|
40
|
+
return nil_comparison(other) unless state?
|
41
41
|
|
42
42
|
# delegate to how the state compares to the other object
|
43
43
|
state <=> other
|
@@ -45,9 +45,10 @@ module OpenHAB
|
|
45
45
|
|
46
46
|
# Special logic for NULL/UNDEF state comparison
|
47
47
|
# @!visibility private
|
48
|
-
def nil_comparison
|
48
|
+
def nil_comparison(other)
|
49
49
|
# if comparing to nil, consider ourselves equal
|
50
50
|
return 0 if other.nil?
|
51
|
+
|
51
52
|
# if the other object is an Item, only consider equal if we're
|
52
53
|
# in the same _kind_ of UnDefType state
|
53
54
|
return raw_state == other.raw_state if other.is_a?(GenericItem) && !other.state?
|
@@ -6,10 +6,13 @@ module OpenHAB
|
|
6
6
|
#
|
7
7
|
# Persistence extension for Items
|
8
8
|
#
|
9
|
+
# @note Methods that accept a timestamp can accept a ++ZonedDateTime++, Ruby ++Time++, or a ++Duration++.
|
10
|
+
# When given a positive Duration, the timestamp will be calculated as ++now-Duration++
|
11
|
+
#
|
9
12
|
module Persistence
|
10
13
|
java_import Java::OrgOpenhabCoreTypesUtil::UnitUtils
|
11
14
|
|
12
|
-
# A
|
15
|
+
# A state class with an added timestamp attribute. This is used to hold OpenHAB's HistoricItem.
|
13
16
|
class HistoricState < SimpleDelegator
|
14
17
|
attr_reader :timestamp, :state
|
15
18
|
|
@@ -29,14 +32,169 @@ module OpenHAB
|
|
29
32
|
|
30
33
|
# All persistence methods that require a timestamp
|
31
34
|
PERSISTENCE_METHODS = (QUANTITY_METHODS +
|
32
|
-
%i[changed_since
|
35
|
+
%i[changed_since?
|
33
36
|
evolution_rate
|
34
37
|
historic_state
|
35
38
|
maximum_since
|
36
39
|
minimum_since
|
37
|
-
updated_since]).freeze
|
40
|
+
updated_since?]).freeze
|
38
41
|
private_constant :QUANTITY_METHODS, :PERSISTENCE_METHODS
|
39
42
|
|
43
|
+
# @!method persist(service = nil)
|
44
|
+
# Persist the state of the item
|
45
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
46
|
+
# @return [void]
|
47
|
+
|
48
|
+
# @!method last_update(service = nil)
|
49
|
+
# Return the time the item was last updated.
|
50
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
51
|
+
# @return [ZonedDateTime] The timestamp of the last update
|
52
|
+
|
53
|
+
# @!method average_since(timestamp, service = nil)
|
54
|
+
# Return the average value of the item's state since the given time
|
55
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
56
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
57
|
+
# @return [DecimalType, QuantityType, nil] The average value since ++timestamp++,
|
58
|
+
# or nil if no previous state could be found.
|
59
|
+
|
60
|
+
# @!method average_between(start, finish, service = nil)
|
61
|
+
# Return the average value of the item's state between two points in time
|
62
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
63
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
64
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
65
|
+
# @return [DecimalType, QuantityType, nil] The average value between ++start++ and ++finish++,
|
66
|
+
# or nil if no previous state could be found.
|
67
|
+
|
68
|
+
# @!method delta_since(timestamp, service = nil)
|
69
|
+
# Return the difference value of the item's state since the given time
|
70
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
71
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
72
|
+
# @return [DecimalType, QuantityType, nil] The difference value since ++timestamp++,
|
73
|
+
# or nil if no previous state could be found.
|
74
|
+
|
75
|
+
# @!method delta_between(start, finish, service = nil)
|
76
|
+
# Return the difference value of the item's state between two points in time
|
77
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
78
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
79
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
80
|
+
# @return [DecimalType, QuantityType, nil] The difference value between ++start++ and ++finish++,
|
81
|
+
# or nil if no previous state could be found.
|
82
|
+
|
83
|
+
# @!method deviation_since(timestamp, service = nil)
|
84
|
+
# Return the standard deviation of the item's state since the given time
|
85
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
86
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
87
|
+
# @return [DecimalType, QuantityType, nil] The standard deviation since ++timestamp++,
|
88
|
+
# or nil if no previous state could be found.
|
89
|
+
|
90
|
+
# @!method deviation_between(start, finish, service = nil)
|
91
|
+
# Return the standard deviation of the item's state between two points in time
|
92
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
93
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
94
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
95
|
+
# @return [DecimalType, QuantityType, nil] The standard deviation between ++start++ and ++finish++,
|
96
|
+
# or nil if no previous state could be found.
|
97
|
+
|
98
|
+
# @!method sum_since(timestamp, service = nil)
|
99
|
+
# Return the sum of the item's state since the given time
|
100
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
101
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
102
|
+
# @return [DecimalType, QuantityType, nil] The sum since ++timestamp++,
|
103
|
+
# or nil if no previous state could be found.
|
104
|
+
|
105
|
+
# @!method sum_between(start, finish, service = nil)
|
106
|
+
# Return the sum of the item's state between two points in time
|
107
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
108
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
109
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
110
|
+
# @return [DecimalType, QuantityType, nil] The sum between ++start++ and ++finish++,
|
111
|
+
# or nil if no previous state could be found.
|
112
|
+
|
113
|
+
# @!method variance_since(timestamp, service = nil)
|
114
|
+
# Return the variance of the item's state since the given time
|
115
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
116
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
117
|
+
# @return [DecimalType, QuantityType, nil] The variance since ++timestamp++,
|
118
|
+
# or nil if no previous state could be found.
|
119
|
+
|
120
|
+
# @!method variance_between(start, finish, service = nil)
|
121
|
+
# Return the variance of the item's state between two points in time
|
122
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
123
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
124
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
125
|
+
# @return [DecimalType, QuantityType, nil] The variance between ++start++ and ++finish++,
|
126
|
+
# or nil if no previous state could be found.
|
127
|
+
|
128
|
+
# @!method changed_since?(timestamp, service = nil)
|
129
|
+
# Whether the item's state has changed since the given time
|
130
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
131
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
132
|
+
# @return [Boolean] True if the item's state has changed since the given ++timestamp++, False otherwise.
|
133
|
+
|
134
|
+
# @!method changed_between?(start, finish, service = nil)
|
135
|
+
# Whether the item's state changed between two points in time
|
136
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
137
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
138
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
139
|
+
# @return [Boolean] True if the item's state changed between ++start++ and ++finish++, False otherwise.
|
140
|
+
|
141
|
+
# @!method evolution_rate(timestamp, service = nil)
|
142
|
+
# Return the evolution rate of the item's state since the given time
|
143
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
144
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
145
|
+
# @return [DecimalType, QuantityType, nil] The evolution rate since ++timestamp++,
|
146
|
+
# or nil if no previous state could be found.
|
147
|
+
|
148
|
+
# @!method historic_state(timestamp, service = nil)
|
149
|
+
# Return the the item's state at the given time
|
150
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time at which to search
|
151
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
152
|
+
# @return [HistoricState, nil] The item's state at ++timestamp++,
|
153
|
+
# or nil if no previous state could be found.
|
154
|
+
|
155
|
+
# @!method maximum_since(timestamp, service = nil)
|
156
|
+
# Return the maximum value of the item's state since the given time
|
157
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
158
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
159
|
+
# @return [HistoricState, nil] The maximum value since ++timestamp++,
|
160
|
+
# or nil if no previous state could be found.
|
161
|
+
|
162
|
+
# @!method maximum_between(start, finish, service = nil)
|
163
|
+
# Return the maximum value of the item's state between two points in time
|
164
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
165
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
166
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
167
|
+
# @return [HistoricState, nil] The maximum value between ++start++ and ++finish++,
|
168
|
+
# or nil if no previous state could be found.
|
169
|
+
|
170
|
+
# @!method minimum_since(timestamp, service = nil)
|
171
|
+
# Return the minimum value of the item's state since the given time
|
172
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
173
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
174
|
+
# @return [HistoricState, nil] The minimum value since ++timestamp++,
|
175
|
+
# or nil if no previous state could be found.
|
176
|
+
|
177
|
+
# @!method minimum_between(start, finish, service = nil)
|
178
|
+
# Return the minimum value of the item's state between two points in time
|
179
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
180
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
181
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
182
|
+
# @return [HistoricState, nil] The minimum value between ++start++ and ++finish++,
|
183
|
+
# or nil if no previous state could be found.
|
184
|
+
|
185
|
+
# @!method updated_since?(timestamp, service = nil)
|
186
|
+
# Whether the item's state has been updated since the given time
|
187
|
+
# @param [ZonedDateTime, Time, Duration] timestamp The point in time from which to search
|
188
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
189
|
+
# @return [Boolean] True if the item's state has been updated since the given ++timestamp++, False otherwise.
|
190
|
+
|
191
|
+
# @!method updated_between?(start, finish, service = nil)
|
192
|
+
# Whether the item's state was updated between two points in time
|
193
|
+
# @param [ZonedDateTime, Time, Duration] start The point in time from which to search
|
194
|
+
# @param [ZonedDateTime, Time, Duration] finish The point in time to which to search
|
195
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
196
|
+
# @return [Boolean] True if the item's state was updated between ++start++ and ++finish++, False otherwise.
|
197
|
+
|
40
198
|
%i[persist last_update].each do |method|
|
41
199
|
define_method(method) do |service = nil|
|
42
200
|
service ||= persistence_service
|
@@ -51,7 +209,7 @@ module OpenHAB
|
|
51
209
|
# searches the first state not equal the current state
|
52
210
|
# @param service [String] the name of the PersistenceService to use
|
53
211
|
#
|
54
|
-
# @return the previous state or nil if no previous state could be found,
|
212
|
+
# @return [HistoricState, nil] the previous state or nil if no previous state could be found,
|
55
213
|
# or if the default persistence service is not configured or
|
56
214
|
# does not refer to a valid service
|
57
215
|
#
|
@@ -64,15 +222,27 @@ module OpenHAB
|
|
64
222
|
PERSISTENCE_METHODS.each do |method|
|
65
223
|
define_method(method) do |timestamp, service = nil|
|
66
224
|
service ||= persistence_service
|
67
|
-
result = PersistenceExtensions.public_send(method, self, to_zdt(timestamp),
|
68
|
-
|
69
|
-
|
70
|
-
|
225
|
+
result = PersistenceExtensions.public_send(method.to_s.delete_suffix('?'), self, to_zdt(timestamp),
|
226
|
+
service&.to_s)
|
227
|
+
wrap_result(result, method)
|
228
|
+
end
|
229
|
+
|
230
|
+
next unless /_since\??$/.match?(method.to_s)
|
71
231
|
|
72
|
-
|
232
|
+
between_method = method.to_s.sub('_since', '_between').to_sym
|
233
|
+
define_method(between_method) do |start, finish, service = nil|
|
234
|
+
service ||= persistence_service
|
235
|
+
result = PersistenceExtensions.public_send(between_method.to_s.delete_suffix('?'), self, to_zdt(start),
|
236
|
+
to_zdt(finish), service&.to_s)
|
237
|
+
wrap_result(result, method)
|
73
238
|
end
|
74
239
|
end
|
75
240
|
|
241
|
+
alias changed_since changed_since?
|
242
|
+
alias changed_between changed_between?
|
243
|
+
alias updated_since updated_since?
|
244
|
+
alias updated_between updated_between?
|
245
|
+
|
76
246
|
private
|
77
247
|
|
78
248
|
#
|
@@ -103,6 +273,26 @@ module OpenHAB
|
|
103
273
|
end
|
104
274
|
end
|
105
275
|
|
276
|
+
#
|
277
|
+
# Wrap the result into a more convenient object type depending on the method and result.
|
278
|
+
#
|
279
|
+
# @param [Object] result the raw result type to be wrapped
|
280
|
+
# @param [Symbol] method the name of the called method
|
281
|
+
#
|
282
|
+
# @return [HistoricState] a {HistoricState} object if the result was a HistoricItem
|
283
|
+
# @return [QuantityType] a ++QuantityType++ object if the result was an average, delta, deviation,
|
284
|
+
# sum, or variance.
|
285
|
+
# @return [Object] the original result object otherwise.
|
286
|
+
#
|
287
|
+
def wrap_result(result, method)
|
288
|
+
java_import org.openhab.core.persistence.HistoricItem
|
289
|
+
|
290
|
+
return HistoricState.new(quantify(result.state), result.timestamp) if result.is_a?(HistoricItem)
|
291
|
+
return quantify(result) if QUANTITY_METHODS.include?(method)
|
292
|
+
|
293
|
+
result
|
294
|
+
end
|
295
|
+
|
106
296
|
#
|
107
297
|
# Get the specified persistence service from the current thread local variable
|
108
298
|
#
|
@@ -20,9 +20,6 @@ module OpenHAB
|
|
20
20
|
class Proc
|
21
21
|
include OpenHAB::Log
|
22
22
|
|
23
|
-
# Proc that doesn't check any fields
|
24
|
-
ANY = Proc.new.freeze
|
25
|
-
|
26
23
|
#
|
27
24
|
# Converts supplied ranges to procs that check range
|
28
25
|
# @param [Array] ranges objects to convert to range proc if they are ranges
|
@@ -83,6 +80,9 @@ module OpenHAB
|
|
83
80
|
@command = command
|
84
81
|
end
|
85
82
|
|
83
|
+
# Proc that doesn't check any fields
|
84
|
+
ANY = Proc.new.freeze # this needs to be defined _after_ initialize so its instance variables are set
|
85
|
+
|
86
86
|
#
|
87
87
|
# Process rule
|
88
88
|
# @param [Hash] inputs inputs from trigger
|
data/lib/openhab/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openhab-scripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.42.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian O'Connell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|