openhab-scripting 4.6.2 → 4.7.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: 287e243222ea07f7a3157b208722d47f489f14456713ad86401292f6b2fda942
4
- data.tar.gz: 44968c29cf24415646ebb27ce64c3894966c4e9f9707edcd303eb89d4a4b1f04
3
+ metadata.gz: c0e7aabfc4cdcd9a89787c861b639e087f903e9f499db1e24d1b67b0baea71eb
4
+ data.tar.gz: d590f67786a6499e17afc791fe18564223d13a0792d649494b197daf2c688536
5
5
  SHA512:
6
- metadata.gz: 12ce91f43449208a374b04ab92171a93c4ab3b68f2fee8ce7f948f7bf21f2be4a8d967b8f5758be957f5ca36cac831ebcb5f184204d650ed50d1fb345b1c2f7a
7
- data.tar.gz: d7da5a64ab6aef028308a998ea83a77da1d77d12cbccb24c34875f6e51a9c6360e204efd75287de4d4f1fbc17b9bcd722057da227821f519452945fb17fd1666
6
+ metadata.gz: 91b26707cfa19145ad2d38587e476057a9ae7f8ac3c77a7a3c237f119c257ccbec79419fd77cd9b61656da8c6c18ff35be4ad14a1ea1d674ee3f28e26cc412aa
7
+ data.tar.gz: d168357490983f4ce8a5d3152394cf5c982270ae110d829096a32d9637dfc2c99a453a82783b4e5ba9300f5832632bedb88a077654623a43b8a0228bfe07cf40
@@ -25,6 +25,7 @@ module OpenHAB
25
25
  extend Forwardable
26
26
 
27
27
  def_delegator :@metadata, :value
28
+ def_delegator :__getobj__, :to_h, :to_hash
28
29
 
29
30
  def initialize(metadata: nil, key: nil, value: nil, config: nil)
30
31
  @metadata = metadata || Metadata.new(key || MetadataKey.new('', ''), value&.to_s, config)
@@ -68,6 +69,7 @@ module OpenHAB
68
69
  # @return [Java::Org::openhab::core::items::Metadata] the old metadata
69
70
  #
70
71
  def config=(config)
72
+ config = config.to_hash if config.respond_to?(:to_hash)
71
73
  raise ArgumentError, 'Configuration must be a hash' unless config.is_a? Hash
72
74
 
73
75
  metadata = Metadata.new(@metadata&.uID, @metadata&.value, config)
@@ -158,7 +160,7 @@ module OpenHAB
158
160
  meta_value, configuration = update_from_value(value)
159
161
 
160
162
  key = MetadataKey.new(namespace, @item_name)
161
- metadata = Metadata.new(key, meta_value&.to_s, configuration)
163
+ metadata = Metadata.new(key, meta_value&.to_s, configuration.to_h)
162
164
  # registry.get can be omitted, but registry.update will log a warning for nonexistent metadata
163
165
  if NamespaceAccessor.registry.get(key)
164
166
  NamespaceAccessor.registry.update(metadata)
@@ -45,7 +45,7 @@ module OpenHAB
45
45
  #
46
46
  def logger
47
47
  if @rule_name
48
- Log.logger(@rule_name.chomp.gsub(/\s+/, '_'))
48
+ Log.logger_for(@rule_name.chomp.gsub(/\s+/, '_'))
49
49
  else
50
50
  super
51
51
  end
@@ -127,7 +127,7 @@ module OpenHAB
127
127
  #
128
128
  def logger
129
129
  if name
130
- Log.logger(name.chomp.gsub(/\s+/, '_'))
130
+ Log.logger_for(name.chomp.gsub(/\s+/, '_'))
131
131
  else
132
132
  super
133
133
  end
@@ -39,7 +39,7 @@ module OpenHAB
39
39
  else
40
40
  # Place in array and flatten to support multiple to elements or single or nil
41
41
  [to].flatten.each do |to_state|
42
- create_changed_trigger(item, from, to_state)
42
+ [from].flatten.each { |from_state| create_changed_trigger(item, from_state, to_state) }
43
43
  end
44
44
  end
45
45
  end
@@ -137,31 +137,36 @@ module OpenHAB
137
137
  # @return [Logger] for the current class
138
138
  #
139
139
  def logger
140
- Log.logger(self.class.name)
140
+ Log.logger(self.class)
141
141
  end
142
142
 
143
143
  class << self
144
144
  #
145
145
  # Injects a logger into the base class
146
146
  #
147
- # @param [String] name of the logger
147
+ # @param [Class] class the logger is for
148
148
  #
149
149
  # @return [Logger] for the supplied name
150
150
  #
151
- def logger(name)
152
- name ||= self.class.name
151
+ def logger(klass)
152
+ if klass.respond_to?(:java_class) &&
153
+ klass.java_class &&
154
+ !klass.java_class.name.start_with?('org.jruby.Ruby')
155
+ klass = klass.java_class
156
+ end
157
+ name = klass.name
153
158
  @loggers[name] ||= Log.logger_for(name)
154
159
  end
155
160
 
156
161
  #
157
162
  # Configure a logger for the supplied class name
158
163
  #
159
- # @param [String] classname to configure logger for
164
+ # @param [String] name to configure logger for
160
165
  #
161
166
  # @return [Logger] for the supplied classname
162
167
  #
163
- def logger_for(classname)
164
- configure_logger_for(classname)
168
+ def logger_for(name)
169
+ configure_logger_for(name)
165
170
  end
166
171
 
167
172
  private
@@ -173,10 +178,10 @@ module OpenHAB
173
178
  #
174
179
  # @return [Logger] Logger for the supplied classname
175
180
  #
176
- def configure_logger_for(classname)
181
+ def configure_logger_for(name)
177
182
  log_prefix = Configuration.log_prefix
178
- log_prefix += if classname
179
- ".#{classname}"
183
+ log_prefix += if name
184
+ ".#{name}"
180
185
  else
181
186
  ".#{log_caller}"
182
187
  end
@@ -207,7 +212,7 @@ module OpenHAB
207
212
  def self.included(base)
208
213
  class << base
209
214
  def logger
210
- Log.logger(self.class.name)
215
+ Log.logger(self)
211
216
  end
212
217
  end
213
218
  end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.6.2'
8
+ VERSION = '4.7.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.6.2
4
+ version: 4.7.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-24 00:00:00.000000000 Z
11
+ date: 2021-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler