openhab-scripting 4.39.0 → 4.41.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: 1fb1294914e9c3e343bef8f0c1aaca327dbaa5875d446ec3e507edc1f390c9c9
4
- data.tar.gz: be121541f849f733505c6180557f88fdd98869d89e0a593c6fc48db0e7e6daf5
3
+ metadata.gz: 101fdd6964b1dd5eaefcf5ecaf528ecc01ca12c280440da11ce8646d10fbd67c
4
+ data.tar.gz: 40bf18765cc29aee28d9ae486cd7c965435f5cbcf8f47867559bb72ccec7f3d9
5
5
  SHA512:
6
- metadata.gz: e6af3e7152dd02c9d98dea19f9bcaa4f474a20daac090941c1121705d177afec2498a2704462645d51b6e4e055efda1f0431702c0f7c6f126718b7994ef6baad
7
- data.tar.gz: f9af8246710e44dc86719d10ba2577003293640e1c11885c054da9d23d0be8746e1103151c173672ddfab96ae218f5d717318ab72d628a194f7a243647ea885d
6
+ metadata.gz: 8a8ce171ac466b46f28e5a5abc59cc2de62a20d16210e58fb7ea33b6ee5a6ad0b9399afb40491142d52396cbbee33b5be444f4d5530176b9ac34764f06a4ec5b
7
+ data.tar.gz: 57171fa39cfc71afaa8d8cb7488e184ea031cf6f8b01a135410a97317399e8a478d6cf9691ba81168d023882c488b07de5f47a921e516a05589bd198731da8b8
@@ -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
- # otherwise, it's a non-nil thing comparing to nil, which is undefined
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 'openhab/dsl/items/metadata'
4
- require 'openhab/dsl/items/persistence'
5
- require 'openhab/dsl/items/semantics'
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
@@ -44,6 +44,7 @@ module OpenHAB
44
44
 
45
45
  include Enumerable
46
46
  include ComparableItem
47
+ prepend Semantics # make Semantics#points take precedence over Enumerable#points for GroupItem
47
48
 
48
49
  remove_method :==
49
50
 
@@ -22,7 +22,8 @@ module OpenHAB
22
22
  # @return [Boolean]
23
23
  #
24
24
  def ==(other)
25
- logger.trace("(#{self.class}) #{self} == #{other} (#{other.class})")
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
@@ -4,168 +4,165 @@ require_relative 'semantics/enumerable'
4
4
 
5
5
  module OpenHAB
6
6
  module DSL
7
- # Module for implementing semantics helper methods on [GenericItem]
8
- #
9
- # Wraps https://www.openhab.org/javadoc/latest/org/openhab/core/model/script/actions/semantics,
10
- # as well as adding a few additional convenience methods.
11
- # Also includes Classes for each semantic tag.
12
- #
13
- # Be warned that the Semantic model is stricter than can actually be
14
- # described by tags and groups on an Item. It makes assumptions that any
15
- # given item only belongs to one semantic type (Location, Equipment, Point).
16
- #
17
- # See https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.semantics/model/SemanticTags.csv
18
- module Semantics
19
- # @!visibility private
20
- # import the actual semantics action
21
- SemanticsAction = org.openhab.core.model.script.actions.Semantics
22
- private_constant :SemanticsAction
23
-
24
- # import all the semantics constants
25
- [org.openhab.core.semantics.model.point.Points,
26
- org.openhab.core.semantics.model.property.Properties,
27
- org.openhab.core.semantics.model.equipment.Equipments,
28
- org.openhab.core.semantics.model.location.Locations].each do |parent_tag|
29
- parent_tag.stream.for_each do |tag|
30
- const_set(tag.simple_name.to_sym, tag.ruby_class)
7
+ module Items
8
+ # Module for implementing semantics helper methods on [GenericItem]
9
+ #
10
+ # Wraps https://www.openhab.org/javadoc/latest/org/openhab/core/model/script/actions/semantics,
11
+ # as well as adding a few additional convenience methods.
12
+ # Also includes Classes for each semantic tag.
13
+ #
14
+ # Be warned that the Semantic model is stricter than can actually be
15
+ # described by tags and groups on an Item. It makes assumptions that any
16
+ # given item only belongs to one semantic type (Location, Equipment, Point).
17
+ #
18
+ # See https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.semantics/model/SemanticTags.csv
19
+ module Semantics
20
+ # @!visibility private
21
+ # import the actual semantics action
22
+ SemanticsAction = org.openhab.core.model.script.actions.Semantics
23
+ private_constant :SemanticsAction
24
+
25
+ # import all the semantics constants
26
+ [org.openhab.core.semantics.model.point.Points,
27
+ org.openhab.core.semantics.model.property.Properties,
28
+ org.openhab.core.semantics.model.equipment.Equipments,
29
+ org.openhab.core.semantics.model.location.Locations].each do |parent_tag|
30
+ parent_tag.stream.for_each do |tag|
31
+ const_set(tag.simple_name.to_sym, tag.ruby_class)
32
+ end
31
33
  end
