openhab-scripting 4.44.2 → 4.45.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/dsl/dsl.rb +9 -7
- data/lib/openhab/dsl/monkey_patch/java/java.rb +4 -0
- data/lib/openhab/dsl/monkey_patch/java/local_time.rb +44 -0
- data/lib/openhab/dsl/monkey_patch/java/time_extensions.rb +50 -0
- data/lib/openhab/dsl/monkey_patch/java/zoned_date_time.rb +45 -0
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +3 -2
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +4 -1
- data/lib/openhab/dsl/monkey_patch/ruby/time.rb +61 -0
- data/lib/openhab/dsl/time/time_of_day.rb +8 -5
- data/lib/openhab/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92e2d3cfb9d4cda1452db68930c6f0d291ee3c81b1df4f9cbf4cfe9e0946d1a3
|
4
|
+
data.tar.gz: b2df2b5577372f44b0a7ab265abc9e03c8ee3fcec1c24152302f42cf66892221
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f865451318a850196975f2d5482eaba83a33229c050475bf8ea46fdf058ad95ca494dc2cf2ae1f0b1aae38fd29a78fbeffefbaf2eadd2d669dbbe66ab33fb5
|
7
|
+
data.tar.gz: 8b268e91ca36f4450a1ea73a6794b0b7fe8651a0e8566573f5168d046260c3b6b8d11fae78ada7d2c86331ce6c08ed9c4cdf66ad3ff08e6bcb049e76823cd46b
|
data/lib/openhab/dsl/dsl.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
require 'openhab/dsl/monkey_patch/ruby/ruby'
|
10
|
+
require_relative 'types/types'
|
11
|
+
require_relative 'items/items'
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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,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,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
|
-
|
120
|
-
when
|
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
|
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
|
data/lib/openhab/version.rb
CHANGED
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.
|
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-09-
|
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
|