openhab-scripting 4.39.1 → 4.42.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 +4 -4
- data/lib/openhab/dsl/items/comparable_item.rb +22 -10
- data/lib/openhab/dsl/items/generic_item.rb +27 -3
- data/lib/openhab/dsl/items/item_equality.rb +24 -1
- data/lib/openhab/dsl/items/persistence.rb +199 -9
- data/lib/openhab/dsl/items/semantics.rb +5 -5
- data/lib/openhab/dsl/types/point_type.rb +1 -1
- data/lib/openhab/dsl/types/type.rb +3 -3
- data/lib/openhab/log/logger.rb +6 -4
- data/lib/openhab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62974273127c66d888a44c8871b287dd6cfc90485ad04e9d461b407d19474eb1
|
4
|
+
data.tar.gz: d9540eeb7d3df3df1075ff8c79a4bc8eef1ca9e6920860bce2c5a3c64a2931b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26fbfcddca4f673fbaf1a2399bb126c06715dfbe966ae1c0a77259bdc5b1debafbbdb9b9103c81d0c8bc31311118b44517504e749611cb0c80cc4ddea1e69e23
|
7
|
+
data.tar.gz: 80e903ea1be4ce311c3f5093fa678bd38a22ddc5e97ac24245faaa5ad14cd5cd383b3e82f9cce11da6d7e062608ce5181a8eed3005f5aab09982f0a78f5eb944
|
@@ -9,9 +9,12 @@ module OpenHAB
|
|
9
9
|
#
|
10
10
|
# Comparison
|
11
11
|
#
|
12
|
-
# @param [GenericItem, Types::Type, Object] other object to
|
12
|
+
# @param [GenericItem, Types::Type, Object, GenericItemObject] other object to
|
13
13
|
# compare to
|
14
14
|
#
|
15
|
+
# When comparing GenericItemObject on either side, perform object comparison
|
16
|
+
# return 0 if the object is equal, or nil otherwise.
|
17
|
+
#
|
15
18
|
# If this item is +NULL+ or +UNDEF+, and +other+ is nil, they are
|
16
19
|
# considered equal
|
17
20
|
#
|
@@ -28,21 +31,30 @@ module OpenHAB
|
|
28
31
|
#
|
29
32
|
def <=>(other)
|
30
33
|
logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
|
31
|
-
# if we're NULL or UNDEF, implement special logic
|
32
|
-
unless state?
|
33
|
-
# if comparing to nil, consider ourselves equal
|
34
|
-
return 0 if other.nil?
|
35
|
-
# if the other object is an Item, only consider equal if we're
|
36
|
-
# in the same _kind_ of UnDefType state
|
37
|
-
return raw_state == other.raw_state if other.is_a?(GenericItem) && !other.state?
|
38
34
|
|
39
|
-
|
40
|
-
return nil
|
35
|
+
if is_a?(OpenHAB::DSL::GenericItemObject) || other.is_a?(OpenHAB::DSL::GenericItemObject)
|
36
|
+
return eql?(other) ? 0 : nil
|
41
37
|
end
|
42
38
|
|
39
|
+
# if we're NULL or UNDEF, implement special logic
|
40
|
+
return nil_comparison unless state?
|
41
|
+
|
43
42
|
# delegate to how the state compares to the other object
|
44
43
|
state <=> other
|
45
44
|
end
|
45
|
+
|
46
|
+
# Special logic for NULL/UNDEF state comparison
|
47
|
+
# @!visibility private
|
48
|
+
def nil_comparison
|
49
|
+
# if comparing to nil, consider ourselves equal
|
50
|
+
return 0 if other.nil?
|
51
|
+
# if the other object is an Item, only consider equal if we're
|
52
|
+
# in the same _kind_ of UnDefType state
|
53
|
+
return raw_state == other.raw_state if other.is_a?(GenericItem) && !other.state?
|
54
|
+
|
55
|
+
# otherwise, it's a non-nil thing comparing to nil, which is undefined
|
56
|
+
nil
|
57
|
+
end
|
46
58
|
end
|
47
59
|
end
|
48
60
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
|
3
|
+
require 'delegate'
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
require_relative 'metadata'
|
7
|
+
require_relative 'persistence'
|
8
|
+
require_relative 'semantics'
|
6
9
|
|
7
10
|
require_relative 'item_equality'
|
8
11
|
|
@@ -170,6 +173,17 @@ module OpenHAB
|
|
170
173
|
other.instance_of?(self.class) && hash == other.hash
|
171
174
|
end
|
172
175
|
|
176
|
+
#
|
177
|
+
# A method to indicate that item comparison is requested instead of state comparison
|
178
|
+
#
|
179
|
+
# Example: Item1.item == items['Item1'].item should return true
|
180
|
+
#
|
181
|
+
# See ItemEquality#==
|
182
|
+
#
|
183
|
+
def item
|
184
|
+
@item ||= GenericItemObject.new(self)
|
185
|
+
end
|
186
|
+
|
173
187
|
# @!method null?
|
174
188
|
# Check if the item state == +NULL+
|
175
189
|
# @return [Boolean]
|
@@ -201,5 +215,15 @@ module OpenHAB
|
|
201
215
|
end
|
202
216
|
end
|
203
217
|
end
|
218
|
+
|
219
|
+
# A helper class to flag that item comparison is wanted instead of state comparison
|
220
|
+
# It is used by ItemEquality#===
|
221
|
+
class GenericItemObject < SimpleDelegator
|
222
|
+
extend Forwardable
|
223
|
+
include Log
|
224
|
+
include OpenHAB::DSL::Items::ItemEquality
|
225
|
+
|
226
|
+
def_delegator :__getobj__, :instance_of? # instance_of? is used by GenericItem#eql? to check for item equality
|
227
|
+
end
|
204
228
|
end
|
205
229
|
end
|
@@ -22,7 +22,8 @@ module OpenHAB
|
|
22
22
|
# @return [Boolean]
|
23
23
|
#
|
24
24
|
def ==(other)
|
25
|
-
logger.trace
|
25
|
+
logger.trace { "ItemEquality#== (#{self.class}) #{self} == #{other} (#{other.class})" }
|
26
|
+
return eql?(other) if generic_item_object?(other)
|
26
27
|
return true if equal?(other) || eql?(other)
|
27
28
|
return true if !state? && other.nil?
|
28
29
|
|
@@ -30,6 +31,28 @@ module OpenHAB
|
|
30
31
|
|
31
32
|
state == other
|
32
33
|
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Check item object equality for grep
|
37
|
+
#
|
38
|
+
def ===(other)
|
39
|
+
logger.trace { "ItemEquality#=== (#{self.class}) #{self} == #{other} (#{other.class})" }
|
40
|
+
eql?(other)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
#
|
46
|
+
# Determines if an object equality check is required, based on whether
|
47
|
+
# either operand is a GenericItemObject
|
48
|
+
#
|
49
|
+
# @param [Object] other
|
50
|
+
#
|
51
|
+
# @return [Boolean]
|
52
|
+
#
|
53
|
+
def generic_item_object?(other)
|
54
|
+
other.is_a?(OpenHAB::DSL::GenericItemObject) || is_a?(OpenHAB::DSL::GenericItemObject)
|
55
|
+
end
|
33
56
|
end
|
34
57
|
end
|
35
58
|
end
|
@@ -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
|
#
|
@@ -62,17 +220,29 @@ module OpenHAB
|
|
62
220
|
end
|
63
221
|
|
64
222
|
PERSISTENCE_METHODS.each do |method|
|
223
|
+
public_method = method.to_s.delete_suffix('?') # For some reason, the boolean methods with '?' are missing
|
65
224
|
define_method(method) do |timestamp, service = nil|
|
66
225
|
service ||= persistence_service
|
67
|
-
result = PersistenceExtensions.public_send(
|
68
|
-
|
69
|
-
|
70
|
-
|
226
|
+
result = PersistenceExtensions.public_send(public_method, self, to_zdt(timestamp), 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(public_method, self, to_zdt(start), to_zdt(finish),
|
236
|
+
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
|
#
|
@@ -73,8 +73,7 @@ module OpenHAB
|
|
73
73
|
|
74
74
|
# Gets the related Location Item of this Item.
|
75
75
|
#
|
76
|
-
#
|
77
|
-
# groups one level at a time, returning the first Location Item found.
|
76
|
+
# Checks ancestor groups one level at a time, returning the first Location Item found.
|
78
77
|
#
|
79
78
|
# @return [GenericItem, nil]
|
80
79
|
def location
|
@@ -92,8 +91,7 @@ module OpenHAB
|
|
92
91
|
|
93
92
|
# Gets the related Equipment Item of this Item.
|
94
93
|
#
|
95
|
-
#
|
96
|
-
# groups one level at a time, returning the first Equipment Item found.
|
94
|
+
# Checks ancestor groups one level at a time, returning the first Equipment Item found.
|
97
95
|
#
|
98
96
|
# @return [GenericItem, nil]
|
99
97
|
def equipment
|
@@ -173,7 +171,7 @@ end
|
|
173
171
|
# Additions to Enumerable to allow easily filtering groups of items based on the semantic model
|
174
172
|
module Enumerable
|
175
173
|
# Returns a new array of items that are a semantics Location (optionally of the given type)
|
176
|
-
def
|
174
|
+
def locations(type = nil)
|
177
175
|
if type && !(type < OpenHAB::DSL::Items::Semantics::Location)
|
178
176
|
raise ArgumentError, 'type must be a subclass of Location'
|
179
177
|
end
|
@@ -183,6 +181,8 @@ module Enumerable
|
|
183
181
|
|
184
182
|
result
|
185
183
|
end
|
184
|
+
# @deprecated Please use {#locations}
|
185
|
+
alias sublocations locations
|
186
186
|
|
187
187
|
# Returns a new array of items that are a semantics equipment (optionally of the given type)
|
188
188
|
#
|
@@ -57,7 +57,7 @@ module OpenHAB
|
|
57
57
|
# @return [Boolean]
|
58
58
|
#
|
59
59
|
def ==(other) # rubocop:disable Metrics
|
60
|
-
logger.trace
|
60
|
+
logger.trace { "(#{self.class}) #{self} == #{other} (#{other.class})" }
|
61
61
|
if other.is_a?(Items::LocationItem) ||
|
62
62
|
(other.is_a?(Items::GroupItem) && other.base_item.is_a?(LocationItem))
|
63
63
|
return false unless other.state?
|
@@ -48,8 +48,8 @@ module OpenHAB
|
|
48
48
|
# or item state of the same type
|
49
49
|
#
|
50
50
|
def ===(other)
|
51
|
-
logger.trace
|
52
|
-
other = other.state if other.respond_to?(:state)
|
51
|
+
logger.trace { "Type (#{self.class}) #{self} === #{other} (#{other.class})" }
|
52
|
+
other = other.state if other.respond_to?(:state) && !other.is_a?(OpenHAB::DSL::GenericItemObject)
|
53
53
|
return false unless instance_of?(other.class)
|
54
54
|
|
55
55
|
eql?(other)
|
@@ -62,7 +62,7 @@ module OpenHAB
|
|
62
62
|
# type conversions
|
63
63
|
#
|
64
64
|
def ==(other) # rubocop:disable Metrics
|
65
|
-
logger.trace
|
65
|
+
logger.trace { "(#{self.class}) #{self} == #{other} (#{other.class})" }
|
66
66
|
return true if equal?(other)
|
67
67
|
|
68
68
|
# i.e. ON == OFF, REFRESH == ON, ON == REFRESH
|
data/lib/openhab/log/logger.rb
CHANGED
@@ -54,7 +54,9 @@ module OpenHAB
|
|
54
54
|
define_method(level) do |msg = nil, &block|
|
55
55
|
log(severity: level, msg: msg, &block)
|
56
56
|
end
|
57
|
-
define_method("#{level}
|
57
|
+
define_method("#{level}?") { @sl4fj_logger.send("is_#{level}_enabled") }
|
58
|
+
# @deprecated
|
59
|
+
alias_method "#{level}_enabled?", "#{level}?"
|
58
60
|
end
|
59
61
|
|
60
62
|
#
|
@@ -62,7 +64,7 @@ module OpenHAB
|
|
62
64
|
# @param [String] preamble to put at start of log message
|
63
65
|
# @param [Hash] kwargs key and values to log
|
64
66
|
def state(preamble = 'State:', **kwargs)
|
65
|
-
return unless
|
67
|
+
return unless trace?
|
66
68
|
|
67
69
|
states = kwargs.transform_keys(&:to_s)
|
68
70
|
.transform_keys(&:capitalize)
|
@@ -82,7 +84,7 @@ module OpenHAB
|
|
82
84
|
# @return [Exception] the exception, potentially with a cleaned backtrace.
|
83
85
|
#
|
84
86
|
def clean_backtrace(error)
|
85
|
-
return error if
|
87
|
+
return error if debug?
|
86
88
|
|
87
89
|
if error.respond_to? :backtrace_locations
|
88
90
|
backtrace = error.backtrace_locations.map(&:to_s).grep_v(INTERNAL_CALL_REGEX)
|
@@ -122,7 +124,7 @@ module OpenHAB
|
|
122
124
|
raise ArgumentError, "Unknown Severity #{severity}" unless LEVELS.include? severity
|
123
125
|
|
124
126
|
# Dynamically check enablement of underlying logger, this expands to "is_<level>_enabled"
|
125
|
-
return unless send("#{severity}
|
127
|
+
return unless send("#{severity}?")
|
126
128
|
|
127
129
|
# Process block if no message provided
|
128
130
|
msg = yield if msg.nil? && block_given?
|
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.0
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|