openhab-scripting 4.30.4 → 4.32.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/dsl/items/color_item.rb +0 -23
- data/lib/openhab/dsl/rules/triggers/command.rb +53 -13
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +32 -13
- data/lib/openhab/dsl/types/hsb_type.rb +27 -2
- data/lib/openhab/dsl/types/string_type.rb +1 -1
- 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: 89c274fd9901e8ccc5d1890a7cf41dbf17ab6d79eb2b798b4e86dde9101cdd11
|
4
|
+
data.tar.gz: dea8df6ebfb5b572745df0f4ab2b33ac251d74f0fe694ca4759e227f0588b4c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ddee7681015930c085afe7fa68a6c6b913e414097d8da32ed9519b2d701ad71699f9bc585186f9cf229fb67633f3781995b04099290b67dd781ba9d5e167e93
|
7
|
+
data.tar.gz: a8d606a0b5c1fe02822955ad03fd6affbf111a774581cb1706ab7661af874ef907004c73e21bfa445f16780e27f65090b140ab83487b3dc2b6729ac1fba01b03
|
@@ -54,29 +54,6 @@ module OpenHAB
|
|
54
54
|
super
|
55
55
|
end
|
56
56
|
|
57
|
-
#
|
58
|
-
# Convert the ColorItem to a hash
|
59
|
-
# @param [:hsb, :rgb] format for hash
|
60
|
-
# @return [Hash] in requested format
|
61
|
-
def to_h(format = :hsb)
|
62
|
-
values = to_a(format)
|
63
|
-
keys = (format == :hsb ? %i[hue saturation brightness] : %i[red green blue])
|
64
|
-
keys.zip(values).to_h
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
# Convert the ColorItem to an array of values
|
69
|
-
# @param [:hsb, :rgb] format for elements in the array
|
70
|
-
# @return [Array] of ColorItem components in requested format
|
71
|
-
def to_a(format = :hsb)
|
72
|
-
case format
|
73
|
-
when :hsb then [hue, saturation, brightness]
|
74
|
-
when :rgb then [red, green, blue].map(&:to_byte)
|
75
|
-
else
|
76
|
-
raise ArgumentError, "Unsupported format #{format}"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
57
|
private
|
81
58
|
|
82
59
|
# Mapping of hash values sets to conversion methods
|
@@ -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.
|
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
|
|
@@ -105,13 +105,15 @@ module OpenHAB
|
|
105
105
|
#
|
106
106
|
# nil is returned if the two values are incomparable
|
107
107
|
#
|
108
|
-
def <=>(other)
|
108
|
+
def <=>(other) # rubocop:disable Metrics
|
109
109
|
logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
|
110
110
|
if other.is_a?(Items::ColorItem) ||
|
111
111
|
(other.is_a?(Items::GroupItem) && other.base_item.is_a?(ColorItem))
|
112
|
-
return
|
112
|
+
return nil unless other.state?
|
113
113
|
|
114
114
|
self <=> other.state
|
115
|
+
elsif other.is_a?(HSBType)
|
116
|
+
to_a <=> other.to_a
|
115
117
|
elsif other.respond_to?(:to_str)
|
116
118
|
self <=> HSBType.new(other)
|
117
119
|
else
|
@@ -178,6 +180,29 @@ module OpenHAB
|
|
178
180
|
"#{hue},#{saturation},#{brightness}"
|
179
181
|
end
|
180
182
|
|
183
|
+
#
|
184
|
+
# Convert the ColorItem to a hash
|
185
|
+
# @param [:hsb, :rgb] format for hash
|
186
|
+
# @return [Hash] in requested format
|
187
|
+
def to_h(format = :hsb)
|
188
|
+
values = to_a(format)
|
189
|
+
keys = (format == :hsb ? %i[hue saturation brightness] : %i[red green blue])
|
190
|
+
keys.zip(values).to_h
|
191
|
+
end
|
192
|
+
|
193
|
+
#
|
194
|
+
# Convert the ColorItem to an array of values
|
195
|
+
# @param [:hsb, :rgb] format for elements in the array
|
196
|
+
# @return [Array] of ColorItem components in requested format
|
197
|
+
def to_a(format = :hsb)
|
198
|
+
case format
|
199
|
+
when :hsb then [hue, saturation, brightness]
|
200
|
+
when :rgb then [red, green, blue].map(&:to_byte)
|
201
|
+
else
|
202
|
+
raise ArgumentError, "Unsupported format #{format}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
181
206
|
# @!attribute [r] saturation
|
182
207
|
# @return [PercentType]
|
183
208
|
|
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.1
|
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-
|
11
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|