openhab-scripting 4.45.1 → 4.46.1

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: 219ff31be5a2a08d9c0fcfdac6a15a1703e056928ce3fcea17e10da6824a26d8
4
- data.tar.gz: 5b7be5678b869b4b3f469c5039d4663d153206433f91f178832f9812ff24838c
3
+ metadata.gz: c6843041898c2a83a667d7e64e3233b6d8d88cf86909f683ce13ccd3e1194289
4
+ data.tar.gz: ce84f8f828d2c7b193b830c1818a2a3f9333455a1381ffbb7be33d64d0be0210
5
5
  SHA512:
6
- metadata.gz: aa2881c99476b13c112dcde86e0c2a2b52e5c8af2504340254ebba5a6461aed04ee49d2098a84281b38160cd1bd3933ee17d663bda40f84b1c9e45648408574f
7
- data.tar.gz: 3393c479d762c7442cb6af4605efd90cab156d413eebe87757338c035af93aa9d41500dcfb4d67c11e677cd26592dfae64a0ffe1ecb1bbace42584ae1194514f
6
+ metadata.gz: 225f88032d55646e9b397a75e698df1b52e6f5eff09b3ac2cfed672436ffaea40cee492b9216a38d0a051f3a834072ae51919e0d5a3f6d6b93e2fc289707c61e
7
+ data.tar.gz: b464df4e24dbada506a9b14a80b82e714a6fd0e534fbe186de4b6257b0c0bb3a90de7a775d220156d1988b902f9580f3f3824324c8013b816c94b73ebc1241a7
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ruby2_keywords'
4
+ require 'openhab/log/logger'
3
5
  require_relative 'generic_item'
4
6
 
5
7
  module OpenHAB
@@ -81,14 +83,13 @@ module OpenHAB
81
83
  end
82
84
 
83
85
  # activate +ensure_states+ before forwarding to the wrapped object
84
- def method_missing(method, *args, &block)
86
+ ruby2_keywords def method_missing(method, *args, &block)
85
87
  return super unless @item.respond_to?(method)
86
88
 
87
89
  ensure_states do
88
90
  @item.__send__(method, *args, &block)
89
91
  end
90
92
  end
91
- ruby2_keywords :method_missing if respond_to? :ruby2_keywords
92
93
 
93
94
  # .
94
95
  def respond_to_missing?(method, include_private = false)
@@ -46,7 +46,7 @@ module OpenHAB
46
46
  # Explicit conversion to array
47
47
  # @return [Array]
48
48
  def to_a
49
- $ir.items.to_a
49
+ $ir.items.map { |item| OpenHAB::Core::ItemProxy.new(item) }
50
50
  end
51
51
  end
52
52
  end
@@ -174,7 +174,7 @@ module OpenHAB
174
174
  OpenHAB::DSL.import_presets
175
175
  @semaphore.synchronize do
176
176
  thread_local(**@thread_locals) do
177
- logger.trace "Canceling implicit timer #{@timed_command_details.timer} for "\
177
+ logger.trace "Canceling implicit timer #{@timed_command_details.timer} for " \
178
178
  "#{@timed_command_details.item.id} because received event #{inputs}"
179
179
  @timed_command_details.timer.cancel
180
180
  # Disabled due to OpenHAB design
@@ -9,7 +9,7 @@ module OpenHAB
9
9
  # @return [Pathname] OpenHAB conf path
10
10
  #
11
11
  def self.conf_root
12
- Pathname.new(ENV['OPENHAB_CONF'])
12
+ Pathname.new(ENV.fetch('OPENHAB_CONF', nil))
13
13
  end
14
14
 
15
15
  module DSL
@@ -162,7 +162,7 @@ module OpenHAB
162
162
  now = Time.now
163
163
  return true if @between.cover? now
164
164
 
165
- logger.trace("Skipped execution of rule '#{name}' because the current time #{now} "\
165
+ logger.trace("Skipped execution of rule '#{name}' because the current time #{now} " \
166
166
  "is not between #{@between.begin} and #{@between.end}")
167
167
  else
168
168
  logger.trace("Skipped execution of rule '#{name}' because of guard #{@guard}")
@@ -112,7 +112,7 @@ module OpenHAB
112
112
  #
113
113
  def wait_trigger(item:, duration:, to: nil, from: nil, attach: nil)
114
114
  item_name = item.respond_to?(:name) ? item.name : item.to_s
115
- logger.trace("Creating Changed Wait Change Trigger for Item(#{item_name}) Duration(#{duration}) "\
115
+ logger.trace("Creating Changed Wait Change Trigger for Item(#{item_name}) Duration(#{duration}) " \
116
116
  "To(#{to}) From(#{from}) Attach(#{attach})")
117
117
  conditions = Conditions::Duration.new(to: to, from: from, duration: duration)
118
118
  changed_trigger(item: item, to: nil, from: nil, attach: attach, conditions: conditions)
@@ -36,7 +36,7 @@ module OpenHAB
36
36
  @conditions = Conditions::Proc.new(to: to, from: from)
37
37
  @duration = duration
38
38
  @timer = nil
39
- logger.trace "Created Duration Condition To(#{to}) From(#{from}) "\
39
+ logger.trace "Created Duration Condition To(#{to}) From(#{from}) " \
40
40
  "Conditions(#{@conditions}) Duration(#{@duration})"
41
41
  end
42
42
 
@@ -102,16 +102,6 @@ module OpenHAB
102
102
  end
103
103
  end
104
104
 
105
- java_import java.time.Month
106
- # Extend Month with helper method
107
- class Month
108
- # Calcalute and memoize the maximum number of days in a year before this month
109
- # @return [Number] maximum nummber of days in a year before this month
110
- def max_days_before
111
- @max_days_before ||= Month.values.select { |month| month < self }.sum(&:max_length)
112
- end
113
- end
114
-
115
105
  java_import java.time.MonthDay
116
106
  # Extend MonthDay java object with some helper methods
117
107
  class MonthDay
@@ -131,6 +121,12 @@ module OpenHAB
131
121
  MonthDay.of(m, d)
132
122
  end
133
123
 
124
+ # Calcalute the maximum number of days in a year before a supplied month
125
+ # @return [Number] maximum nummber of days in a year before this month
126
+ def max_days_before(month)
127
+ java.time.Month.values.select { |i| i < month }.sum(&:max_length)
128
+ end
129
+
134
130
  # Parse MonthDay string as defined with by Monthday class without leading double dash "--"
135
131
  def self.parse(string)
136
132
  logger.trace("#{self.class}.parse #{string} (#{string.class})")
@@ -146,7 +142,7 @@ module OpenHAB
146
142
 
147
143
  # Get the maximum (supports leap years) day of the year this month day could be
148
144
  def max_day_of_year
149
- day_of_month + month.max_days_before
145
+ day_of_month + max_days_before(month)
150
146
  end
151
147
 
152
148
  # Remove -- from MonthDay string representation
@@ -173,7 +169,7 @@ module OpenHAB
173
169
  self.<=>(MonthDay.parse(other))
174
170
  when OpenHAB::DSL::Between::MonthDayRange::DayOfYear
175
171
  # Compare with DayOfYear and invert result
176
- -other.<=>(self)
172
+ -(other <=> self)
177
173
  else
178
174
  super
179
175
  end
@@ -189,9 +189,9 @@ module OpenHAB
189
189
  def <=>(other)
190
190
  other_second_of_day = to_second_of_day(other)
191
191
  logger.trace do
192
- "SOD(#{sod}) "\
193
- "other SOD(#{other_second_of_day}) "\
194
- "Other Class (#{other.class}) "\
192
+ "SOD(#{sod}) " \
193
+ "other SOD(#{other_second_of_day}) " \
194
+ "Other Class (#{other.class}) " \
195
195
  "Result (#{sod <=> other_second_of_day})"
196
196
  end
197
197
  sod <=> other_second_of_day
@@ -208,8 +208,8 @@ module OpenHAB
208
208
  # @param [Object] object to derive class name for
209
209
  # @return [String] name of class for logging
210
210
  def klass_name(object)
211
- object.then(&:class)
212
- .then { |klass| java_klass(klass) }
211
+ object = object.class unless object.is_a?(Class)
212
+ object.then { |klass| java_klass(klass) }
213
213
  .then(&:name)
214
214
  .then { |name| filter_base_classes(name) }
215
215
  .then { |name| ".#{name}" unless name.nil? } # name is frozen in jruby 9.4
@@ -222,7 +222,8 @@ module OpenHAB
222
222
  def java_klass(klass)
223
223
  if klass.respond_to?(:java_class) &&
224
224
  klass.java_class &&
225
- !klass.java_class.name.start_with?('org.jruby.Ruby')
225
+ !klass.java_class.name.start_with?('org.jruby.Ruby') &&
226
+ !klass.java_class.name.start_with?('org.jruby.gen')
226
227
  klass = klass.java_class
227
228
  end
228
229
  klass
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.45.1'
8
+ VERSION = '4.46.1'
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.45.1
4
+ version: 4.46.1
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-09-21 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby2_keywords
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
55
69
  description: JRuby Helper Libraries for OpenHAB Scripting
56
70
  email:
57
71
  - broconne@gmail.com