32
- end
33
-
34
- # put ourself into the global namespace, replacing the action
35
- ::Semantics = self # rubocop:disable Naming/ConstantName
36
34
 
37
- # Checks if this Item is a Location
38
- #
39
- # This is implemented as checking if the item's semantic_type
40
- # is a Location. I.e. an Item has a single semantic_type.
41
- #
42
- # @return [true, false]
43
- def location?
44
- SemanticsAction.location?(self)
45
- end
35
+ # put ourself into the global namespace, replacing the action
36
+ ::Semantics = self # rubocop:disable Naming/ConstantName
37
+
38
+ # Checks if this Item is a Location
39
+ #
40
+ # This is implemented as checking if the item's semantic_type
41
+ # is a Location. I.e. an Item has a single semantic_type.
42
+ #
43
+ # @return [true, false]
44
+ def location?
45
+ SemanticsAction.location?(self)
46
+ end
46
47
 
47
- # Checks if this Item is an Equipment
48
- #
49
- # This is implemented as checking if the item's semantic_type
50
- # is an Equipment. I.e. an Item has a single semantic_type.
51
- #
52
- # @return [true, false]
53
- def equipment?
54
- SemanticsAction.equipment?(self)
55
- end
48
+ # Checks if this Item is an Equipment
49
+ #
50
+ # This is implemented as checking if the item's semantic_type
51
+ # is an Equipment. I.e. an Item has a single semantic_type.
52
+ #
53
+ # @return [true, false]
54
+ def equipment?
55
+ SemanticsAction.equipment?(self)
56
+ end
56
57
 
57
- # Checks if this Item is a Point
58
- #
59
- # This is implemented as checking if the item's semantic_type
60
- # is a Point. I.e. an Item has a single semantic_type.
61
- #
62
- # @return [true, false]
63
- def point?
64
- SemanticsAction.point?(self)
65
- end
58
+ # Checks if this Item is a Point
59
+ #
60
+ # This is implemented as checking if the item's semantic_type
61
+ # is a Point. I.e. an Item has a single semantic_type.
62
+ #
63
+ # @return [true, false]
64
+ def point?
65
+ SemanticsAction.point?(self)
66
+ end
66
67
 
67
- # Checks if this Item has any semantic tags
68
- # @return [true, false]
69
- def semantic?
70
- !!semantic_type
71
- end
68
+ # Checks if this Item has any semantic tags
69
+ # @return [true, false]
70
+ def semantic?
71
+ !!semantic_type
72
+ end
72
73
 
73
- # Gets the related Location Item of this Item.
74
- #
75
- # Returns +self+ if this Item is a Location. Otherwise, checks ancestor
76
- # groups one level at a time, returning the first Location Item found.
77
- #
78
- # @return [GenericItem, nil]
79
- def location
80
- SemanticsAction.get_location(self)
81
- end
74
+ # Gets the related Location Item of this Item.
75
+ #
76
+ # Checks ancestor groups one level at a time, returning the first Location Item found.
77
+ #
78
+ # @return [GenericItem, nil]
79
+ def location
80
+ SemanticsAction.get_location(self)
81
+ end
82
82
 
83
- # Returns the sub-class of [Location] related to this Item.
84
- #
85
- # In other words, the semantic_type of this Item's Location.
86
- #
87
- # @return [Class]
88
- def location_type
89
- SemanticsAction.get_location_type(self)&.ruby_class
90
- end
83
+ # Returns the sub-class of [Location] related to this Item.
84
+ #
85
+ # In other words, the semantic_type of this Item's Location.
86
+ #
87
+ # @return [Class]
88
+ def location_type
89
+ SemanticsAction.get_location_type(self)&.ruby_class
90
+ end
91
91
 
