openhab-scripting 4.39.1 → 4.40.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ec5b89b1270a09daed465179e9643c559c51491d030f5b6b53431f942d026fb
4
- data.tar.gz: 292889a440bfc0f08d091fe5eb31894ca78654cabd5d9684d8b803d2840dd75d
3
+ metadata.gz: 7aaa16073cb2b4d71edb5e80debef49282a864bad1e057fb307b5cd8b9ca7844
4
+ data.tar.gz: 641502dca198f6cf42d5a489153f6c04fd3bf70900d4a0873bfb01d686bea6b7
5
5
  SHA512:
6
- metadata.gz: 30e263e6eec5bf3f0258b198817d68f5ca6d31fbca7bb7ac0187601cbd07a91122daa52991e61615003db5a6e308574136d1b1045ad288329539be3e30b0ff28
7
- data.tar.gz: 0e00529a2b6cc75a4e33a44d97623abf2144e38e637d7a3d70bd6a68f8acd19cf7de18811d8306ee9e35effd3756ae4eb53c032106e68d47e122231bb9cc590f
6
+ metadata.gz: 978fe9d74ac7bc6481bb59cfb32a5c917f7707933e68d686be6119096f64daf78a49af1c9e4870abaecc0eec234e50314fae8093f1f04d1c38f6e15cdbe89bd9
7
+ data.tar.gz: b959d2aef01f436f90a56142e4e2c9a4a532de091bd846b97b799a609e16d849d5df2e3de77d91b0a2de588f0da6cf3e6904205b9236538c123484552484565f
@@ -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
@@ -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
@@ -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
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.39.1'
8
+ VERSION = '4.40.0'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.39.1
4
+ version: 4.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell