openhab-scripting 4.14.1 → 4.16.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/items/generic_item.rb +19 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +20 -10
- data/lib/openhab/dsl/rules/rule.rb +1 -1
- data/lib/openhab/dsl/rules/rule_config.rb +1 -0
- data/lib/openhab/dsl/rules/triggers/generic.rb +29 -0
- data/lib/openhab/dsl/rules/triggers/trigger.rb +1 -0
- data/lib/openhab/dsl/things.rb +13 -4
- data/lib/openhab/dsl/types/quantity_type.rb +1 -5
- data/lib/openhab/dsl/types/type.rb +1 -1
- data/lib/openhab/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f765fc75455c9aace6d355e897477c727dcdc7e826bb3b16824979c2cf882f56
|
4
|
+
data.tar.gz: cfb0262989931a22e637e1e2f625ca3f5256da37587d8400b10f68ece4b6c358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b0f1896dd66a599449dd96b061f38cc6ad92694bd9502bf14b5b6767330d8eebd714ea41536bb49f730a6fdb9c48e64a04b77c7cb9d54e72d61d617336c2d9
|
7
|
+
data.tar.gz: ff13507c8f80c3f7dbae3089d8ef322e0c0fbaccf835cdb80ea58ea4e595ac8e92b2e440cf4a2c8c2bf9c9401f9da7f98219857ed88ead80adbe853f3b2f2b76
|
@@ -131,6 +131,25 @@ module OpenHAB
|
|
131
131
|
group_names.map { |name| Groups.groups[name] }
|
132
132
|
end
|
133
133
|
|
134
|
+
# Return the item's thing if this item is linked with a thing. If an item is linked to more than one thing,
|
135
|
+
# this method only returns the first thing.
|
136
|
+
#
|
137
|
+
# @return [Thing] The thing associated with this item or nil
|
138
|
+
def thing
|
139
|
+
all_linked_things.first
|
140
|
+
end
|
141
|
+
alias linked_thing thing
|
142
|
+
|
143
|
+
# Returns all of the item's linked things.
|
144
|
+
#
|
145
|
+
# @return [Array] An array of things or an empty array
|
146
|
+
def things
|
147
|
+
registry = OpenHAB::Core::OSGI.service('org.openhab.core.thing.link.ItemChannelLinkRegistry')
|
148
|
+
channels = registry.get_bound_channels(name).to_a
|
149
|
+
channels.map(&:thing_uid).uniq.map { |tuid| Object.things[tuid] }
|
150
|
+
end
|
151
|
+
alias all_linked_things things
|
152
|
+
|
134
153
|
#
|
135
154
|
# Check equality without type conversion
|
136
155
|
#
|
@@ -87,7 +87,7 @@ module OpenHAB
|
|
87
87
|
# @return [Queue] <description>
|
88
88
|
#
|
89
89
|
def create_queue(inputs)
|
90
|
-
case check_guards(event: inputs
|
90
|
+
case check_guards(event: extract_event(inputs))
|
91
91
|
when true
|
92
92
|
@run_queue.dup.grep_v(RuleConfig::Otherwise)
|
93
93
|
when false
|
@@ -95,13 +95,30 @@ module OpenHAB
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
#
|
99
|
+
# Extract the event object from inputs
|
100
|
+
# and merge other inputs keys/values into the event
|
101
|
+
#
|
102
|
+
# @param [Map] inputs rule inputs
|
103
|
+
#
|
104
|
+
# @return [Object] event object
|
105
|
+
#
|
106
|
+
def extract_event(inputs)
|
107
|
+
event = inputs&.dig('event')
|
108
|
+
unless event
|
109
|
+
event = Struct.new(:event, :attachment, :command).new
|
110
|
+
event.command = inputs&.dig('command')
|
111
|
+
end
|
112
|
+
add_attachment(event, inputs)
|
113
|
+
end
|
114
|
+
|
98
115
|
#
|
99
116
|
# Get the trigger_id for the trigger that caused the rule creation
|
100
117
|
#
|
101
118
|
# @return [Hash] Input hash potentially containing trigger id
|
102
119
|
#
|
103
120
|
def trigger_id(inputs)
|
104
|
-
inputs&.
|
121
|
+
inputs&.dig('module')
|
105
122
|
end
|
106
123
|
|
107
124
|
#
|
@@ -128,10 +145,6 @@ module OpenHAB
|
|
128
145
|
attachment = @attachments[trigger_id(inputs)]
|
129
146
|
return event unless attachment
|
130
147
|
|
131
|
-
# Some events, like those from cron triggers don't have an event
|
132
|
-
# so an event is created
|
133
|
-
event ||= Struct.new(:event).new
|
134
|
-
|
135
148
|
event.attachment = attachment
|
136
149
|
event
|
137
150
|
end
|
@@ -301,11 +314,9 @@ module OpenHAB
|
|
301
314
|
# @param [Map] inputs OpenHAB map object describing rule trigge
|
302
315
|
#
|
303
316
|
#
|
304
|
-
# rubocop:disable Metrics/MethodLength
|
305
317
|
# No logical way to break this method up
|
306
318
|
def process_queue(run_queue, mod, inputs)
|
307
|
-
event = inputs
|
308
|
-
event = add_attachment(event, inputs)
|
319
|
+
event = extract_event(inputs)
|
309
320
|
|
310
321
|
while (task = run_queue.shift)
|
311
322
|
if task.is_a? RuleConfig::Delay
|
@@ -317,7 +328,6 @@ module OpenHAB
|
|
317
328
|
rescue StandardError => e
|
318
329
|
print_backtrace(e)
|
319
330
|
end
|
320
|
-
# rubocop:enable Metrics/MethodLength
|
321
331
|
|
322
332
|
#
|
323
333
|
# Dispatch execution block tasks to different methods
|
@@ -38,7 +38,6 @@ module OpenHAB
|
|
38
38
|
config.guard = Guard::Guard.new(only_if: config.only_if, not_if: config.not_if)
|
39
39
|
logger.trace { config.inspect }
|
40
40
|
process_rule_config(config)
|
41
|
-
config
|
42
41
|
rescue StandardError => e
|
43
42
|
re_raise_with_backtrace(e)
|
44
43
|
end
|
@@ -89,6 +88,7 @@ module OpenHAB
|
|
89
88
|
Rules.script_rules << rule
|
90
89
|
add_rule(rule)
|
91
90
|
rule.execute(nil, { 'event' => Struct.new(:attachment).new(config.start_attachment) }) if config.on_start?
|
91
|
+
rule
|
92
92
|
end
|
93
93
|
|
94
94
|
#
|
@@ -8,6 +8,7 @@ require 'openhab/dsl/rules/triggers/changed'
|
|
8
8
|
require 'openhab/dsl/rules/triggers/channel'
|
9
9
|
require 'openhab/dsl/rules/triggers/command'
|
10
10
|
require 'openhab/dsl/rules/triggers/updated'
|
11
|
+
require 'openhab/dsl/rules/triggers/generic'
|
11
12
|
require 'openhab/dsl/rules/guard'
|
12
13
|
require 'openhab/core/entity_lookup'
|
13
14
|
require 'openhab/dsl/between'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openhab/log/logger'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module Rules
|
8
|
+
#
|
9
|
+
# Module holds rule triggers
|
10
|
+
#
|
11
|
+
module Triggers
|
12
|
+
include OpenHAB::Log
|
13
|
+
|
14
|
+
#
|
15
|
+
# Create a generic trigger given the trigger type uid and a configuration hash
|
16
|
+
#
|
17
|
+
# @param [Type] Trigger type UID
|
18
|
+
# @param [Configuration] A hash containing the trigger configuration entries
|
19
|
+
#
|
20
|
+
# @return [Trigger] Trigger object
|
21
|
+
#
|
22
|
+
def trigger(type, attach: nil, **configuration)
|
23
|
+
logger.trace("Creating a generic trigger for type(#{type}) with configuration(#{configuration})")
|
24
|
+
append_trigger(type, configuration, attach: attach)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -48,6 +48,7 @@ module OpenHAB
|
|
48
48
|
#
|
49
49
|
def append_trigger(type, config, attach: nil)
|
50
50
|
logger.trace("Creating trigger of type #{type} for #{config}")
|
51
|
+
config.transform_keys!(&:to_s)
|
51
52
|
trigger = Trigger.trigger(type: type, config: config)
|
52
53
|
@attachments[trigger.id] = attach if attach
|
53
54
|
@triggers << trigger
|
data/lib/openhab/dsl/things.rb
CHANGED
@@ -83,11 +83,11 @@ module OpenHAB
|
|
83
83
|
include LazyArray
|
84
84
|
include Singleton
|
85
85
|
|
86
|
-
# Gets a specific thing by name in the format binding_id:type_id:thing_id
|
87
|
-
# @return Thing specified by name or nil if name does not exist in thing registry
|
86
|
+
# Gets a specific thing by name in the format binding_id:type_id:thing_id or via the ThingUID
|
87
|
+
# @return Thing specified by name/UID or nil if name/UID does not exist in thing registry
|
88
88
|
def [](uid)
|
89
|
-
|
90
|
-
thing = $things.get(
|
89
|
+
uid = generate_thing_uid(uid) unless uid.is_a?(org.openhab.core.thing.ThingUID)
|
90
|
+
thing = $things.get(uid) # rubocop: disable Style/GlobalVars
|
91
91
|
return unless thing
|
92
92
|
|
93
93
|
logger.trace("Retrieved Thing(#{thing}) from registry for uid: #{uid}")
|
@@ -100,6 +100,15 @@ module OpenHAB
|
|
100
100
|
def to_a
|
101
101
|
$things.getAll.map { |thing| Thing.new(thing) } # rubocop: disable Style/GlobalVars
|
102
102
|
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
# Returns a ThingUID given a string like object
|
107
|
+
#
|
108
|
+
# @return ThingUID generated by given name
|
109
|
+
def generate_thing_uid(uid)
|
110
|
+
org.openhab.core.thing.ThingUID.new(*uid.split(':'))
|
111
|
+
end
|
103
112
|
end
|
104
113
|
|
105
114
|
#
|
@@ -30,11 +30,7 @@ module OpenHAB
|
|
30
30
|
#
|
31
31
|
# @return [QuantityType] This quantity converted to another unit
|
32
32
|
#
|
33
|
-
|
34
|
-
other = org.openhab.core.types.util.UnitUtils.parse_unit(other) if other.is_a?(String)
|
35
|
-
|
36
|
-
to_unit(other)
|
37
|
-
end
|
33
|
+
alias | to_unit
|
38
34
|
|
39
35
|
#
|
40
36
|
# Comparison
|
@@ -27,7 +27,7 @@ module OpenHAB
|
|
27
27
|
#
|
28
28
|
def coerce(other)
|
29
29
|
logger.trace("Coercing #{self} (#{self.class}) as a request from #{other.class}")
|
30
|
-
return [other.as(self.class), self] if other.is_a?(Type)
|
30
|
+
return [other.as(self.class), self] if other.is_a?(Type) && other.respond_to?(:as)
|
31
31
|
end
|
32
32
|
|
33
33
|
#
|
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.16.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: 2021-11-
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/openhab/dsl/rules/triggers/channel.rb
|
104
104
|
- lib/openhab/dsl/rules/triggers/command.rb
|
105
105
|
- lib/openhab/dsl/rules/triggers/cron.rb
|
106
|
+
- lib/openhab/dsl/rules/triggers/generic.rb
|
106
107
|
- lib/openhab/dsl/rules/triggers/trigger.rb
|
107
108
|
- lib/openhab/dsl/rules/triggers/updated.rb
|
108
109
|
- lib/openhab/dsl/states.rb
|