openhab-scripting 4.44.2 → 4.45.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: 5fc4da63132db46b324f609f104065c23d2ca43f9caa44e1736fcaa5aa0cefc1
4
- data.tar.gz: db4f92843a5c3cba9a11a83c37a832eadd115bdcc75269d2b30800db61bff84b
3
+ metadata.gz: 219ff31be5a2a08d9c0fcfdac6a15a1703e056928ce3fcea17e10da6824a26d8
4
+ data.tar.gz: 5b7be5678b869b4b3f469c5039d4663d153206433f91f178832f9812ff24838c
5
5
  SHA512:
6
- metadata.gz: 62976743367c2cda9c3d88f3fed7701feae81a852226dc93b2c9a41702035ba453e98a21ae3365030a467cc9bd899834eb63d144be2d589fba2716188b7cb2a0
7
- data.tar.gz: 8f88d0b217d6bcfa7029f601acb551eaf030f63452a99cafba05be514b11ec8b000efbdd9dc3dbc8fed2c98c4e9e19e2e617cdb86749353173679a6ed2118073
6
+ metadata.gz: aa2881c99476b13c112dcde86e0c2a2b52e5c8af2504340254ebba5a6461aed04ee49d2098a84281b38160cd1bd3933ee17d663bda40f84b1c9e45648408574f
7
+ data.tar.gz: 3393c479d762c7442cb6af4605efd90cab156d413eebe87757338c035af93aa9d41500dcfb4d67c11e677cd26592dfae64a0ffe1ecb1bbace42584ae1194514f
@@ -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'
@@ -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)
@@ -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
@@ -159,9 +159,9 @@ module OpenHAB
159
159
  <<~RUBY, __FILE__, __LINE__ + 1
160
160
  def #{ruby_op}(other)
161
161
  if other.is_a?(DecimalType)
162
- self.class.new(to_big_decimal.#{java_op}(other.to_big_decimal))
162
+ self.class.new(to_big_decimal.#{java_op}(other.to_big_decimal, java.math.MathContext::DECIMAL128))
163
163
  elsif other.is_a?(java.math.BigDecimal)
164
- self.class.new(to_big_decimal.#{java_op}(other))
164
+ self.class.new(to_big_decimal.#{java_op}(other, java.math.MathContext::DECIMAL128))
165
165
  elsif other.respond_to?(:to_d)
166
166
  result = to_d #{ruby_op} other
167
167
  # result could already be a QuantityType
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.44.2'
8
+ VERSION = '4.45.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.44.2
4
+ version: 4.45.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-06 00:00:00.000000000 Z
11
+ date: 2022-09-21 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