openhab-scripting 2.13.0 → 2.13.1
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 +4 -4
- data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +7 -35
- data/lib/openhab/core/dsl/rule/cron.rb +26 -3
- data/lib/openhab/core/dsl/rule/rule.rb +1 -1
- data/lib/openhab/core/dsl/timers.rb +2 -4
- data/lib/openhab/version.rb +1 -1
- metadata +1 -2
- data/lib/openhab/core/duration.rb +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '089e0d97f175f04c563675de122c80d0f5988be5ea38be8833736e4e73341a75'
|
4
|
+
data.tar.gz: 4b98810dd2e4f01772272fc10e457b57e81ade54c19b1dc59a72afd85c368b5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67abc23128c151fdeb509f7a6c770696e0221b6a41a6e8af36628c891aa959c72e7ed7123d1e6d9711da3fe862eba2adaac9e3692e1026193cc7638e11de926a
|
7
|
+
data.tar.gz: 4348d10e590f9e8179c3559c05ae2417cd9a75150d069e98f1566316e60a5d5ed12b4057b0d67272e97d92c813cbf337c97dac8d69b1cc5538b06576aa3084f7
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'core/duration'
|
4
|
-
|
5
3
|
module OpenHAB
|
6
4
|
module Core
|
7
5
|
module DSL
|
@@ -14,44 +12,18 @@ module OpenHAB
|
|
14
12
|
include OpenHAB::Core
|
15
13
|
|
16
14
|
#
|
17
|
-
# Create Duration with
|
18
|
-
#
|
19
|
-
# @return [OpenHAB::Core::Duration] Duration with number of seconds from self
|
20
|
-
#
|
21
|
-
def seconds
|
22
|
-
Duration.new(temporal_unit: :SECONDS, amount: self)
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# Create Duration with unit of milliseconds
|
27
|
-
#
|
28
|
-
# @return [OpenHAB::Core::Duration] Duration with number of milliseconds from self
|
29
|
-
#
|
30
|
-
def milliseconds
|
31
|
-
Duration.new(temporal_unit: :MILLISECONDS, amount: self)
|
32
|
-
end
|
33
|
-
|
34
|
-
#
|
35
|
-
# Create Duration with unit of minutes
|
36
|
-
#
|
37
|
-
# @return [OpenHAB::Core::Duration] Duration with number of minutes from self
|
38
|
-
#
|
39
|
-
def minutes
|
40
|
-
Duration.new(temporal_unit: :MINUTES, amount: self)
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
# Create Duration with unit of hours
|
15
|
+
# Create Duration with the specified unit
|
45
16
|
#
|
46
|
-
# @return [
|
17
|
+
# @return [Java::JavaTime::Duration] Duration with number of units from self
|
47
18
|
#
|
48
|
-
|
49
|
-
Duration.
|
19
|
+
%w[millis seconds minutes hours].each do |unit|
|
20
|
+
define_method(unit) { Java::JavaTime::Duration.public_send("of_#{unit}", self) }
|
50
21
|
end
|
51
22
|
|
52
23
|
alias second seconds
|
53
|
-
alias millisecond
|
54
|
-
alias
|
24
|
+
alias millisecond millis
|
25
|
+
alias milliseconds millis
|
26
|
+
alias ms millis
|
55
27
|
alias minute minutes
|
56
28
|
alias hour hours
|
57
29
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'java'
|
4
|
-
require 'core/duration'
|
5
4
|
require 'core/dsl/time_of_day'
|
6
5
|
require 'core/cron'
|
7
6
|
|
@@ -64,8 +63,10 @@ module OpenHAB
|
|
64
63
|
expression_map = EXPRESSION_MAP[value]
|
65
64
|
expression_map = at_condition(expression_map, at) if at
|
66
65
|
cron(map_to_cron(expression_map))
|
67
|
-
when Duration
|
68
|
-
|
66
|
+
when Java::JavaTime::Duration
|
67
|
+
raise ArgumentError, '"at" cannot be used with duration' if at
|
68
|
+
|
69
|
+
cron(map_to_cron(duration_to_map(value)))
|
69
70
|
else
|
70
71
|
raise ArgumentExpression, 'Unknown interval' unless expression_map
|
71
72
|
end
|
@@ -93,6 +94,28 @@ module OpenHAB
|
|
93
94
|
%i[second minute hour dom month dow].map { |field| map.fetch(field) }.join(' ')
|
94
95
|
end
|
95
96
|
|
97
|
+
#
|
98
|
+
# Convert a Java Duration to a map for the map_to_cron method
|
99
|
+
#
|
100
|
+
# @param duration [Java::JavaTime::Duration] The duration object
|
101
|
+
#
|
102
|
+
# @return [Hash] a map suitable for map_to_cron
|
103
|
+
#
|
104
|
+
def duration_to_map(duration)
|
105
|
+
if duration.to_millis_part.zero? && duration.to_nanos_part.zero? && duration.to_days.zero?
|
106
|
+
%i[second minute hour].each do |unit|
|
107
|
+
to_unit_part = duration.public_send("to_#{unit}s_part")
|
108
|
+
next unless to_unit_part.positive?
|
109
|
+
|
110
|
+
to_unit = duration.public_send("to_#{unit}s")
|
111
|
+
break unless to_unit_part == to_unit
|
112
|
+
|
113
|
+
return EXPRESSION_MAP[unit].merge(unit => "*/#{to_unit}")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
raise ArgumentError, "Cron Expression not supported for duration: #{duration}"
|
117
|
+
end
|
118
|
+
|
96
119
|
#
|
97
120
|
# If an at time is provided, parse that and merge the new fields into the expression.
|
98
121
|
#
|
@@ -274,7 +274,7 @@ module OpenHAB
|
|
274
274
|
process_trigger_delay(mod, inputs)
|
275
275
|
else
|
276
276
|
logger.trace("Item changed to #{state} for #{trigger_delay}, rescheduling timer.")
|
277
|
-
trigger_delay.timer.reschedule(ZonedDateTime.now.plus(
|
277
|
+
trigger_delay.timer.reschedule(ZonedDateTime.now.plus(duration))
|
278
278
|
end
|
279
279
|
end
|
280
280
|
else
|
@@ -4,8 +4,6 @@ require 'java'
|
|
4
4
|
require 'delegate'
|
5
5
|
require 'forwardable'
|
6
6
|
|
7
|
-
require 'core/duration'
|
8
|
-
|
9
7
|
module OpenHAB
|
10
8
|
module Core
|
11
9
|
module DSL
|
@@ -49,7 +47,7 @@ module OpenHAB
|
|
49
47
|
|
50
48
|
semaphore.synchronize do
|
51
49
|
@timer = ScriptExecution.createTimer(
|
52
|
-
ZonedDateTime.now.plus(
|
50
|
+
ZonedDateTime.now.plus(@duration), @block
|
53
51
|
)
|
54
52
|
super(@timer)
|
55
53
|
end
|
@@ -64,7 +62,7 @@ module OpenHAB
|
|
64
62
|
#
|
65
63
|
def reschedule(duration = nil)
|
66
64
|
duration ||= @duration
|
67
|
-
@timer.reschedule(ZonedDateTime.now.plus(
|
65
|
+
@timer.reschedule(ZonedDateTime.now.plus(duration))
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
data/lib/openhab/version.rb
CHANGED
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: 2.13.
|
4
|
+
version: 2.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian O'Connell
|
@@ -76,7 +76,6 @@ files:
|
|
76
76
|
- lib/openhab/core/dsl/timers.rb
|
77
77
|
- lib/openhab/core/dsl/types/quantity.rb
|
78
78
|
- lib/openhab/core/dsl/units.rb
|
79
|
-
- lib/openhab/core/duration.rb
|
80
79
|
- lib/openhab/core/log.rb
|
81
80
|
- lib/openhab/core/patch_load_path.rb
|
82
81
|
- lib/openhab/core/startup_delay.rb
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openhab/core/cron'
|
4
|
-
|
5
|
-
module OpenHAB
|
6
|
-
module Core
|
7
|
-
#
|
8
|
-
# This class represents a duration of time
|
9
|
-
#
|
10
|
-
class Duration
|
11
|
-
include OpenHAB::Core::Cron
|
12
|
-
|
13
|
-
# @return [Array] of supported temperal units (milliseconds, seconds, minutes and hours)
|
14
|
-
TEMPORAL_UNITS = %i[MILLISECONDS SECONDS MINUTES HOURS].freeze
|
15
|
-
|
16
|
-
#
|
17
|
-
# Create a new Duration object
|
18
|
-
#
|
19
|
-
# @param [Symbol] temporal_unit Unit for duration
|
20
|
-
# @param [Integer] amount of that unit
|
21
|
-
#
|
22
|
-
def initialize(temporal_unit:, amount:)
|
23
|
-
unless TEMPORAL_UNITS.include? temporal_unit
|
24
|
-
raise ArgumentError,
|
25
|
-
"Unexpected Temporal Unit: #{temporal_unit}"
|
26
|
-
end
|
27
|
-
|
28
|
-
@temporal_unit = temporal_unit
|
29
|
-
@amount = amount
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# Return a map
|
34
|
-
#
|
35
|
-
# @return [Map] Map with fields representing this duration @see OpenHAB::Core::Cron
|
36
|
-
#
|
37
|
-
def cron_map
|
38
|
-
case @temporal_unit
|
39
|
-
when :SECONDS
|
40
|
-
cron_expression_map.merge(second: "*/#{@amount}")
|
41
|
-
when :MINUTES
|
42
|
-
cron_expression_map.merge(minute: "*/#{@amount}")
|
43
|
-
when :HOURS
|
44
|
-
cron_expression_map.merge(hour: "*/#{@amount}")
|
45
|
-
else
|
46
|
-
raise ArgumentError, "Cron Expression not supported for temporal unit: #{temporal_unit}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# Convert the duration to milliseconds
|
52
|
-
#
|
53
|
-
# @return [Integer] Duration in milliseconds
|
54
|
-
#
|
55
|
-
def to_ms
|
56
|
-
case @temporal_unit
|
57
|
-
when :MILLISECONDS
|
58
|
-
@amount
|
59
|
-
when :SECONDS
|
60
|
-
@amount * 1000
|
61
|
-
when :MINUTES
|
62
|
-
@amount * 1000 * 60
|
63
|
-
when :HOURS
|
64
|
-
@amount * 1000 * 60 * 60
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
#
|
69
|
-
# Return a string representation of the duration
|
70
|
-
#
|
71
|
-
# @return [String] Duration in string
|
72
|
-
#
|
73
|
-
def to_s
|
74
|
-
"#{@amount} #{(@amount == 1) ? @temporal_unit.to_s.downcase.delete_suffix('s') : @temporal_unit.to_s.downcase}"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|