openhab-scripting 4.32.0 → 4.32.3

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: 737517891b51326c4c0ab343c448cca3f07a4855ca44222a8564d107d5101cf4
4
- data.tar.gz: 0cd4aea92b89e152c7bc7bb0b1e759a22609d833f1022510ec348ff4ad634812
3
+ metadata.gz: 7c1093824867216ac9015ebc8bba44843f327a03c5c896ae44e8c18a90d3ffba
4
+ data.tar.gz: b3496046440b79efbc9d8967634337dc8ee035f4e64d596eb64863f4d2f8e617
5
5
  SHA512:
6
- metadata.gz: c479724e15cb266f9f797f2e6c5646384f089ff83164890cfd2c6924d1ec0b07011015d4195a4e6de30dfa06da8c2617d2528de4652f8432afd4b2cef4c9bb21
7
- data.tar.gz: 6e52ab144a7ba4118c39b9d843ba33a16a9f66903b6f9cdd6fd1cb585febdc121b5934bdd59ae813422c2e6325755302a0285f002427258762ae275214f686ce
6
+ metadata.gz: b4267271e7c487fafc419b874b3a919026c21305c8449836427df7f54361299d91e2f22a26fe7533ca114630862e74e4c671f06828c9a591b485e53da6609eca
7
+ data.tar.gz: cf88fac5372d571b4e2d68f85e8c395488397b314c260957180d1f60173f082c47ebbbc3670b0daa3f5fed753ca4f11154d4c4f45f678aae573626719236d3d2
@@ -54,29 +54,6 @@ module OpenHAB
54
54
  super
55
55
  end
56
56
 
57
- #
58
- # Convert the ColorItem to a hash
59
- # @param [:hsb, :rgb] format for hash
60
- # @return [Hash] in requested format
61
- def to_h(format = :hsb)
62
- values = to_a(format)
63
- keys = (format == :hsb ? %i[hue saturation brightness] : %i[red green blue])
64
- keys.zip(values).to_h
65
- end
66
-
67
- #
68
- # Convert the ColorItem to an array of values
69
- # @param [:hsb, :rgb] format for elements in the array
70
- # @return [Array] of ColorItem components in requested format
71
- def to_a(format = :hsb)
72
- case format
73
- when :hsb then [hue, saturation, brightness]
74
- when :rgb then [red, green, blue].map(&:to_byte)
75
- else
76
- raise ArgumentError, "Unsupported format #{format}"
77
- end
78
- end
79
-
80
57
  private
81
58
 
82
59
  # Mapping of hash values sets to conversion methods
@@ -9,12 +9,10 @@ module OpenHAB
9
9
  # Patches OpenHAB actions
10
10
  #
11
11
  module Actions
12
- java_import Java::OrgOpenhabCoreAutomationModuleScriptInternalDefaultscope::ScriptThingActions
13
-
14
12
  #
15
13
  # MonkeyPatching ScriptThingActions
16
14
  #
17
- class ScriptThingActions
15
+ class << $actions # rubocop:disable Style/GlobalVars
18
16
  field_reader :THING_ACTIONS_MAP
19
17
 
20
18
  #
@@ -23,7 +21,7 @@ module OpenHAB
23
21
  # @return [Set] of keys for defined actions in the form of 'scope-thing_uid'
24
22
  #
25
23
  def action_keys
26
- ScriptThingActions.THING_ACTIONS_MAP.keys
24
+ self.class.THING_ACTIONS_MAP.keys
27
25
  end
28
26
  end
29
27
  end
@@ -105,13 +105,15 @@ module OpenHAB
105
105
  #
106
106
  # nil is returned if the two values are incomparable
107
107
  #
108
- def <=>(other)
108
+ def <=>(other) # rubocop:disable Metrics
109
109
  logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
110
110
  if other.is_a?(Items::ColorItem) ||
111
111
  (other.is_a?(Items::GroupItem) && other.base_item.is_a?(ColorItem))
112
- return false unless other.state?
112
+ return nil unless other.state?
113
113
 
114
114
  self <=> other.state
115
+ elsif other.is_a?(HSBType)
116
+ to_a <=> other.to_a
115
117
  elsif other.respond_to?(:to_str)
116
118
  self <=> HSBType.new(other)
117
119
  else
@@ -178,6 +180,29 @@ module OpenHAB
178
180
  "#{hue},#{saturation},#{brightness}"
179
181
  end
180
182
 
183
+ #
184
+ # Convert the ColorItem to a hash
185
+ # @param [:hsb, :rgb] format for hash
186
+ # @return [Hash] in requested format
187
+ def to_h(format = :hsb)
188
+ values = to_a(format)
189
+ keys = (format == :hsb ? %i[hue saturation brightness] : %i[red green blue])
190
+ keys.zip(values).to_h
191
+ end
192
+
193
+ #
194
+ # Convert the ColorItem to an array of values
195
+ # @param [:hsb, :rgb] format for elements in the array
196
+ # @return [Array] of ColorItem components in requested format
197
+ def to_a(format = :hsb)
198
+ case format
199
+ when :hsb then [hue, saturation, brightness]
200
+ when :rgb then [red, green, blue].map(&:to_byte)
201
+ else
202
+ raise ArgumentError, "Unsupported format #{format}"
203
+ end
204
+ end
205
+
181
206
  # @!attribute [r] saturation
182
207
  # @return [PercentType]
183
208
 
@@ -8,7 +8,8 @@ module OpenHAB
8
8
  #
9
9
  # Provides access to the OpenHAB logging using a Ruby logging methods
10
10
  #
11
- module Log
11
+
12
+ module Core
12
13
  #
13
14
  # Ruby Logger that forwards messages at appropriate levels to OpenHAB Logger
14
15
  #
@@ -105,7 +106,9 @@ module OpenHAB
105
106
  #
106
107
  def log_exception(exception, rule_name)
107
108
  exception = clean_backtrace(exception)
108
- error { "#{exception.message} (#{exception.class})\nIn rule: #{rule_name}\n#{exception.backtrace&.join("\n")}" }
109
+ error do
110
+ "#{exception.message} (#{exception.class})\nIn rule: #{rule_name}\n#{exception.backtrace&.join("\n")}"
111
+ end
109
112
  end
110
113
 
111
114
  private
@@ -152,6 +155,12 @@ module OpenHAB
152
155
  end
153
156
  end
154
157
  end
158
+ end
159
+
160
+ module Log
161
+ #
162
+ # Ruby Logger that forwards messages at appropriate levels to OpenHAB Logger
163
+ #
155
164
 
156
165
  # Logger caches
157
166
  @loggers = {}
@@ -180,7 +189,7 @@ module OpenHAB
180
189
  # of logger name requires lots of operations and logger
181
190
  # names for some objects are specific to the class
182
191
  logger_name = logger_name(object)
183
- @loggers[logger_name] ||= Logger.new(logger_name)
192
+ @loggers[logger_name] ||= OpenHAB::Core::Logger.new(logger_name)
184
193
  end
185
194
 
186
195
  private
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.32.0'
8
+ VERSION = '4.32.3'
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.32.0
4
+ version: 4.32.3
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-01-23 00:00:00.000000000 Z
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler