openhab-scripting 5.6.0 → 5.7.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/core/actions/audio.rb +5 -2
- data/lib/openhab/core/items/registry.rb +1 -1
- data/lib/openhab/core/items/semantics.rb +12 -19
- data/lib/openhab/core/provider.rb +1 -1
- data/lib/openhab/core/sitemaps/provider.rb +132 -0
- data/lib/openhab/core/things/proxy.rb +2 -1
- data/lib/openhab/core/types/date_time_type.rb +2 -1
- data/lib/openhab/core/types/open_closed_type.rb +2 -1
- data/lib/openhab/core/types/quantity_type.rb +45 -35
- data/lib/openhab/core/types/string_type.rb +1 -1
- data/lib/openhab/core/types/up_down_type.rb +2 -1
- data/lib/openhab/core/value_cache.rb +5 -4
- data/lib/openhab/core_ext/java/duration.rb +2 -1
- data/lib/openhab/core_ext/java/local_time.rb +8 -6
- data/lib/openhab/core_ext/java/month_day.rb +2 -1
- data/lib/openhab/core_ext/java/period.rb +1 -1
- data/lib/openhab/core_ext/ruby/numeric.rb +1 -0
- data/lib/openhab/dsl/items/builder.rb +3 -1
- data/lib/openhab/dsl/rules/builder.rb +54 -23
- data/lib/openhab/dsl/rules/triggers/conditions/generic.rb +1 -1
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +33 -14
- data/lib/openhab/dsl/sitemaps/builder.rb +942 -0
- data/lib/openhab/dsl/things/builder.rb +4 -2
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +5 -0
- data/lib/openhab/osgi.rb +1 -1
- data/lib/openhab/rspec/karaf.rb +5 -2
- data/lib/openhab/rspec/openhab/core/actions.rb +0 -3
- metadata +11 -23
@@ -26,16 +26,15 @@ module OpenHAB
|
|
26
26
|
# @return [Hash] Map with symbols for :seconds, :minute, :hour, :dom, :month, :dow
|
27
27
|
# configured to fire every second
|
28
28
|
#
|
29
|
-
CRON_EXPRESSION_MAP =
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}.freeze
|
29
|
+
CRON_EXPRESSION_MAP = {
|
30
|
+
second: "*",
|
31
|
+
minute: "*",
|
32
|
+
hour: "*",
|
33
|
+
dom: "?",
|
34
|
+
month: "*",
|
35
|
+
dow: "?",
|
36
|
+
year: "*"
|
37
|
+
}.freeze
|
39
38
|
private_constant :CRON_EXPRESSION_MAP
|
40
39
|
|
41
40
|
# @return [Hash] Map of days of the week from symbols to to openHAB cron strings
|
@@ -52,7 +51,6 @@ module OpenHAB
|
|
52
51
|
|
53
52
|
# @return [Hash] Converts the DAY_OF_WEEK_MAP to map used by Cron Expression
|
54
53
|
DAY_OF_WEEK_EXPRESSION_MAP = DAY_OF_WEEK_MAP.transform_values { |v| CRON_EXPRESSION_MAP.merge(dow: v) }
|
55
|
-
|
56
54
|
private_constant :DAY_OF_WEEK_EXPRESSION_MAP
|
57
55
|
|
58
56
|
# @return [Hash] Create a set of cron expressions based on different time intervals
|
@@ -65,9 +63,12 @@ module OpenHAB
|
|
65
63
|
month: CRON_EXPRESSION_MAP.merge(second: "0", minute: "0", hour: "0", dom: "1"),
|
66
64
|
year: CRON_EXPRESSION_MAP.merge(second: "0", minute: "0", hour: "0", dom: "1", month: "1")
|
67
65
|
}.merge(DAY_OF_WEEK_EXPRESSION_MAP).freeze
|
68
|
-
|
69
66
|
private_constant :EXPRESSION_MAP
|
70
67
|
|
68
|
+
# @return [Hash] Translate cron field names to expression keys
|
69
|
+
FIELD_TO_EXPRESSION_KEY = Hash.new { |_, key| key }.merge({ dow: :week, dom: :day })
|
70
|
+
private_constant :FIELD_TO_EXPRESSION_KEY
|
71
|
+
|
71
72
|
#
|
72
73
|
# Create a cron map from a duration
|
73
74
|
#
|
@@ -124,10 +125,28 @@ module OpenHAB
|
|
124
125
|
"unknown keyword#{"s" if extra_fields.size > 1}: #{extra_fields.map(&:inspect).join(", ")}"
|
125
126
|
end
|
126
127
|
|
127
|
-
fields = fields.
|
128
|
+
fields = fields.to_h do |key, value|
|
129
|
+
if value.is_a?(Range)
|
130
|
+
if value.exclude_end?
|
131
|
+
raise ArgumentError,
|
132
|
+
"Range must be inclusive for '#{key}'. Try '#{value.begin}..#{value.end}' instead"
|
133
|
+
end
|
134
|
+
|
135
|
+
unless value.begin && value.end
|
136
|
+
raise ArgumentError,
|
137
|
+
"Range must have a beginning and ending for '#{key}'"
|
138
|
+
end
|
139
|
+
|
140
|
+
[key, "#{value.begin.to_s.upcase}-#{value.end.to_s.upcase}".delete(" ")]
|
141
|
+
else
|
142
|
+
[key, value.to_s.delete(" ").upcase]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
# convert fields' key dow->week, dom->day to look into EXPRESSION_MAP
|
146
|
+
fields_expression = fields.transform_keys { |key| FIELD_TO_EXPRESSION_KEY[key] }
|
128
147
|
# find the first expression map that has a field from fields.
|
129
148
|
# this ensure more-specific fields get set to 0, not *
|
130
|
-
base_key = EXPRESSION_MAP.keys.find { |field, _|
|
149
|
+
base_key = EXPRESSION_MAP.keys.find { |field, _| fields_expression.key?(field) }
|
131
150
|
base_expression = EXPRESSION_MAP[base_key]
|
132
151
|
expression_map = base_expression.merge(fields)
|
133
152
|
|