openhab-scripting 4.36.0 → 4.37.0

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: 0f8ae7a88299903d5fe44ecc1a1bf2f16bdeb659545a567d1e86dfc908367694
4
- data.tar.gz: 94db08cd7ee03e382db6d7b4ebed8b240ae4e354a7b62073b0a81cc1b7228cdd
3
+ metadata.gz: 152174c3766a83b620a0ec7df6e692bb914e187c788d9c5eecfcedd42bfd641c
4
+ data.tar.gz: 44084d3557abd293faf97858470414cf5f3dd65e07faa8f74e8f40e0d6ea8edb
5
5
  SHA512:
6
- metadata.gz: 6f8ea8b5f0ab16e602f002cf749102c4250bb3525fc6f7e18f11eafe294125d198d6a85c5565bfc29629024dad0f5823ef0a298e7e90f7aa776030b84df4a25f
7
- data.tar.gz: 9a04fb5c20858fbe6b1e63dbdff39207f8de7a7809b26000eef663cc3ff146e75e9e6717df1e2485b087fe92736af248f9352085b472d64e931008d60b7eb89c
6
+ metadata.gz: 617deb9b4f75a92a407cf8db6ff695f409ac5f006690751c10100919d414851dc83758ec0560badf3d40097cc896d86de132a215d22a3f505b8e97bff26a8ad2
7
+ data.tar.gz: 5a2c037047ce9db79d57a153e5df94c631144d511ac716b1862a8a6c4fc567d01c6efa15d93583f2bc80a792c47c85e30dda65ec481a1f14f6a588765638d56f
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'imports'
4
+
5
+ OpenHAB::DSL.import_presets
6
+
3
7
  require 'openhab/log/logger'
4
8
 
5
9
  # the order of these is important
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ include OpenHAB::Log
6
+ #
7
+ # Import required java classes
8
+ #
9
+ def self.import_presets # rubocop:disable Metrics/AbcSize
10
+ return if Object.const_get(:ZonedDateTime).is_a?(Class)
11
+
12
+ # Fix the import problem in OpenHAB 3.2 addon. Not required in 3.3+
13
+ [java.time.Duration,
14
+ java.time.ZonedDateTime,
15
+ java.time.ZoneId,
16
+ java.time.temporal.ChronoUnit].each do |klass|
17
+ Object.const_set(klass.java_class.simple_name.to_sym, klass)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -171,6 +171,7 @@ module OpenHAB
171
171
  # rubocop: disable Metrics/AbcSize
172
172
  # There is no feasible way to break this method into smaller components
173
173
  def execute(_mod = nil, inputs = nil)
174
+ OpenHAB::DSL.import_presets
174
175
  @semaphore.synchronize do
175
176
  thread_local(@thread_locals) do
176
177
  logger.trace "Canceling implicit timer #{@timed_command_details.timer} for "\
@@ -3,6 +3,15 @@
3
3
  require 'pathname'
4
4
 
5
5
  module OpenHAB
6
+ #
7
+ # Return the OpenHAB conf directory as a ruby pathname
8
+ #
9
+ # @return [Pathname] OpenHAB conf path
10
+ #
11
+ def self.conf_root
12
+ Pathname.new(ENV['OPENHAB_CONF'])
13
+ end
14
+
6
15
  module DSL
7
16
  #
8
17
  # Provides access to OpenHAB attributes
@@ -12,13 +21,9 @@ module OpenHAB
12
21
 
13
22
  module_function
14
23
 
15
- #
16
- # Return the OpenHAB conf directory as a ruby pathname
17
- #
18
- # @return [Pathname] OpenHAB conf path
19
- #
24
+ # @deprecated Please use {OpenHAB.conf_root} instead
20
25
  def __conf__
21
- Pathname.new(ENV['OPENHAB_CONF'])
26
+ OpenHAB.conf_root
22
27
  end
23
28
  end
24
29
  end
@@ -23,7 +23,6 @@ module OpenHAB
23
23
  include OpenHAB::Log
24
24
  include OpenHAB::Core::ThreadLocal
25
25
  include OpenHAB::DSL::Between
26
- java_import java.time.ZonedDateTime
27
26
 
28
27
  #
29
28
  # Create a new Rule
@@ -55,6 +54,7 @@ module OpenHAB
55
54
  #
56
55
  #
57
56
  def execute(mod = nil, inputs = nil)
57
+ OpenHAB::DSL.import_presets
58
58
  thread_local(RULE_NAME: name) do
59
59
  logger.trace { "Execute called with mod (#{mod&.to_string}) and inputs (#{inputs.inspect})" }
60
60
  logger.trace { "Event details #{inputs['event'].inspect}" } if inputs&.key?('event')
@@ -95,11 +95,24 @@ module OpenHAB
95
95
  class TimerSet < Set
96
96
  #
97
97
  # A shorthand to cancel all the timer objects held within the set
98
- # so that timers[timer_id].cancel_all is equivalent to timers[timer_id].each(&:cancel)
98
+ # so that timers[timer_id].cancel is equivalent to timers[timer_id].each(&:cancel)
99
99
  #
100
- def cancel_all
100
+ def cancel
101
101
  each(&:cancel)
102
102
  end
103
+ # @deprecated Please use {cancel} instead
104
+ alias cancel_all cancel
105
+
106
+ #
107
+ # A shorthand to reschedule all the timer objects held within the set
108
+ #
109
+ # @param [Duration] duration An optional duration to reschedule
110
+ #
111
+ # @return [TimerSet] Set of timers
112
+ #
113
+ def reschedule(duration = nil)
114
+ each { |timer| timer.reschedule duration }
115
+ end
103
116
  end
104
117
  end
105
118
  end
@@ -9,7 +9,6 @@ require 'openhab/core/thread_local'
9
9
  module OpenHAB
10
10
  module DSL
11
11
  java_import org.openhab.core.model.script.actions.ScriptExecution
12
- java_import java.time.ZonedDateTime
13
12
 
14
13
  # Ruby wrapper for OpenHAB Timer
15
14
  # This class implements delegator to delegate methods to the OpenHAB timer
@@ -80,6 +79,7 @@ module OpenHAB
80
79
  #
81
80
  def timer_block(semaphore)
82
81
  proc {
82
+ OpenHAB::DSL.import_presets
83
83
  semaphore.synchronize do
84
84
  Timers.timer_manager.delete(self)
85
85
  thread_local(@thread_locals) do
@@ -8,7 +8,6 @@ module OpenHAB
8
8
  module DSL
9
9
  module Types
10
10
  DateTimeType = org.openhab.core.library.types.DateTimeType
11
- java_import java.time.ZonedDateTime # This is needed for the addon prior to ruby_class fix (OH 3.2.0)
12
11
 
13
12
  # global alias - required for jrubyscripting addon <= OH3.2.0
14
13
  ::DateTimeType = DateTimeType if ::DateTimeType.is_a?(Java::JavaLang::Class)
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.36.0'
8
+ VERSION = '4.37.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.36.0
4
+ version: 4.37.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: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ files:
60
60
  - lib/openhab/dsl/dsl.rb
61
61
  - lib/openhab/dsl/gems.rb
62
62
  - lib/openhab/dsl/group.rb
63
+ - lib/openhab/dsl/imports.rb
63
64
  - lib/openhab/dsl/items/color_item.rb
64
65
  - lib/openhab/dsl/items/comparable_item.rb
65
66
  - lib/openhab/dsl/items/contact_item.rb