openhab-scripting 4.31.0 → 4.32.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/triggers/command.rb +53 -13
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +32 -13
- 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: 737517891b51326c4c0ab343c448cca3f07a4855ca44222a8564d107d5101cf4
|
4
|
+
data.tar.gz: 0cd4aea92b89e152c7bc7bb0b1e759a22609d833f1022510ec348ff4ad634812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c479724e15cb266f9f797f2e6c5646384f089ff83164890cfd2c6924d1ec0b07011015d4195a4e6de30dfa06da8c2617d2528de4652f8432afd4b2cef4c9bb21
|
7
|
+
data.tar.gz: 6e52ab144a7ba4118c39b9d843ba33a16a9f66903b6f9cdd6fd1cb585febdc121b5934bdd59ae813422c2e6325755302a0285f002427258762ae275214f686ce
|
@@ -29,10 +29,11 @@ module OpenHAB
|
|
29
29
|
combined_commands = Command.combine_commands(command: command, commands: commands)
|
30
30
|
|
31
31
|
Command.flatten_items(items).map do |item|
|
32
|
-
|
33
|
-
|
32
|
+
combined_commands.map do |cmd|
|
33
|
+
logger.states 'Creating received command trigger', item: item, command: cmd
|
34
34
|
|
35
|
-
|
35
|
+
command_trigger.trigger(item: item, command: cmd, attach: attach)
|
36
|
+
end
|
36
37
|
end.flatten
|
37
38
|
end
|
38
39
|
|
@@ -57,6 +58,47 @@ module OpenHAB
|
|
57
58
|
combined_commands
|
58
59
|
end
|
59
60
|
|
61
|
+
#
|
62
|
+
# Create a received command trigger
|
63
|
+
#
|
64
|
+
# @param [Object] item item to create trigger for
|
65
|
+
# @param [Object] command to check against
|
66
|
+
# @param [Object] attach attachment
|
67
|
+
#
|
68
|
+
# @return [Trigger] OpenHAB triggers
|
69
|
+
#
|
70
|
+
def trigger(item:, command:, attach:)
|
71
|
+
case command
|
72
|
+
when Range then range_trigger(item: item, command: command, attach: attach)
|
73
|
+
when Proc then proc_trigger(item: item, command: command, attach: attach)
|
74
|
+
else command_trigger(item: item, command: command, attach: attach)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Creates a trigger with a range condition on the 'command' field
|
80
|
+
# @param [Object] item to create changed trigger on
|
81
|
+
# @param [Object] command to restrict trigger to
|
82
|
+
# @param [Object] attach to trigger
|
83
|
+
# @return [Trigger] OpenHAB trigger
|
84
|
+
#
|
85
|
+
def range_trigger(item:, command:, attach:)
|
86
|
+
command_range, * = Conditions::Proc.range_procs(command)
|
87
|
+
proc_trigger(item: item, command: command_range, attach: attach)
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Creates a trigger with a proc condition on the 'command' field
|
92
|
+
# @param [Object] item to create changed trigger on
|
93
|
+
# @param [Object] command to restrict trigger to
|
94
|
+
# @param [Object] attach to trigger
|
95
|
+
# @return [Trigger] OpenHAB trigger
|
96
|
+
#
|
97
|
+
def proc_trigger(item:, command:, attach:)
|
98
|
+
conditions = Conditions::Proc.new(command: command)
|
99
|
+
command_trigger(item: item, command: nil, attach: attach, conditions: conditions)
|
100
|
+
end
|
101
|
+
|
60
102
|
#
|
61
103
|
# Create a received trigger based on item type
|
62
104
|
#
|
@@ -64,16 +106,14 @@ module OpenHAB
|
|
64
106
|
# @param [Object] item to create trigger for
|
65
107
|
#
|
66
108
|
#
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
append_trigger(type: type, config: config, attach: attach)
|
76
|
-
end
|
109
|
+
def command_trigger(item:, command:, attach: nil, conditions: nil)
|
110
|
+
type, config = if item.is_a? OpenHAB::DSL::Items::GroupItem::GroupMembers
|
111
|
+
group(group: item)
|
112
|
+
else
|
113
|
+
item(item: item)
|
114
|
+
end
|
115
|
+
config['command'] = command.to_s unless command.nil?
|
116
|
+
append_trigger(type: type, config: config, attach: attach, conditions: conditions)
|
77
117
|
end
|
78
118
|
|
79
119
|
private
|
@@ -38,9 +38,9 @@ module OpenHAB
|
|
38
38
|
#
|
39
39
|
def self.range_proc(range)
|
40
40
|
logger.trace("Creating range proc for #{range}")
|
41
|
-
lambda do |
|
42
|
-
logger.trace("Range proc checking if #{
|
43
|
-
range.cover?
|
41
|
+
lambda do |val|
|
42
|
+
logger.trace("Range proc checking if #{val} is in #{range}")
|
43
|
+
range.cover? val
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -77,9 +77,10 @@ module OpenHAB
|
|
77
77
|
# @param [Proc] from Proc to check against from value
|
78
78
|
# @param [Proc] to Proc to check against to value
|
79
79
|
#
|
80
|
-
def initialize(from: nil, to: nil)
|
80
|
+
def initialize(from: nil, to: nil, command: nil)
|
81
81
|
@from = from
|
82
82
|
@to = to
|
83
|
+
@command = command
|
83
84
|
end
|
84
85
|
|
85
86
|
#
|
@@ -88,7 +89,18 @@ module OpenHAB
|
|
88
89
|
#
|
89
90
|
def process(mod:, inputs:) # rubocop:disable Lint/UnusedMethodArgument - mod is unused here but required
|
90
91
|
logger.trace("Checking #{inputs} against condition trigger #{self}")
|
91
|
-
yield if
|
92
|
+
yield if check_procs(inputs: inputs)
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# Check if command condition match the proc
|
97
|
+
# @param [Hash] inputs from trigger must be supplied if state is not supplied
|
98
|
+
# @return [true/false] depending on if from is set and matches supplied conditions
|
99
|
+
#
|
100
|
+
def check_command(inputs: nil)
|
101
|
+
command = input_state(inputs, 'command')
|
102
|
+
logger.trace "Checking command(#{@command}) against command(#{command})"
|
103
|
+
check_proc(proc: @command, value: command)
|
92
104
|
end
|
93
105
|
|
94
106
|
#
|
@@ -100,7 +112,7 @@ module OpenHAB
|
|
100
112
|
def check_from(inputs: nil, state: nil)
|
101
113
|
state ||= input_state(inputs, 'oldState')
|
102
114
|
logger.trace "Checking from(#{@from}) against state(#{state})"
|
103
|
-
check_proc(proc: @from,
|
115
|
+
check_proc(proc: @from, value: state)
|
104
116
|
end
|
105
117
|
|
106
118
|
#
|
@@ -112,27 +124,34 @@ module OpenHAB
|
|
112
124
|
def check_to(inputs: nil, state: nil)
|
113
125
|
state ||= input_state(inputs, 'newState', 'state')
|
114
126
|
logger.trace "Checking to(#{@to}) against state(#{state})"
|
115
|
-
check_proc(proc: @to,
|
127
|
+
check_proc(proc: @to, value: state)
|
116
128
|
end
|
117
129
|
|
118
130
|
# Describe the Proc Condition as a string
|
119
131
|
# @return [String] string representation of proc condition
|
120
132
|
#
|
121
133
|
def to_s
|
122
|
-
"From:(#{@from}) To:(#{@to})"
|
134
|
+
"From:(#{@from}) To:(#{@to}) Command:(#{@command})"
|
123
135
|
end
|
124
136
|
|
125
137
|
private
|
126
138
|
|
139
|
+
#
|
140
|
+
# Check all procs
|
141
|
+
# @param [Hash] inputs from event
|
142
|
+
# @return [true/false] true if all procs return true, false otherwise
|
143
|
+
def check_procs(inputs:)
|
144
|
+
check_from(inputs: inputs) && check_to(inputs: inputs) && check_command(inputs: inputs)
|
145
|
+
end
|
146
|
+
|
127
147
|
# Check if a field matches the proc condition
|
128
148
|
# @param [Proc] proc to call
|
129
|
-
# @param [Hash]
|
130
|
-
# @param [Array] fields array of fields to extract from inputs, first one found is passed to proc
|
149
|
+
# @param [Hash] value to check
|
131
150
|
# @return [true,false] true if proc is nil or proc.call returns true, false otherwise
|
132
|
-
def check_proc(proc:,
|
133
|
-
return true if proc.nil? || proc.call(
|
151
|
+
def check_proc(proc:, value:)
|
152
|
+
return true if proc.nil? || proc.call(value)
|
134
153
|
|
135
|
-
logger.trace("Skipped execution of rule because
|
154
|
+
logger.trace("Skipped execution of rule because value #{value} evaluated false for (#{proc})")
|
136
155
|
false
|
137
156
|
end
|
138
157
|
|
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.32.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-01-
|
11
|
+
date: 2022-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|