openhab-scripting 5.4.2 → 5.5.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: 98baaf8e8f9abf971d25737d726127c8b7396f600e0a34079f8b4c8ae26eef64
4
- data.tar.gz: ea340479297eb523bed7ea18ab033c381c3b0479ca6b7b289689c87e90fcab47
3
+ metadata.gz: 9b21bcd2b958405fb4b4843435e3a6ffa14690af1b6f58139897982a7d55323f
4
+ data.tar.gz: a1c258192db348813c49b94e21492771d9b2e7d6515e6aff0e04b5bba7786711
5
5
  SHA512:
6
- metadata.gz: 8059407518f7f621aa0ed19b11f1d3d51c423c6692dcf90e6342b39907f72021325127c28b28008089f507747debaa7ea07876d276c7252e4501f81de911e46e
7
- data.tar.gz: 6896b15e4bfc5cada7ce6eda2ae11f551d94fbf1e9911b649059dc59be9f949064d0ade274396a620810b58cdf7c67898423e56410974f8a317bc081e48bd2b4
6
+ metadata.gz: 81fd4bfaa0f3cb1907622938750dc0eabcc51b0d46d8ad39fd63282ad6118771f79b38a72fc10ffaa19f0037564d1adb710c7da0b981dad37f9cdf9b6f665cfd
7
+ data.tar.gz: 1b30d461514d2f952e71e3ce7325dd5582fa386ca21723458b725378f6f78880f96bf5693a03aeb64d8a70775830979fe6d8f732c67076abaf9fd687e0ff4948
@@ -74,13 +74,20 @@ module OpenHAB
74
74
  # All persistence methods that require a timestamp
75
75
  # Note the _between methods are automatically created from the _since methods
76
76
  PERSISTENCE_METHODS = (QUANTITY_METHODS +
77
- %i[changed_since?
78
- count_since
79
- count_state_changes_since
80
- historic_state
81
- maximum_since
82
- minimum_since
83
- updated_since?]).freeze
77
+ %i[ changed_since?
78
+ count_since
79
+ count_state_changes_since
80
+ historic_state
81
+ maximum_since
82
+ minimum_since
83
+ updated_since?])
84
+
85
+ # @deprecated OH3.4 - in openHAB 4, just add :get_all_states_since and freeze the list above
86
+ if Gem::Version.new(OpenHAB::Core::VERSION) >= Gem::Version.new("4.0.0")
87
+ PERSISTENCE_METHODS << :get_all_states_since
88
+ end
89
+ PERSISTENCE_METHODS.freeze
90
+
84
91
  private_constant :QUANTITY_METHODS, :PERSISTENCE_METHODS
85
92
 
86
93
  # @!method persist(service = nil)
@@ -275,6 +282,21 @@ module OpenHAB
275
282
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
276
283
  # @return [Integer] The number of values persisted for this item.
277
284
 
285
+ # @!method all_states_since(timestamp, service = nil)
286
+ # @since openHAB 4.0
287
+ # Returns all the states from a point in time until now.
288
+ # @param [#to_zoned_date_time] timestamp The point in time from which to search
289
+ # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
290
+ # @return [Array<HistoricState>] An array of {HistoricState} persisted for this item.
291
+
292
+ # @!method all_states_between(start, finish, service = nil)
293
+ # @since openHAB 4.0
294
+ # Returns all the states between two points in time.
295
+ # @param [#to_zoned_date_time] start The point in time from which to search
296
+ # @param [#to_zoned_date_time] finish The point in time to which to search
297
+ # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
298
+ # @return [Array<HistoricState>] An array of {HistoricState} persisted for this item.
299
+
278
300
  %i[persist last_update].each do |method|
279
301
  define_method(method) do |service = nil|
280
302
  service ||= persistence_service
@@ -363,6 +385,11 @@ module OpenHAB
363
385
 
364
386
  alias_method :state_changes_since, :count_state_changes_since
365
387
  alias_method :state_changes_between, :count_state_changes_between
388
+ # @deprecated OH 3.4 - if guard is unnecessary in OH4
389
+ if Gem::Version.new(OpenHAB::Core::VERSION) >= Gem::Version.new("4.0.0")
390
+ alias_method :all_states_since, :get_all_states_since
391
+ alias_method :all_states_between, :get_all_states_between
392
+ end
366
393
 
367
394
  private
368
395
 
@@ -391,15 +418,21 @@ module OpenHAB
391
418
  # @return [HistoricState] a {HistoricState} object if the result was a HistoricItem
392
419
  # @return [QuantityType] a `QuantityType` object if the result was an average, delta, deviation,
393
420
  # sum, or variance.
421
+ # @return [Array<HistoricState>] an array of {HistoricState} objects if the result was an array
422
+ # of HistoricItem
394
423
  # @return [Object] the original result object otherwise.
395
424
  #
396
425
  def wrap_result(result, method)
397
- if result.is_a?(org.openhab.core.persistence.HistoricItem)
398
- return HistoricState.new(quantify(result.state), result)
399
- end
400
- return quantify(result) if QUANTITY_METHODS.include?(method)
426
+ case result
427
+ when org.openhab.core.persistence.HistoricItem
428
+ HistoricState.new(quantify(result.state), result)
429
+ when java.util.Collection, Array
430
+ result.to_a.map { |historic_item| wrap_result(historic_item, method) }
431
+ else
432
+ return quantify(result) if QUANTITY_METHODS.include?(method)
401
433
 
402
- result
434
+ result
435
+ end
403
436
  end
404
437
 
405
438
  #
@@ -81,7 +81,8 @@ module OpenHAB
81
81
  def process_active_timer(timer, inputs, mod, &block)
82
82
  old_state = Conditions.old_state_from(inputs)
83
83
  new_state = Conditions.new_state_from(inputs)
84
- if new_state != @tracking_from && @conditions.process(mod: nil, inputs: { "state" => new_state })
84
+ if @conditions.from? && new_state != @tracking_from &&
85
+ @conditions.process(mod: nil, inputs: { "state" => new_state })
85
86
  logger.trace("Item changed from #{old_state} to #{new_state} for #{self}, keep waiting.")
86
87
  else
87
88
  logger.trace("Item changed from #{old_state} to #{new_state} for #{self}, canceling timer.")
@@ -41,6 +41,13 @@ module OpenHAB
41
41
  true
42
42
  end
43
43
 
44
+ #
45
+ # Returns true if a `from` condition was specified
46
+ #
47
+ def from?
48
+ !@from.nil?
49
+ end
50
+
44
51
  private
45
52
 
46
53
  def check_value(value, expected_value)
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.4.2"
7
+ VERSION = "5.5.0"
8
8
  end
9
9
  end
data/lib/openhab/log.rb CHANGED
@@ -296,8 +296,8 @@ module OpenHAB
296
296
  return error if debug?
297
297
 
298
298
  if error.respond_to? :backtrace_locations
299
- backtrace = error.backtrace_locations.map(&:to_s).grep_v(INTERNAL_CALL_REGEX)
300
- error.set_backtrace(backtrace)
299
+ backtrace = error.backtrace_locations&.map(&:to_s)&.grep_v(INTERNAL_CALL_REGEX)
300
+ error.set_backtrace(backtrace) if backtrace
301
301
  elsif error.respond_to? :stack_trace
302
302
  backtrace = error.stack_trace.reject { |line| JAVA_INTERNAL_CALL_REGEX.match? line.to_s }
303
303
  error.set_stack_trace(backtrace)
@@ -229,8 +229,17 @@ module OpenHAB
229
229
  bundle = org.osgi.framework.FrameworkUtil.get_bundle(org.openhab.core.persistence.PersistenceService.java_class)
230
230
  bundle.bundle_context.register_service(org.openhab.core.persistence.PersistenceService.java_class, ps, nil)
231
231
 
232
- # wait for the rule engine
233
232
  rs = OSGi.service("org.openhab.core.service.ReadyService")
233
+
234
+ # Add a fake automation:scriptEngineFactories to satisfy startlevel 30
235
+ begin
236
+ sef_marker = org.openhab.core.automation.module.script.internal.ScriptEngineFactoryBundleTracker::READY_MARKER
237
+ rs.mark_ready(sef_marker)
238
+ rescue NameError
239
+ # @deprecated OH3.4 NOOP - the ScriptEngineFactoryBundleTracker doesn't exist in OH3
240
+ end
241
+
242
+ # wait for the rule engine
234
243
  filter = org.openhab.core.service.ReadyMarkerFilter.new
235
244
  .with_type(org.openhab.core.service.StartLevelService::STARTLEVEL_MARKER_TYPE)
236
245
  .with_identifier(org.openhab.core.service.StartLevelService::STARTLEVEL_RULEENGINE.to_s)
data/lib/openhab/rspec.rb CHANGED
@@ -16,7 +16,7 @@ require_relative "rspec/helpers"
16
16
  require_relative "rspec/karaf"
17
17
  require_relative "rspec/hooks"
18
18
 
19
- return unless defined?(RSpec)
19
+ require "rspec/core"
20
20
 
21
21
  RSpec.configure do |c|
22
22
  c.add_setting :openhab_automation_search_paths, default: [
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: 5.4.2
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-07-23 00:00:00.000000000 Z
13
+ date: 2023-08-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler