openhab-scripting 4.33.1 → 4.35.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/rules/automation_rule.rb +3 -1
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +47 -6
- data/lib/openhab/dsl/states.rb +12 -0
- data/lib/openhab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a64a452ca8ff7c31d08ceed61a6e2d466250438365ea71c4de1c968b33198f8c
|
4
|
+
data.tar.gz: 31e41c724ad7b7871e913044259f5d3736130d5634d2f9301b98c7093b97f804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cb0812ede637a43674c260dce7124a38fce48c0940cae506125f9c5d6c3ebc3fa08d229a92155060fc5eb816b9e946874cebbc6e0d9654b3405e75879b1dbfd
|
7
|
+
data.tar.gz: cf04212fd7483729494be64840f74c9d6d5241c35c87e4c46f7207c8a007a9d0c537a8379481172d8395cf27c74eae5764d2d2e65ef984d7478104778e19c4a0
|
@@ -42,7 +42,7 @@ module OpenHAB
|
|
42
42
|
@guard = config.guard
|
43
43
|
# Convert between to correct range or nil if not set
|
44
44
|
between = config.between&.then { between(config.between) }
|
45
|
-
@between = between
|
45
|
+
@between = between
|
46
46
|
@trigger_conditions = config.trigger_conditions
|
47
47
|
@attachments = config.attachments
|
48
48
|
end
|
@@ -153,6 +153,8 @@ module OpenHAB
|
|
153
153
|
# Loggging inflates method length
|
154
154
|
def check_guards(event:)
|
155
155
|
if @guard.should_run? event
|
156
|
+
return true if @between.nil?
|
157
|
+
|
156
158
|
now = Time.now
|
157
159
|
return true if @between.cover? now
|
158
160
|
|
@@ -13,16 +13,19 @@ module OpenHAB
|
|
13
13
|
#
|
14
14
|
# Create a rule that executes at the specified interval
|
15
15
|
#
|
16
|
-
# @param [Object] value Symbol or
|
16
|
+
# @param [Object] value String, Symbol, Duration, or MonthDay to execute this rule
|
17
17
|
# @param [Object] at TimeOfDay or String representing TimeOfDay in which to execute rule
|
18
18
|
# @param [Object] attach object to be attached to the trigger
|
19
19
|
#
|
20
20
|
#
|
21
21
|
def every(value, at: nil, attach: nil)
|
22
|
+
return every(MonthDay.parse(value), at: at, attach: attach) if value.is_a? String
|
23
|
+
|
22
24
|
cron_expression = case value
|
23
25
|
when Symbol then Cron.from_symbol(value, at)
|
24
26
|
when Java::JavaTime::Duration then Cron.from_duration(value, at)
|
25
|
-
|
27
|
+
when Java::JavaTime::MonthDay then Cron.from_monthday(value, at)
|
28
|
+
else raise ArgumentError, 'Unknown interval'
|
26
29
|
end
|
27
30
|
cron(cron_expression, attach: attach)
|
28
31
|
end
|
@@ -32,8 +35,18 @@ module OpenHAB
|
|
32
35
|
#
|
33
36
|
# @param [String] expression OpenHAB style cron expression
|
34
37
|
# @param [Object] attach object to be attached to the trigger
|
38
|
+
# @param [Hash] elements cron expression elements (second, minute, hour, dom, month, dow, year)
|
35
39
|
#
|
36
|
-
def cron(expression, attach: nil)
|
40
|
+
def cron(expression = nil, attach: nil, **fields)
|
41
|
+
if fields.any?
|
42
|
+
raise ArgumentError, 'Cron elements cannot be used with a cron expression' if expression
|
43
|
+
|
44
|
+
cron_expression = Cron.from_fields(fields)
|
45
|
+
return cron(cron_expression, attach: attach)
|
46
|
+
end
|
47
|
+
|
48
|
+
raise ArgumentError, 'Missing cron expression or elements' unless expression
|
49
|
+
|
37
50
|
cron = Cron.new(rule_triggers: @rule_triggers)
|
38
51
|
cron.trigger(config: { 'cronExpression' => expression }, attach: attach)
|
39
52
|
end
|
@@ -59,7 +72,8 @@ module OpenHAB
|
|
59
72
|
hour: '*',
|
60
73
|
dom: '?',
|
61
74
|
month: '*',
|
62
|
-
dow: '?'
|
75
|
+
dow: '?',
|
76
|
+
year: '*'
|
63
77
|
}.freeze
|
64
78
|
private_constant :CRON_EXPRESSION_MAP
|
65
79
|
|
@@ -96,7 +110,7 @@ module OpenHAB
|
|
96
110
|
#
|
97
111
|
# Create a cron map from a duration
|
98
112
|
#
|
99
|
-
# @param [
|
113
|
+
# @param [Java::JavaTime::Duration] duration
|
100
114
|
# @param [Object] at TimeOfDay or String representing time of day
|
101
115
|
#
|
102
116
|
# @return [Hash] map describing cron expression
|
@@ -107,6 +121,20 @@ module OpenHAB
|
|
107
121
|
map_to_cron(duration_to_map(duration))
|
108
122
|
end
|
109
123
|
|
124
|
+
#
|
125
|
+
# Create a cron map from a MonthDay
|
126
|
+
#
|
127
|
+
# @param [Java::JavaTime::MonthDay] month_day
|
128
|
+
# @param [Object] at TimeOfDay or String representing time of day
|
129
|
+
#
|
130
|
+
# @return [Hash] map describing cron expression
|
131
|
+
#
|
132
|
+
def self.from_monthday(monthday, at)
|
133
|
+
expression_map = EXPRESSION_MAP[:day].merge(month: monthday.month_value, dom: monthday.day_of_month)
|
134
|
+
expression_map = at_condition(expression_map, at) if at
|
135
|
+
map_to_cron(expression_map)
|
136
|
+
end
|
137
|
+
|
110
138
|
#
|
111
139
|
# Create a cron map from a symbol
|
112
140
|
#
|
@@ -121,6 +149,19 @@ module OpenHAB
|
|
121
149
|
map_to_cron(expression_map)
|
122
150
|
end
|
123
151
|
|
152
|
+
#
|
153
|
+
# Create a cron map from cron elements
|
154
|
+
#
|
155
|
+
# @param [Hash] elements Cron fields (second, minute, hour, dom, month, dow, year)
|
156
|
+
#
|
157
|
+
# @return [Hash] map describing cron expression
|
158
|
+
#
|
159
|
+
def self.from_fields(fields)
|
160
|
+
fields = fields.transform_values { |value| value.to_s.gsub(/\s+/, '') }
|
161
|
+
expression_map = CRON_EXPRESSION_MAP.merge(fields)
|
162
|
+
map_to_cron(expression_map)
|
163
|
+
end
|
164
|
+
|
124
165
|
#
|
125
166
|
# Map cron expression to to cron string
|
126
167
|
#
|
@@ -129,7 +170,7 @@ module OpenHAB
|
|
129
170
|
# @return [String] OpenHAB cron string
|
130
171
|
#
|
131
172
|
def self.map_to_cron(map)
|
132
|
-
%i[second minute hour dom month dow].map { |field| map.fetch(field) }.join(' ')
|
173
|
+
%i[second minute hour dom month dow year].map { |field| map.fetch(field) }.join(' ')
|
133
174
|
end
|
134
175
|
|
135
176
|
#
|
data/lib/openhab/dsl/states.rb
CHANGED
@@ -28,6 +28,18 @@ module OpenHAB
|
|
28
28
|
end
|
29
29
|
states
|
30
30
|
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Check if all the given items have a state (not UNDEF or NULL)
|
34
|
+
#
|
35
|
+
# @param [Array] items whose state must be non-nil
|
36
|
+
# @param [<Type>] check_things when true, also ensures that all linked things are online
|
37
|
+
#
|
38
|
+
# @return [Boolean] true if all the items have a state, false otherwise
|
39
|
+
#
|
40
|
+
def state?(*items, things: false)
|
41
|
+
items.flatten.all? { |item| (!things || item.things.all?(&:online?)) && item.state? }
|
42
|
+
end
|
31
43
|
end
|
32
44
|
|
33
45
|
module Support
|
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.35.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-03-
|
11
|
+
date: 2022-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|