openhab-scripting 4.44.1 → 4.45.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: '0829e9f6bd0cd3d68bef6db15d0e36bbf3b9d5417ce4099830fb7af8b59e35c5'
4
- data.tar.gz: cbfe57842ccbf6ab2fa11d78245033a38ea823b9fa60dcce1cf3a42b14980ef2
3
+ metadata.gz: 92e2d3cfb9d4cda1452db68930c6f0d291ee3c81b1df4f9cbf4cfe9e0946d1a3
4
+ data.tar.gz: b2df2b5577372f44b0a7ab265abc9e03c8ee3fcec1c24152302f42cf66892221
5
5
  SHA512:
6
- metadata.gz: e7cc9582cfda3af6152beb41d897bca407fd0816d5628bdc9da511c4cc9afc2abf215c7a438b6a9c8b21cb2e38f20bf96ac79908a92a2e50d18818e4e86ab11a
7
- data.tar.gz: 929493b4ad6e943fad845aaad7eb19769991a22915d9fffa9607f8b5cef753f07a651f0e542ad7e0bb005b22a04ed4ec99c1ef27a9527428ec8561b0d6a5987c
6
+ metadata.gz: d0f865451318a850196975f2d5482eaba83a33229c050475bf8ea46fdf058ad95ca494dc2cf2ae1f0b1aae38fd29a78fbeffefbaf2eadd2d669dbbe66ab33fb5
7
+ data.tar.gz: 8b268e91ca36f4450a1ea73a6794b0b7fe8651a0e8566573f5168d046260c3b6b8d11fae78ada7d2c86331ce6c08ed9c4cdf66ad3ff08e6bcb049e76823cd46b
@@ -7,14 +7,16 @@ OpenHAB::DSL.import_presets
7
7
  require 'openhab/log/logger'
8
8
 
9
9
  # the order of these is important
10
- require 'openhab/dsl/types/types'
11
- require 'openhab/dsl/items/items'
12
- require 'openhab/dsl/monkey_patch/ruby/ruby'
10
+ require_relative 'types/types'
11
+ require_relative 'items/items'
13
12
 
14
- require 'openhab/dsl/monkey_patch/events/events'
15
- require 'openhab/dsl/monkey_patch/actions/actions'
16
- require 'openhab/dsl/rules/rule'
17
- require 'openhab/dsl/rules/terse'
13
+ require_relative 'monkey_patch/ruby/ruby'
14
+ require_relative 'monkey_patch/java/java'
15
+ require_relative 'monkey_patch/events/events'
16
+ require_relative 'monkey_patch/actions/actions'
17
+
18
+ require_relative 'rules/rule'
19
+ require_relative 'rules/terse'
18
20
  require_relative 'actions'
19
21
  require_relative 'channel'
20
22
  require_relative 'timers'
@@ -29,7 +29,7 @@ module OpenHAB
29
29
  #
30
30
  # @return [Array]
31
31
  def to_a
32
- group.get_members.to_a
32
+ group.get_members.map { |i| ::OpenHAB::Core::ItemProxy.new(i) }
33
33
  end
34
34
 
35
35
  # Name of the group
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'local_time'
4
+ require_relative 'zoned_date_time'
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'time_extensions'
4
+
5
+ module OpenHAB
6
+ module DSL
7
+ # monkey patches
8
+ module MonkeyPatch
9
+ # extensions to Java objects
10
+ module JavaExtensions
11
+ #
12
+ # Extend LocalTime class to support arithmetic operators
13
+ #
14
+ module LocalTimeExtensions
15
+ include TimeExtensions
16
+ include OpenHAB::Log
17
+
18
+ # apply meta-programming methods to prepending class
19
+ # @!visibility private
20
+ def self.prepended(klass)
21
+ # remove the JRuby default == so that we can inherit the Ruby method
22
+ klass.remove_method :==
23
+ end
24
+
25
+ #
26
+ # Comparison
27
+ #
28
+ # @param [LocalTime,TimeOfDay] other object to compare to
29
+ #
30
+ # @return [Integer] -1, 0, +1 depending on whether +other+ is
31
+ # less than, equal to, or greater than self
32
+ #
33
+ def compare_to(other)
34
+ logger.trace("(#{self.class}) #{self} compare_to #{other} (#{other.class})")
35
+ other = other.local_time if other.is_a?(TimeOfDay)
36
+ super
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ java.time.LocalTime.prepend(OpenHAB::DSL::MonkeyPatch::JavaExtensions::LocalTimeExtensions)
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ # monkey patches
6
+ module MonkeyPatch
7
+ # Extensions to Java objects
8
+ module JavaExtensions
9
+ # Common extensions to Java date/time classes
10
+ module TimeExtensions
11
+ #
12
+ # Add other TemporalAmount or Duration object
13
+ #
14
+ # @param [TemporalAmount] other the TemporalAmount to be added to this ZonedDateTime object
15
+ #
16
+ # @return [ZonedDateTime] The resulting ZonedDateTime object after adding {other}
17
+ #
18
+ def +(other)
19
+ plus(other)
20
+ end
21
+
22
+ #
23
+ # Subtract other TemporalAmount or Duration object
24
+ #
25
+ # @param [TemporalAmount] other the TemporalAmount to be subtracted from this ZonedDateTime object
26
+ #
27
+ # @return [ZonedDateTime] The resulting ZonedDateTime object after subtracting {other}
28
+ #
29
+ def -(other)
30
+ minus(other)
31
+ end
32
+
33
+ #
34
+ # Compare against another time object
35
+ #
36
+ # @param [Object] other The other time object to compare against.
37
+ #
38
+ # @return [Integer] -1, 0, +1 depending on whether +other+ is
39
+ # less than, equal to, or greater than self
40
+ #
41
+ def <=>(other)
42
+ compare_to(other)
43
+ rescue StandardError
44
+ nil
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'time_extensions'
4
+
5
+ module OpenHAB
6
+ module DSL
7
+ module MonkeyPatch
8
+ #
9
+ # Extends the functionalities of Java classes
10
+ #
11
+ module JavaExtensions
12
+ #
13
+ # Extend ZonedDateTime class to support arithmetic operators
14
+ #
15
+ module ZonedDateTimeExtensions
16
+ include TimeExtensions
17
+ include OpenHAB::Log
18
+
19
+ # apply meta-programming methods to prepending class
20
+ # @!visibility private
21
+ def self.prepended(klass)
22
+ # remove the JRuby default == so that we can inherit the Ruby method
23
+ klass.remove_method :==
24
+ end
25
+
26
+ #
27
+ # Comparison
28
+ #
29
+ # @param [ZonedDateTime,Time] other object to compare to
30
+ #
31
+ # @return [Integer] -1, 0, +1 depending on whether +other+ is
32
+ # less than, equal to, or greater than self
33
+ #
34
+ def compare_to(other)
35
+ logger.trace("(#{self.class}) #{self} compare_to #{other} (#{other.class})")
36
+ other = other.to_java(ZonedDateTime) if other.is_a? Time
37
+ super
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ ZonedDateTime.prepend(OpenHAB::DSL::MonkeyPatch::JavaExtensions::ZonedDateTimeExtensions)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'openhab/dsl/monkey_patch/ruby/number'
4
- require 'openhab/dsl/monkey_patch/ruby/string'
3
+ require_relative 'number'
4
+ require_relative 'string'
5
+ require_relative 'time'
5
6
  require 'bigdecimal/util'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'openhab/dsl/time/time_of_day'
4
+
3
5
  module OpenHAB
4
6
  module DSL
5
7
  # monkey patches
@@ -16,7 +18,8 @@ module OpenHAB
16
18
  when Types::QuantityType,
17
19
  Types::DateTimeType,
18
20
  Items::DateTimeItem,
19
- Items::NumericItem
21
+ Items::NumericItem,
22
+ Between::TimeOfDay
20
23
  other == self
21
24
  else
22
25
  super
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ module MonkeyPatch
6
+ module Ruby
7
+ # Extend Time class to allow adding/subtracting against Duration
8
+ module TimeExtensions
9
+ #
10
+ # Add time offset
11
+ #
12
+ # @param [Numeric,Duration] other The offset to add
13
+ #
14
+ # @return [Time] The resulting time after adding the given offset
15
+ #
16
+ def +(other)
17
+ other = to_seconds(other)
18
+ super
19
+ end
20
+
21
+ #
22
+ # Subtract time offset
23
+ #
24
+ # @param [Numeric,Duration] other The offset to subtract
25
+ #
26
+ # @return [Time] The resulting time after subtracting the given offset
27
+ #
28
+ def -(other)
29
+ other = to_seconds(other)
30
+ super
31
+ end
32
+
33
+ #
34
+ # Convert to ZonedDateTime
35
+ #
36
+ # @return [ZonedDateTime] The current time object converted to ZonedDateTime
37
+ #
38
+ def to_zdt
39
+ to_java(ZonedDateTime)
40
+ end
41
+
42
+ private
43
+
44
+ #
45
+ # Convert to floating point seconds if the given value reponds to to_nanos
46
+ #
47
+ # @param [Numeric,Duration] value The duration to convert into seconds.
48
+ #
49
+ # @return [Numeric] The number of seconds from the given value
50
+ #
51
+ def to_seconds(value)
52
+ value = value.to_nanos.to_f / 1_000_000_000 if value.respond_to? :to_nanos
53
+ value
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ Time.prepend(OpenHAB::DSL::MonkeyPatch::Ruby::TimeExtensions)
@@ -62,6 +62,7 @@ module OpenHAB
62
62
  def initialize(trigger)
