openhab-scripting 5.12.0 → 5.13.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/{uid.rb → abstract_uid.rb} +1 -1
- data/lib/openhab/core/sitemaps/provider.rb +35 -11
- data/lib/openhab/core/things/abstract_description_type.rb +21 -0
- data/lib/openhab/core/things/channel.rb +9 -0
- data/lib/openhab/core/things/channel_definition.rb +61 -0
- data/lib/openhab/core/things/channel_group_definition.rb +51 -0
- data/lib/openhab/core/things/channel_group_type.rb +45 -0
- data/lib/openhab/core/things/channel_group_type_uid.rb +37 -0
- data/lib/openhab/core/things/channel_group_uid.rb +25 -0
- data/lib/openhab/core/things/channel_type.rb +74 -0
- data/lib/openhab/core/things/channel_type_uid.rb +53 -0
- data/lib/openhab/core/things/channel_uid.rb +19 -2
- data/lib/openhab/core/things/thing.rb +11 -2
- data/lib/openhab/core/things/thing_type.rb +62 -0
- data/lib/openhab/core/things/thing_type_uid.rb +54 -0
- data/lib/openhab/core/things/thing_uid.rb +30 -0
- data/lib/openhab/core/things/uid.rb +25 -0
- data/lib/openhab/core/things.rb +1 -3
- data/lib/openhab/dsl/rules/builder.rb +46 -8
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +1 -0
- data/lib/openhab/dsl/sitemaps/builder.rb +199 -57
- data/lib/openhab/dsl/things/builder.rb +52 -18
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +4 -4
- metadata +15 -3
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "uid"
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module Core
|
7
|
+
module Things
|
8
|
+
java_import org.openhab.core.thing.ThingUID
|
9
|
+
|
10
|
+
#
|
11
|
+
# {ThingUID} represents a unique identifier for a {Thing}.
|
12
|
+
#
|
13
|
+
# @!attribute [r] id
|
14
|
+
# @return [String]
|
15
|
+
#
|
16
|
+
# @!attribute [r] bridge_ids
|
17
|
+
# @return [Array<string>]
|
18
|
+
#
|
19
|
+
class ThingUID < UID
|
20
|
+
extend Forwardable
|
21
|
+
|
22
|
+
# @!attribute [r] thing
|
23
|
+
# @return [Thing]
|
24
|
+
def thing
|
25
|
+
EntityLookup.lookup_thing(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../abstract_uid"
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module Core
|
7
|
+
module Things
|
8
|
+
java_import org.openhab.core.thing.UID
|
9
|
+
|
10
|
+
#
|
11
|
+
# Base class for binding related unique identifiers.
|
12
|
+
#
|
13
|
+
# A UID must always start with a binding ID.
|
14
|
+
#
|
15
|
+
# @!attribute [r] binding_id
|
16
|
+
# @return [String]
|
17
|
+
#
|
18
|
+
# @!attribute [r] category
|
19
|
+
# (see ChannelGroupType#category)
|
20
|
+
#
|
21
|
+
class UID < AbstractUID
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/openhab/core/things.rb
CHANGED
@@ -7,9 +7,7 @@ module OpenHAB
|
|
7
7
|
# as well as related infrastructure.
|
8
8
|
#
|
9
9
|
module Things
|
10
|
-
java_import org.openhab.core.thing.ThingStatus
|
11
|
-
org.openhab.core.thing.ThingUID,
|
12
|
-
org.openhab.core.thing.ThingTypeUID
|
10
|
+
java_import org.openhab.core.thing.ThingStatus
|
13
11
|
|
14
12
|
class << self
|
15
13
|
# @!visibility private
|
@@ -38,7 +38,7 @@ module OpenHAB
|
|
38
38
|
# Create a new rule
|
39
39
|
#
|
40
40
|
# The rule must have at least one trigger and one execution block.
|
41
|
-
# To create a "script" without any triggers, use {
|
41
|
+
# To create a "script" without any triggers, use {OpenHAB::DSL.script script}.
|
42
42
|
#
|
43
43
|
# @param [String] name The rule name
|
44
44
|
# @yield Block executed in the context of a {Rules::BuilderDSL}
|
@@ -87,14 +87,45 @@ module OpenHAB
|
|
87
87
|
# Create a new script
|
88
88
|
#
|
89
89
|
# A script is a rule with no triggers. It can be called by various other actions,
|
90
|
-
# such as the Run Rules action.
|
90
|
+
# such as the Run Rules action, or by calling {Core::Rules::Rule#trigger}.
|
91
|
+
#
|
92
|
+
# Scripts can be executed with some additional context, similar to method parameters
|
93
|
+
# (see {Core::Rules::Rule#trigger}).
|
94
|
+
# The context can be accessed from within the script's execution block as a "local" variable.
|
91
95
|
#
|
92
|
-
# @param [String] name A
|
96
|
+
# @param [String] name A name for the script
|
97
|
+
# @param [String] description A description of the script
|
93
98
|
# @param [String] id The script's ID
|
99
|
+
# @param [String, Symbol, Semantics::Tag, Array<String, Symbol, Semantics::Tag>, nil] tag
|
100
|
+
# Tags to assign to the script
|
101
|
+
# @param [String, Symbol, Semantics::Tag, Array<String, Symbol, Semantics::Tag>, nil] tags
|
102
|
+
# Fluent alias for `tag`
|
94
103
|
# @yield [] Block executed when the script is executed.
|
95
104
|
# @return [Core::Rules::Rule]
|
96
105
|
#
|
97
|
-
|
106
|
+
# @example A simple script
|
107
|
+
# # return the script object into a variable
|
108
|
+
# door_check = script "Check all doors", id: "door_check", tags: :security do
|
109
|
+
# open_doors = gDoors.members.select(&:open?).map(&:label).join(", ")
|
110
|
+
# notify("The following doors are open: #{open_doors}") unless open_doors.empty?
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# # run is an alias of trigger
|
114
|
+
# door_check.run
|
115
|
+
#
|
116
|
+
# @example A script with context
|
117
|
+
# # This script expects to be called with `message` as context/parameter
|
118
|
+
# DESTINATION_EMAIL = "myemail@example.com"
|
119
|
+
# script "Send Notifications", id: "send_alert" do
|
120
|
+
# notify(message)
|
121
|
+
# things["mail:smtp:local"].send_mail(DESTINATION_EMAIL, "OpenHAB Alert", message)
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# rules.scripts["send_alert"].run(message: "The door is open!")
|
125
|
+
#
|
126
|
+
# @see Core::Rules::Rule#trigger
|
127
|
+
#
|
128
|
+
def script(name = nil, description: nil, id: nil, tag: nil, tags: nil, script: nil, &block)
|
98
129
|
raise ArgumentError, "Block is required" unless block
|
99
130
|
|
100
131
|
id ||= NameInference.infer_rule_id_from_block(block)
|
@@ -105,8 +136,9 @@ module OpenHAB
|
|
105
136
|
ThreadLocal.thread_local(openhab_rule_type: "script", openhab_rule_uid: id) do
|
106
137
|
builder = BuilderDSL.new(block.binding)
|
107
138
|
builder.uid(id)
|
108
|
-
builder.tags("Script")
|
139
|
+
builder.tags("Script", *Array.wrap(tag), *Array.wrap(tags))
|
109
140
|
builder.name(name)
|
141
|
+
builder.description(description)
|
110
142
|
builder.script(&block)
|
111
143
|
logger.trace { builder.inspect }
|
112
144
|
builder.build(provider, script)
|
@@ -119,12 +151,17 @@ module OpenHAB
|
|
119
151
|
# A scene is a rule with no triggers. It can be called by various other actions,
|
120
152
|
# such as the Run Rules action.
|
121
153
|
#
|
122
|
-
# @param [String] name A
|
154
|
+
# @param [String] name A name for the scene
|
155
|
+
# @param [String] description A description of the scene
|
123
156
|
# @param [String] id The script's ID
|
157
|
+
# @param [String, Symbol, Semantics::Tag, Array<String, Symbol, Semantics::Tag>, nil] tag
|
158
|
+
# Tags to assign to the script
|
159
|
+
# @param [String, Symbol, Semantics::Tag, Array<String, Symbol, Semantics::Tag>, nil] tags
|
160
|
+
# Fluent alias for `tag`
|
124
161
|
# @yield [] Block executed when the script is executed.
|
125
162
|
# @return [Core::Rules::Rule]
|
126
163
|
#
|
127
|
-
def scene(name = nil, id: nil, script: nil, &block)
|
164
|
+
def scene(name = nil, description: nil, id: nil, tag: nil, tags: nil, script: nil, &block)
|
128
165
|
raise ArgumentError, "Block is required" unless block
|
129
166
|
|
130
167
|
id ||= NameInference.infer_rule_id_from_block(block)
|
@@ -135,8 +172,9 @@ module OpenHAB
|
|
135
172
|
ThreadLocal.thread_local(openhab_rule_type: "script", openhab_rule_uid: id) do
|
136
173
|
builder = BuilderDSL.new(block.binding)
|
137
174
|
builder.uid(id)
|
138
|
-
builder.tags("Scene")
|
175
|
+
builder.tags("Scene", *Array.wrap(tag), *Array.wrap(tags))
|
139
176
|
builder.name(name)
|
177
|
+
builder.description(description)
|
140
178
|
builder.script(&block)
|
141
179
|
logger.trace { builder.inspect }
|
142
180
|
builder.build(provider, script)
|