92
- # Gets the related Equipment Item of this Item.
93
- #
94
- # Returns +self+ if this Item is an Equipment. Otherwise, checks ancestor
95
- # groups one level at a time, returning the first Equipment Item found.
96
- #
97
- # @return [GenericItem, nil]
98
- def equipment
99
- SemanticsAction.get_equipment(self)
100
- end
92
+ # Gets the related Equipment Item of this Item.
93
+ #
94
+ # Checks ancestor groups one level at a time, returning the first Equipment Item found.
95
+ #
96
+ # @return [GenericItem, nil]
97
+ def equipment
98
+ SemanticsAction.get_equipment(self)
99
+ end
101
100
 
102
- # Returns the sub-class of [Equipment] related to this Item.
103
- #
104
- # In other words, the semantic_type of this Item's Equipment.
105
- #
106
- # @return [Class]
107
- def equipment_type
108
- SemanticsAction.get_equipment_type(self)&.ruby_class
109
- end
101
+ # Returns the sub-class of [Equipment] related to this Item.
102
+ #
103
+ # In other words, the semantic_type of this Item's Equipment.
104
+ #
105
+ # @return [Class]
106
+ def equipment_type
107
+ SemanticsAction.get_equipment_type(self)&.ruby_class
108
+ end
110
109
 
111
- # Returns the sub-class of [Point] this Item is tagged with.
112
- #
113
- # @return [Class]
114
- def point_type
115
- SemanticsAction.get_point_type(self)&.ruby_class
116
- end
110
+ # Returns the sub-class of [Point] this Item is tagged with.
111
+ #
112
+ # @return [Class]
113
+ def point_type
114
+ SemanticsAction.get_point_type(self)&.ruby_class
115
+ end
117
116
 
118
- # Returns the sub-class of [Property] this Item is tagged with.
119
- # @return [Class]
120
- def property_type
121
- SemanticsAction.get_property_type(self)&.ruby_class
122
- end
117
+ # Returns the sub-class of [Property] this Item is tagged with.
118
+ # @return [Class]
119
+ def property_type
120
+ SemanticsAction.get_property_type(self)&.ruby_class
121
+ end
123
122
 
124
- # Returns the sub-class of [Tag] this Item is tagged with.
125
- #
126
- # It will only return the first applicable Tag, preferring
127
- # a sub-class of [Location], [Equipment], or [Point] first,
128
- # and if none of those are found, looks for a [Property].
129
- # @return [Class]
130
- def semantic_type
131
- SemanticsAction.get_semantic_type(self)&.ruby_class
132
- end
123
+ # Returns the sub-class of [Tag] this Item is tagged with.
124
+ #
125
+ # It will only return the first applicable Tag, preferring
126
+ # a sub-class of [Location], [Equipment], or [Point] first,
127
+ # and if none of those are found, looks for a [Property].
128
+ # @return [Class]
129
+ def semantic_type
130
+ SemanticsAction.get_semantic_type(self)&.ruby_class
131
+ end
133
132
 
134
- # Return the related Point Items.
135
- #
136
- # Searches this Equipment Item for Points that are tagged appropriately.
137
- #
138
- # If called on a Point Item, it will automatically search for sibling Points
139
- # (and remove itself if found).
140
- #
141
- # @example Get all points for a TV
142
- # eGreatTV.points
143
- # @example Search an Equipment item for its switch
144
- # eGuestFan.points(Semantics::Switch) # => [GuestFan_Dimmer]
145
- # @example Search a Thermostat item for its current temperature item
146
- # eFamilyThermostat.points(Semantics::Status, Semantics::Temperature)
147
- # # => [FamilyThermostat_AmbTemp]
148
- # @example Search a Thermostat item for is setpoints
149
- # eFamilyThermostat.points(Semantics::Control, Semantics::Temperature)
150
- # # => [FamilyThermostat_HeatingSetpoint, FamilyThermostat_CoolingSetpoint]
151
- # @example Given a A/V receiver's input item, search for its power item
152
- # FamilyReceiver_Input.points(Semantics::Switch) # => [FamilyReceiver_Switch]
153
- #
154
- # @param [Class] point_or_property_types
155
- # Pass 1 or 2 classes that are sub-classes of [Point] or [Property].
156
- # Note that when comparing against semantic tags, it does a sub-class check.
157
- # So if you search for [Control], you'll get items tagged with [Switch].
158
- # @return [Array<GenericItem>]
159
- def points(*point_or_property_types)
160
- # automatically search the parent equipment (or location?!) for sibling points
161
- unless equipment? || location?
133
+ # Return the related Point Items.
134
+ #
135
+ # Searches this Equipment Item for Points that are tagged appropriately.
136
+ #
137
+ # If called on a Point Item, it will automatically search for sibling Points
138
+ # (and remove itself if found).
139
+ #
140
+ # @example Get all points for a TV
141
+ # eGreatTV.points
142
+ # @example Search an Equipment item for its switch
143
+ # eGuestFan.points(Semantics::Switch) # => [GuestFan_Dimmer]
144
+ # @example Search a Thermostat item for its current temperature item
145
+ # eFamilyThermostat.points(Semantics::Status, Semantics::Temperature)
146
+ # # => [FamilyThermostat_AmbTemp]
147
+ # @example Search a Thermostat item for is setpoints
148
+ # eFamilyThermostat.points(Semantics::Control, Semantics::Temperature)
149
+ # # => [FamilyThermostat_HeatingSetpoint, FamilyThermostat_CoolingSetpoint]
150
+ # @example Given a A/V receiver's input item, search for its power item
151
+ # FamilyReceiver_Input.points(Semantics::Switch) # => [FamilyReceiver_Switch]
152
+ #
153
+ # @param [Class] point_or_property_types
154
+ # Pass 1 or 2 classes that are sub-classes of [Point] or [Property].
155
+ # Note that when comparing against semantic tags, it does a sub-class check.
156
+ # So if you search for [Control], you'll get items tagged with [Switch].
157
+ # @return [Array<GenericItem>]
158
+ def points(*point_or_property_types)
159
+ return members.points(*point_or_property_types) if equipment? || location?
160
+
161
+ # automatically search the parent equipment (or location?!) for sibling points
162
162
  result = (equipment || location)&.points(*point_or_property_types) || []