63
63
  @trigger = trigger
64
64
  @scheduler = OpenHAB::Core::OSGI.service('org.openhab.core.scheduler.CronScheduler')
65
+ @schedule = nil
65
66
  @expression = trigger.configuration.get('cronExpression')
66
67
  super(trigger)
67
68
  end
@@ -73,7 +74,7 @@ module OpenHAB
73
74
  def setCallback(callback) # rubocop:disable Naming/MethodName
74
75
  synchronized do
75
76
  super(callback)
76
- @scheduler.schedule(self, @expression)
77
+ @schedule = @scheduler.schedule(self, @expression)
77
78
  logger.trace("Scheduled cron job '#{@expression}' for trigger '#{@trigger.id}'.")
78
79
  end
79
80
  end
@@ -102,7 +103,8 @@ module OpenHAB
102
103
  super
103
104
  return unless @schedule
104
105
 
105
- @schedule&.cancel(true)
106
+ @schedule.cancel(true)
107
+ @schedule = nil
106
108
  end
107
109
  logger.trace("cancelled job for trigger '#{@trigger.id}'.")
108
110
  end
@@ -20,6 +20,7 @@ module OpenHAB
20
20
  # @since 0.0.1
21
21
  class TimeOfDay
22
22
  include Comparable
23
+ include OpenHAB::Log
23
24
 
24
25
  # Immutable Java object containing Time Of Day
25
26
  # @return [Java.Time.LocalTime] reprsenting the Time Of Day
@@ -114,11 +115,11 @@ module OpenHAB
114
115
  # @return [Number, nil] -1,0,1 if other TimeOfDay is less than, equal to, or greater than this TimeOfDay
115
116
  # or nil if an object other than TimeOfDay is provided
116
117
  def <=>(other)
118
+ logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
117
119
  case other
118
- when TimeOfDay
119
- @local_time.compare_to(other.local_time)
120
- when String
121
- @local_time.compare_to(TimeOfDay.parse(other).local_time)
120
+ when TimeOfDay then @local_time.compare_to(other.local_time)
121
+ when String then @local_time.compare_to(TimeOfDay.parse(other).local_time)
122
+ when LocalTime then @local_time.compare_to(other)
122
123
  else
123
124
  -(other <=> self)
124
125
  end
@@ -146,7 +147,7 @@ module OpenHAB
146
147
  #
147
148
  # Convert object to TimeOfDay object
148
149
  #
149
- # @param [Object] object TimeOfDay or String to be converted
150
+ # @param [Object] object TimeOfDay, String, or LocalTime to be converted
150
151
  #
151
152
  # @return [TimeOfDay] TimeOfDay created from supplied object
152
153
  #
@@ -155,6 +156,8 @@ module OpenHAB
155
156
  when String then TimeOfDay.parse(object)
156
157
  when Time, OpenHAB::DSL::Types::DateTimeType, OpenHAB::DSL::Items::DateTimeItem
157
158
  TimeOfDay.new(h: object.hour, m: object.min, s: object.sec)
159
+ when LocalTime
160
+ TimeOfDay.new(h: object.hour, m: object.minute, s: object.second)
158
161
  else object
159
162
  end
160
163
  end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.44.1'
8
+ VERSION = '4.45.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.44.1
4
+ version: 4.45.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-08-20 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,9 +108,14 @@ files:
108
108
  - lib/openhab/dsl/monkey_patch/events/item_state.rb
109
109
  - lib/openhab/dsl/monkey_patch/events/item_state_changed.rb
110
110
  - lib/openhab/dsl/monkey_patch/events/thing_status_info.rb
111
+ - lib/openhab/dsl/monkey_patch/java/java.rb
112
+ - lib/openhab/dsl/monkey_patch/java/local_time.rb
113
+ - lib/openhab/dsl/monkey_patch/java/time_extensions.rb
114
+ - lib/openhab/dsl/monkey_patch/java/zoned_date_time.rb
111
115
  - lib/openhab/dsl/monkey_patch/ruby/number.rb
112
116
  - lib/openhab/dsl/monkey_patch/ruby/ruby.rb
113
117
  - lib/openhab/dsl/monkey_patch/ruby/string.rb
118
+ - lib/openhab/dsl/monkey_patch/ruby/time.rb
114
119
  - lib/openhab/dsl/openhab.rb
115
120
  - lib/openhab/dsl/persistence.rb
116
121
  - lib/openhab/dsl/rules/automation_rule.rb