openhab-scripting 4.2.0 → 4.3.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: 4ebe32d36d3366345d28b81bc71d9cd315d1d84feb4a4f1745c882209b1fdbe2
4
- data.tar.gz: 95331e97286e86bc993eb979531c5e3f80bc203e752e97aa9f3a60698fd56274
3
+ metadata.gz: 34dcff6b869bdb1bbcf1e61d84ffe7ff07d039204ee868d16f0f249c3074e898
4
+ data.tar.gz: 39645a3f3486d9bba7db56a43d4c60883c346eea007242603a2dd2f7c8aa3b6e
5
5
  SHA512:
6
- metadata.gz: e406fa7d011a733376bb5977293f44d20b893f1f990486f342c541f8d287c453736b75007ba586bfc5e6801638ac71bc6d294ad1b4a436a83247bee157150eb0
7
- data.tar.gz: d4fad57e6ad4f71a969b8f8c6791c4240854a74800647a4bed770123221eb2491c251c2a28bcbcd1649225d348aadd91b0efc188adba16a56aa7115620224028
6
+ metadata.gz: 303f0751aac26ab7f28a4350ff03151a3a03bb1559f51ae0130c830ea5e20d6bb4165929a173ed4e749cf62ee0e4ab66f1f79845e8e851d44a288407e11be5a5
7
+ data.tar.gz: dfee68ab34f41a303886bc8028ae7a30ff4baaee2fd87cc75602bfa7d82f57c2c3a7bf6190f6efecdb2a364c21a4514fe59984e9da8574cf19c5f3fd782abc7e
@@ -10,6 +10,7 @@ require 'openhab/dsl/monkey_patch/ruby/ruby'
10
10
  require 'openhab/dsl/monkey_patch/events/events'
11
11
  require 'openhab/dsl/monkey_patch/actions/actions'
12
12
  require 'openhab/dsl/rules/rule'
13
+ require 'openhab/dsl/rules/terse'
13
14
  require 'openhab/dsl/actions'
14
15
  require 'openhab/dsl/timers'
15
16
  require 'openhab/dsl/group'
@@ -34,6 +35,7 @@ module OpenHAB
34
35
  base.send :include, OpenHAB::DSL::Items
35
36
  base.send :include, OpenHAB::DSL::Persistence
36
37
  base.send :include, OpenHAB::DSL::Rules
38
+ base.send :include, OpenHAB::DSL::Rules::Terse
37
39
  base.send :include, OpenHAB::DSL::States
38
40
  base.send :include, OpenHAB::DSL::Things
39
41
  base.send :include, OpenHAB::DSL::Timers
@@ -3,6 +3,8 @@
3
3
  require 'openhab/dsl/items/metadata'
4
4
  require 'openhab/dsl/items/persistence'
5
5
 
6
+ require_relative 'item_equality'
7
+
6
8
  module OpenHAB
7
9
  module DSL
8
10
  module Items
@@ -12,6 +14,8 @@ module OpenHAB
12
14
  # Ruby
13
15
  class GenericItem
14
16
  include Log
17
+ include ItemEquality
18
+
15
19
  prepend Metadata
16
20
  prepend Persistence
17
21
 
@@ -135,33 +139,6 @@ module OpenHAB
135
139
  other.instance_of?(self.class) && hash == other.hash
136
140
  end
137
141
 
138
- #
139
- # Check equality, with type conversions
140
- #
141
- # @param [GenericItem, Types::Type, Object] other object to
142
- # compare to
143
- #
144
- # If this item is +NULL+ or +UNDEF+, and +other+ is nil, they are
145
- # considered equal
146
- #
147
- # If this item is +NULL+ or +UNDEF+, and other is a {GenericItem}, they
148
- # are only considered equal if the other item is in the exact same
149
- # state (i.e. +NULL+ != +UNDEF+)
150
- #
151
- # Otherwise, the state of this item is compared with +other+
152
- #
153
- # @return [Boolean]
154
- #
155
- def ==(other)
156
- logger.trace("(#{self.class}) #{self} == #{other} (#{other.class})")
157
- return true if equal?(other) || eql?(other)
158
- return true if !state? && other.nil?
159
-
160
- return raw_state == other.raw_state if other.is_a?(GenericItem)
161
-
162
- state == other
163
- end
164
-
165
142
  # @!method null?
166
143
  # Check if the item state == +NULL+
167
144
  # @return [Boolean]
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ module Items
6
+ # Shared method for checking item equality by delegating to state
7
+ module ItemEquality
8
+ # Check equality, with type conversions
9
+ #
10
+ # @param [GenericItem, Types::Type, Object] other object to
11
+ # compare to
12
+ #
13
+ # If this item is +NULL+ or +UNDEF+, and +other+ is nil, they are
14
+ # considered equal
15
+ #
16
+ # If this item is +NULL+ or +UNDEF+, and other is a {GenericItem}, they
17
+ # are only considered equal if the other item is in the exact same
18
+ # state (i.e. +NULL+ != +UNDEF+)
19
+ #
20
+ # Otherwise, the state of this item is compared with +other+
21
+ #
22
+ # @return [Boolean]
23
+ #
24
+ def ==(other)
25
+ logger.trace("(#{self.class}) #{self} == #{other} (#{other.class})")
26
+ return true if equal?(other) || eql?(other)
27
+ return true if !state? && other.nil?
28
+
29
+ return raw_state == other.raw_state if other.is_a?(GenericItem)
30
+
31
+ state == other
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,7 +2,8 @@
2
2
 
3
3
  require 'forwardable'
4
4
 
5
- require 'openhab/dsl/items/comparable_item'
5
+ require_relative 'comparable_item'
6
+ require_relative 'item_equality'
6
7
 
7
8
  module OpenHAB
8
9
  module DSL
@@ -15,6 +16,7 @@ module OpenHAB
15
16
 
16
17
  # apply meta-programming methods to including class
17
18
  def self.included(klass)
19
+ klass.prepend ItemEquality # make sure this is first
18
20
  klass.extend Forwardable
19
21
  klass.delegate %i[+ - * / % | positive? negative? to_d to_f to_i to_int zero?] => :state
20
22
  # remove the JRuby default == so that we can inherit the Ruby method
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ module Rules
6
+ # Module containing terse rule stubs
7
+ module Terse
8
+ %i[changed channel cron every updated received_command].each do |trigger|
9
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
10
+ def #{trigger}(*args, name: nil, **kwargs, &block) # def changed(*args, name: nil, **kwargs, &block)
11
+ # if no name is given, just default to the name of the rules file # # if no name is given, just default to the name of the rules file
12
+ name ||= File.basename(caller_locations.last.path) # name ||= File.basename(caller_locations.last.path)
13
+ rule name do # rule name do
14
+ #{trigger}(*args, **kwargs) # changed(*args, **kwargs)
15
+ run(&block) # run(&block)
16
+ end # end
17
+ end # end
18
+ module_function #{trigger.inspect} # module_function :changed
19
+ RUBY
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.2.0'
8
+ VERSION = '4.3.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.2.0
4
+ version: 4.3.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: 2021-10-18 00:00:00.000000000 Z
11
+ date: 2021-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ files:
61
61
  - lib/openhab/dsl/items/generic_item.rb
62
62
  - lib/openhab/dsl/items/group_item.rb
63
63
  - lib/openhab/dsl/items/image_item.rb
64
+ - lib/openhab/dsl/items/item_equality.rb
64
65
  - lib/openhab/dsl/items/item_registry.rb
65
66
  - lib/openhab/dsl/items/items.rb
66
67
  - lib/openhab/dsl/items/metadata.rb
@@ -89,6 +90,7 @@ files:
89
90
  - lib/openhab/dsl/rules/property.rb
90
91
  - lib/openhab/dsl/rules/rule.rb
91
92
  - lib/openhab/dsl/rules/rule_config.rb
93
+ - lib/openhab/dsl/rules/terse.rb
92
94
  - lib/openhab/dsl/rules/triggers/changed.rb
93
95
  - lib/openhab/dsl/rules/triggers/channel.rb
94
96
  - lib/openhab/dsl/rules/triggers/command.rb