163
163
  # remove self. but avoid state comparisons
164
164
  result.delete_if { |item| item.eql?(self) }
165
- return result
166
165
  end
167
-
168
- members.points(*point_or_property_types)
169
166
  end
170
167
  end
171
168
  end
@@ -174,21 +171,27 @@ end
174
171
  # Additions to Enumerable to allow easily filtering groups of items based on the semantic model
175
172
  module Enumerable
176
173
  # Returns a new array of items that are a semantics Location (optionally of the given type)
177
- def sublocations(type = nil)
178
- raise ArgumentError, 'type must be a subclass of Location' if type && !(type < OpenHAB::DSL::Semantics::Location)
174
+ def locations(type = nil)
175
+ if type && !(type < OpenHAB::DSL::Items::Semantics::Location)
176
+ raise ArgumentError, 'type must be a subclass of Location'
177
+ end
179
178
 
180
179
  result = select(&:location?)
181
180
  result.select! { |i| i.location_type <= type } if type
182
181
 
183
182
  result
184
183
  end
184
+ # @deprecated Please use {#locations}
185
+ alias sublocations locations
185
186
 
186
187
  # Returns a new array of items that are a semantics equipment (optionally of the given type)
187
188
  #
188
189
  # @example Get all TVs in a room
189
190
  # lGreatRoom.equipments(Semantics::Screen)
190
191
  def equipments(type = nil)
191
- raise ArgumentError, 'type must be a subclass of Equipment' if type && !(type < OpenHAB::DSL::Semantics::Equipment)
192
+ if type && !(type < OpenHAB::DSL::Items::Semantics::Equipment)
193
+ raise ArgumentError, 'type must be a subclass of Equipment'
194
+ end
192
195
 
193
196
  result = select(&:equipment?)
194
197
  result.select! { |i| i.equipment_type <= type } if type
@@ -205,36 +208,20 @@ module Enumerable
205
208
  raise ArgumentError, "wrong number of arguments (given #{point_or_property_types.length}, expected 0..2)"
206
209
  end
207
210
  unless point_or_property_types.all? do |tag|
208
- tag < OpenHAB::DSL::Semantics::Point || tag < OpenHAB::DSL::Semantics::Property
211
+ tag < OpenHAB::DSL::Items::Semantics::Point || tag < OpenHAB::DSL::Items::Semantics::Property
209
212
  end
210
213
  raise ArgumentError, 'point_or_property_types must all be a subclass of Point or Property'
211
214
  end
212
- if point_or_property_types.count { |tag| tag < OpenHAB::DSL::Semantics::Point } > 1 ||
213
- point_or_property_types.count { |tag| tag < OpenHAB::DSL::Semantics::Property } > 1
215
+ if point_or_property_types.count { |tag| tag < OpenHAB::DSL::Items::Semantics::Point } > 1 ||
216
+ point_or_property_types.count { |tag| tag < OpenHAB::DSL::Items::Semantics::Property } > 1
214
217
  raise ArgumentError, 'point_or_property_types cannot both be a subclass of Point or Property'
215
218
  end
216
219
 
217
- filter_with_members(&:point?)
218
- .select do |point|
219
- point_or_property_types.all? do |tag|
220
- (tag < OpenHAB::DSL::Semantics::Point && point.point_type&.<=(tag)) ||
221
- (tag < OpenHAB::DSL::Semantics::Property && point.property_type&.<=(tag))
220
+ select do |point|
221
+ point.point? && point_or_property_types.all? do |tag|
222
+ (tag < OpenHAB::DSL::Items::Semantics::Point && point.point_type <= tag) ||
223
+ (tag < OpenHAB::DSL::Items::Semantics::Property && point.property_type&.<=(tag))
222
224
  end
223
225
  end
224
226
  end
225
-
226
- #
227
- # Select the elements where the given block returns true.
228
- # If the block returns false but the element is a GroupItem with members,
229
- # merge its members into the result and filter them using the same block
230
- #
231
- # @param [Block] &block A block that returns true for the elements and members to be included in the result
232
- #
233
- # @return [Array] The resulting array
234
- #
235
- # !@visibility private
236
- def filter_with_members(&block)
237
- selected, others = partition(&block)
238
- others.members.select(&block).concat(selected)
239
- end
240
227
  end
@@ -35,7 +35,7 @@ module OpenHAB
35
35
  #
36
36
  # @param [String] expression OpenHAB style cron expression
37
37
  # @param [Object] attach object to be attached to the trigger
38
- # @param [Hash] elements cron expression elements (second, minute, hour, dom, month, dow, year)
38
+ # @param [Hash] fields cron expression elements (second, minute, hour, dom, month, dow, year)
39
39
  #
40
40
  def cron(expression = nil, attach: nil, **fields)
41
41
  if fields.any?
@@ -124,7 +124,7 @@ module OpenHAB
124
124
  #
125
125
  # Create a cron map from a MonthDay
126
126
  #
127
- # @param [Java::JavaTime::MonthDay] month_day
127
+ # @param [Java::JavaTime::MonthDay] monthday a {MonthDay} object
128
128
  # @param [Object] at TimeOfDay or String representing time of day
129
129
  #
130
130
  # @return [Hash] map describing cron expression
@@ -152,7 +152,7 @@ module OpenHAB
152
152
  #
153
153
  # Create a cron map from cron elements
154
154
  #
155
- # @param [Hash] elements Cron fields (second, minute, hour, dom, month, dow, year)
155
+ # @param [Hash] fields Cron fields (second, minute, hour, dom, month, dow, year)
156
156
  #
157
157
  # @return [Hash] map describing cron expression
158
158
  #
@@ -33,7 +33,7 @@ module OpenHAB
33
33
  # Check if all the given items have a state (not UNDEF or NULL)
34
34
  #
35
35
  # @param [Array] items whose state must be non-nil
36
- # @param [<Type>] check_things when true, also ensures that all linked things are online
36
+ # @param [<Type>] things when true, also ensures that all linked things are online
37
37
  #
38
38
  # @return [Boolean] true if all the items have a state, false otherwise
39
39
  #
@@ -51,7 +51,7 @@ module OpenHAB
51
51
  #
52
52
  # Create a StateStorage object that stores the states of the given items
53
53
  #
54
- # @param [Array<Item>] *items A list of items
54
+ # @param [Array<Item>] items A list of items
55
55
  #
56
56
  # @return [StateStorage] A state storage object
57
57
  #
@@ -57,7 +57,7 @@ module OpenHAB
57
57
  # @return [Boolean]
58
58
  #
59
59
  def ==(other) # rubocop:disable Metrics
60
- logger.trace("(#{self.class}) #{self} == #{other} (#{other.class})")
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("(#{self.class}) #{self} === #{other} (#{other.class})")
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("(#{self.class}) #{self} == #{other} (#{other.class})")
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
@@ -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}_enabled?") { @sl4fj_logger.send("is_#{level}_enabled") }
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 trace_enabled?
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 debug_enabled?
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}_enabled?")
127
+ return unless send("#{severity}?")
126
128
 
127
129
  # Process block if no message provided
128
130
  msg = yield if msg.nil? && block_given?
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.39.0'
8
+ VERSION = '4.41.0'
9
9
  end
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.39.0
4
+ version: 4.41.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-04-20 00:00:00.000000000 Z
11
+ date: 2022-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler