openhab-scripting 2.16.2 → 2.16.3
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.rb +12 -16
- data/lib/openhab/core/entity_lookup.rb +162 -0
- data/lib/openhab/core/openhab_setup.rb +31 -0
- data/lib/openhab/core/osgi.rb +61 -0
- data/lib/openhab/dsl/actions.rb +105 -0
- data/lib/openhab/dsl/dsl.rb +47 -0
- data/lib/openhab/{core/dsl → dsl}/gems.rb +0 -1
- data/lib/openhab/dsl/group.rb +100 -0
- data/lib/openhab/dsl/items/items.rb +46 -0
- data/lib/openhab/dsl/items/number_item.rb +352 -0
- data/lib/openhab/dsl/items/string_item.rb +120 -0
- data/lib/openhab/dsl/monkey_patch/actions/actions.rb +4 -0
- data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/events/events.rb +5 -0
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +35 -0
- data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +33 -0
- data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +61 -0
- data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +193 -0
- data/lib/openhab/dsl/monkey_patch/items/group_item.rb +37 -0
- data/lib/openhab/dsl/monkey_patch/items/items.rb +133 -0
- data/lib/openhab/dsl/monkey_patch/items/metadata.rb +281 -0
- data/lib/openhab/dsl/monkey_patch/items/persistence.rb +70 -0
- data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +95 -0
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +39 -0
- data/lib/openhab/dsl/monkey_patch/ruby/range.rb +47 -0
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +7 -0
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -0
- data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +70 -0
- data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +51 -0
- data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +36 -0
- data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +69 -0
- data/lib/openhab/dsl/monkey_patch/types/types.rb +8 -0
- data/lib/openhab/dsl/persistence.rb +25 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +342 -0
- data/lib/openhab/dsl/rules/guard.rb +134 -0
- data/lib/openhab/dsl/rules/property.rb +102 -0
- data/lib/openhab/dsl/rules/rule.rb +116 -0
- data/lib/openhab/dsl/rules/rule_config.rb +151 -0
- data/lib/openhab/dsl/rules/triggers/changed.rb +143 -0
- data/lib/openhab/dsl/rules/triggers/channel.rb +53 -0
- data/lib/openhab/dsl/rules/triggers/command.rb +104 -0
- data/lib/openhab/dsl/rules/triggers/cron.rb +177 -0
- data/lib/openhab/dsl/rules/triggers/trigger.rb +124 -0
- data/lib/openhab/dsl/rules/triggers/updated.rb +98 -0
- data/lib/openhab/dsl/states.rb +61 -0
- data/lib/openhab/dsl/things.rb +91 -0
- data/lib/openhab/dsl/time_of_day.rb +228 -0
- data/lib/openhab/dsl/timers.rb +77 -0
- data/lib/openhab/dsl/types/quantity.rb +290 -0
- data/lib/openhab/dsl/units.rb +39 -0
- data/lib/openhab/log/configuration.rb +21 -0
- data/lib/openhab/log/logger.rb +172 -0
- data/lib/openhab/version.rb +1 -1
- metadata +55 -58
- data/lib/openhab/configuration.rb +0 -16
- data/lib/openhab/core/cron.rb +0 -27
- data/lib/openhab/core/debug.rb +0 -34
- data/lib/openhab/core/dsl.rb +0 -51
- data/lib/openhab/core/dsl/actions.rb +0 -107
- data/lib/openhab/core/dsl/entities.rb +0 -147
- data/lib/openhab/core/dsl/group.rb +0 -102
- data/lib/openhab/core/dsl/items/items.rb +0 -51
- data/lib/openhab/core/dsl/items/number_item.rb +0 -323
- data/lib/openhab/core/dsl/items/string_item.rb +0 -122
- data/lib/openhab/core/dsl/monkey_patch/actions/actions.rb +0 -4
- data/lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb +0 -22
- data/lib/openhab/core/dsl/monkey_patch/events.rb +0 -5
- data/lib/openhab/core/dsl/monkey_patch/events/item_command.rb +0 -13
- data/lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb +0 -25
- data/lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb +0 -26
- data/lib/openhab/core/dsl/monkey_patch/items/contact_item.rb +0 -54
- data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +0 -182
- data/lib/openhab/core/dsl/monkey_patch/items/group_item.rb +0 -27
- data/lib/openhab/core/dsl/monkey_patch/items/items.rb +0 -132
- data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +0 -283
- data/lib/openhab/core/dsl/monkey_patch/items/persistence.rb +0 -72
- data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +0 -87
- data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +0 -41
- data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +0 -47
- data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +0 -7
- data/lib/openhab/core/dsl/monkey_patch/ruby/string.rb +0 -43
- data/lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb +0 -60
- data/lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb +0 -41
- data/lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb +0 -25
- data/lib/openhab/core/dsl/monkey_patch/types/percent_type.rb +0 -23
- data/lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb +0 -58
- data/lib/openhab/core/dsl/monkey_patch/types/types.rb +0 -8
- data/lib/openhab/core/dsl/persistence.rb +0 -27
- data/lib/openhab/core/dsl/property.rb +0 -96
- data/lib/openhab/core/dsl/rule/automation_rule.rb +0 -345
- data/lib/openhab/core/dsl/rule/guard.rb +0 -136
- data/lib/openhab/core/dsl/rule/rule.rb +0 -117
- data/lib/openhab/core/dsl/rule/rule_config.rb +0 -153
- data/lib/openhab/core/dsl/rule/triggers/changed.rb +0 -145
- data/lib/openhab/core/dsl/rule/triggers/channel.rb +0 -55
- data/lib/openhab/core/dsl/rule/triggers/command.rb +0 -106
- data/lib/openhab/core/dsl/rule/triggers/cron.rb +0 -160
- data/lib/openhab/core/dsl/rule/triggers/trigger.rb +0 -126
- data/lib/openhab/core/dsl/rule/triggers/updated.rb +0 -100
- data/lib/openhab/core/dsl/states.rb +0 -63
- data/lib/openhab/core/dsl/things.rb +0 -93
- data/lib/openhab/core/dsl/time_of_day.rb +0 -231
- data/lib/openhab/core/dsl/timers.rb +0 -79
- data/lib/openhab/core/dsl/types/quantity.rb +0 -292
- data/lib/openhab/core/dsl/units.rb +0 -41
- data/lib/openhab/core/log.rb +0 -170
- data/lib/openhab/core/patch_load_path.rb +0 -7
- data/lib/openhab/core/startup_delay.rb +0 -23
- data/lib/openhab/osgi.rb +0 -59
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70bdb050049010368d9987f87bcd119f1886c6cc27f1721eb88935e67c4c37b1
|
|
4
|
+
data.tar.gz: 38f66b267318de4710face86e9f4d188120110df670bb22ca610885c2288e4ae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a7c9d8fa0966c4456c378fa86d824fc43a57f75da6ef7289b8c29b6768858fa3677a37d054983d53b4efa8d40ea47cf2b2e8931256ea259eebbb01b753088fa
|
|
7
|
+
data.tar.gz: 753742cfd66167c2a47f76830f344b96f0654f4976ee558a0a3b73bd4f25d842c2ed465a68d2b08b6d1a2ab46e5b74f6822e201ec8cad736c8df4ca410e76c9c
|
data/lib/openhab.rb
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require 'openhab/
|
|
5
|
-
|
|
6
|
-
require 'openhab/core/startup_delay'
|
|
7
|
-
require 'openhab/core/log'
|
|
8
|
-
require 'openhab/core/debug'
|
|
9
|
-
require 'openhab/core/dsl'
|
|
3
|
+
require 'openhab/core/openhab_setup'
|
|
4
|
+
require 'openhab/log/logger'
|
|
5
|
+
require 'openhab/dsl/dsl'
|
|
10
6
|
|
|
11
7
|
require 'openhab/version'
|
|
12
8
|
|
|
@@ -14,7 +10,7 @@ require 'openhab/version'
|
|
|
14
10
|
# Module used to extend base object with OpenHAB Library functionality
|
|
15
11
|
#
|
|
16
12
|
module OpenHAB
|
|
17
|
-
include
|
|
13
|
+
include OpenHAB::Log
|
|
18
14
|
#
|
|
19
15
|
# Extends calling object with DSL and helper methods
|
|
20
16
|
#
|
|
@@ -22,15 +18,15 @@ module OpenHAB
|
|
|
22
18
|
#
|
|
23
19
|
#
|
|
24
20
|
def self.extended(base)
|
|
25
|
-
|
|
26
|
-
base.extend
|
|
27
|
-
base.extend EntityLookup
|
|
28
|
-
base.extend OpenHAB::
|
|
29
|
-
base.extend OpenHAB::
|
|
21
|
+
OpenHAB::Core.wait_till_openhab_ready
|
|
22
|
+
base.extend Log
|
|
23
|
+
base.extend OpenHAB::Core::EntityLookup
|
|
24
|
+
base.extend OpenHAB::DSL
|
|
25
|
+
base.extend OpenHAB::DSL::TimeOfDay
|
|
30
26
|
|
|
31
|
-
base.send :include, OpenHAB::
|
|
32
|
-
base.send :include, OpenHAB::
|
|
33
|
-
base.send :include, OpenHAB::
|
|
27
|
+
base.send :include, OpenHAB::DSL::TimeOfDay
|
|
28
|
+
base.send :include, OpenHAB::DSL::Items
|
|
29
|
+
base.send :include, OpenHAB::DSL::Types
|
|
34
30
|
logger.info "OpenHAB JRuby Scripting Library Version #{OpenHAB::VERSION} Loaded"
|
|
35
31
|
end
|
|
36
32
|
end
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pp'
|
|
4
|
+
require 'java'
|
|
5
|
+
require 'set'
|
|
6
|
+
require 'openhab/dsl/group'
|
|
7
|
+
require 'openhab/log/logger'
|
|
8
|
+
require 'openhab/dsl/items/number_item'
|
|
9
|
+
require 'openhab/dsl/items/string_item'
|
|
10
|
+
|
|
11
|
+
# Automation lookup and injection of OpenHab entities
|
|
12
|
+
java_import org.openhab.core.items.GroupItem
|
|
13
|
+
|
|
14
|
+
module OpenHAB
|
|
15
|
+
module Core
|
|
16
|
+
#
|
|
17
|
+
# Manages access to OpenHAB entities
|
|
18
|
+
#
|
|
19
|
+
module EntityLookup
|
|
20
|
+
include OpenHAB::Log
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# Automatically looks up OpenHAB items and things in appropriate registries
|
|
24
|
+
#
|
|
25
|
+
# @param [method] method Name of item to lookup
|
|
26
|
+
# @param [<Type>] args method arguments
|
|
27
|
+
# @param [<Type>] block supplied to missing method
|
|
28
|
+
#
|
|
29
|
+
# @return [Object] Item or Thing if found in registry
|
|
30
|
+
#
|
|
31
|
+
def method_missing(method, *args, &block)
|
|
32
|
+
return if method.to_s == 'scriptLoaded'
|
|
33
|
+
return if method.to_s == 'scriptUnloaded'
|
|
34
|
+
|
|
35
|
+
logger.trace("method missing, performing OpenHab Lookup for: #{method}")
|
|
36
|
+
EntityLookup.lookup_entity(method) || super
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
# Checks if this method responds to the missing method
|
|
41
|
+
#
|
|
42
|
+
# @param [String] method_name Name of the method to check
|
|
43
|
+
# @param [Boolean] _include_private boolean if private methods should be checked
|
|
44
|
+
#
|
|
45
|
+
# @return [Boolean] true if this object will respond to the supplied method, false otherwise
|
|
46
|
+
#
|
|
47
|
+
def respond_to_missing?(method_name, _include_private = false)
|
|
48
|
+
logger.trace("Checking if OpenHAB entites exist for #{method_name}")
|
|
49
|
+
method_name = method_name.to_s if method_name.is_a? Symbol
|
|
50
|
+
|
|
51
|
+
method_name == 'scriptLoaded' ||
|
|
52
|
+
method_name == 'scriptUnloaded' ||
|
|
53
|
+
EntityLookup.lookup_entity(method_name) ||
|
|
54
|
+
super
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
#
|
|
58
|
+
# Looks up an OpenHAB entity
|
|
59
|
+
# items are checked first, then things
|
|
60
|
+
#
|
|
61
|
+
# @param [String] name of entity to lookup in item or thing registry
|
|
62
|
+
#
|
|
63
|
+
# @return [Thing,Item] if found, nil otherwise
|
|
64
|
+
#
|
|
65
|
+
def self.lookup_entity(name)
|
|
66
|
+
lookup_item(name) || lookup_thing(name)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
#
|
|
70
|
+
# Decorate items with Ruby wrappers
|
|
71
|
+
#
|
|
72
|
+
# @param [Array] items Array of items to decorate
|
|
73
|
+
#
|
|
74
|
+
# @return [Array] Array of decorated items
|
|
75
|
+
#
|
|
76
|
+
def self.decorate_items(*items)
|
|
77
|
+
items.flatten.map { |item| decorate_item(item) }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# Decorate item with Ruby wrappers
|
|
82
|
+
#
|
|
83
|
+
# @param [Object] item the item object to decorate
|
|
84
|
+
#
|
|
85
|
+
# @return [Object] the ruby wrapper for the item
|
|
86
|
+
#
|
|
87
|
+
private_class_method def self.decorate_item(item)
|
|
88
|
+
case item
|
|
89
|
+
when GroupItem
|
|
90
|
+
decorate_group(item)
|
|
91
|
+
when Java::Org.openhab.core.library.items::NumberItem
|
|
92
|
+
OpenHAB::DSL::Items::NumberItem.new(item)
|
|
93
|
+
when Java::Org.openhab.core.library.items::StringItem
|
|
94
|
+
OpenHAB::DSL::Items::StringItem.new(item)
|
|
95
|
+
else
|
|
96
|
+
item
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
#
|
|
101
|
+
# Looks up a Thing in the OpenHAB registry replacing '_' with ':'
|
|
102
|
+
#
|
|
103
|
+
# @param [String] name of Thing to lookup in Thing registry
|
|
104
|
+
#
|
|
105
|
+
# @return [Thing] if found, nil otherwise
|
|
106
|
+
#
|
|
107
|
+
def self.lookup_thing(name)
|
|
108
|
+
logger.trace("Looking up thing(#{name})")
|
|
109
|
+
# Convert from : syntax to underscore
|
|
110
|
+
name = name.to_s if name.is_a? Symbol
|
|
111
|
+
|
|
112
|
+
# Thing UIDs have at least 3 segements
|
|
113
|
+
return if name.count('_') < 3
|
|
114
|
+
|
|
115
|
+
name = name.gsub('_', ':')
|
|
116
|
+
# rubocop: disable Style/GlobalVars
|
|
117
|
+
$things.get(Java::OrgOpenhabCoreThing::ThingUID.new(name))
|
|
118
|
+
# rubocop: enable Style/GlobalVars
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
#
|
|
122
|
+
# Lookup OpenHAB items in item registry
|
|
123
|
+
#
|
|
124
|
+
# @param [String] name of item to lookup
|
|
125
|
+
#
|
|
126
|
+
# @return [Item] OpenHAB item if registry contains a matching item, nil othewise
|
|
127
|
+
#
|
|
128
|
+
def self.lookup_item(name)
|
|
129
|
+
logger.trace("Looking up item(#{name})")
|
|
130
|
+
name = name.to_s if name.is_a? Symbol
|
|
131
|
+
# rubocop: disable Style/GlobalVars
|
|
132
|
+
item = $ir.get(name)
|
|
133
|
+
# rubocop: enable Style/GlobalVars
|
|
134
|
+
decorate_item(item)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
#
|
|
138
|
+
# Decorate a group from an item base
|
|
139
|
+
#
|
|
140
|
+
# @param [OpenHAB item] item item to convert to a group item
|
|
141
|
+
#
|
|
142
|
+
# @return [OpenHAB::DSL::Groups::Group] Group created from supplied item
|
|
143
|
+
#
|
|
144
|
+
private_class_method def self.decorate_group(item)
|
|
145
|
+
group = OpenHAB::DSL::Groups::Group.new(Set.new(decorate_items(item.all_members.to_a)))
|
|
146
|
+
group.group = item
|
|
147
|
+
group
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
#
|
|
154
|
+
# Implements const_missing to return OpenHAB items or things if mapping to missing name if they exist
|
|
155
|
+
#
|
|
156
|
+
# @param [String] name Capital string that was not set as a constant and to be looked up
|
|
157
|
+
#
|
|
158
|
+
# @return [Object] OpenHAB Item or Thing if their name exist in OpenHAB item and thing regestries
|
|
159
|
+
#
|
|
160
|
+
def Object.const_missing(name)
|
|
161
|
+
OpenHAB::Core::EntityLookup.lookup_entity(name) || super
|
|
162
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'openhab/log/logger'
|
|
4
|
+
|
|
5
|
+
module OpenHAB
|
|
6
|
+
#
|
|
7
|
+
# Core support for OpenHAB JRuby Library
|
|
8
|
+
#
|
|
9
|
+
module Core
|
|
10
|
+
include OpenHAB::Log
|
|
11
|
+
|
|
12
|
+
# @return [Integer] Number of seconds to wait between checks for automation manager
|
|
13
|
+
CHECK_DELAY = 10
|
|
14
|
+
private_constant :CHECK_DELAY
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# Wait until OpenHAB engine ready to process
|
|
18
|
+
#
|
|
19
|
+
#
|
|
20
|
+
def self.wait_till_openhab_ready
|
|
21
|
+
logger.debug('Checking readyness of OpenHAB')
|
|
22
|
+
# rubocop: disable Style/GlobalVars
|
|
23
|
+
until $scriptExtension.get('automationManager')
|
|
24
|
+
logger.debug("Automation manager not loaded, checking again in #{CHECK_DELAY} seconds.")
|
|
25
|
+
sleep CHECK_DELAY
|
|
26
|
+
end
|
|
27
|
+
# rubocop: enable Style/GlobalVars
|
|
28
|
+
logger.debug 'Automation manager instantiated, OpenHAB ready for rule processing.'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'java'
|
|
4
|
+
require 'openhab/log/logger'
|
|
5
|
+
|
|
6
|
+
module OpenHAB
|
|
7
|
+
module Core
|
|
8
|
+
#
|
|
9
|
+
# OSGI services interface
|
|
10
|
+
#
|
|
11
|
+
class OSGI
|
|
12
|
+
include OpenHAB::Log
|
|
13
|
+
|
|
14
|
+
java_import org.openhab.core.model.script.actions.ScriptExecution
|
|
15
|
+
java_import org.osgi.framework.FrameworkUtil
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
# @param name [String] The service name
|
|
19
|
+
#
|
|
20
|
+
# @return [Service]
|
|
21
|
+
#
|
|
22
|
+
def self.service(name)
|
|
23
|
+
ref = bundle_context.getServiceReference(name)
|
|
24
|
+
service = bundle_context.getService(ref) if ref
|
|
25
|
+
logger.trace "OSGI service(#{service}) found for '#{name}' using OSGI Service Reference #{ref}"
|
|
26
|
+
|
|
27
|
+
service
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# @param name [String] The service name
|
|
32
|
+
# @param filter [String] Filter for service names. See https://docs.osgi.org/javadoc/r4v43/core/org/osgi/framework/Filter.html
|
|
33
|
+
#
|
|
34
|
+
# @return [Array] An array of services
|
|
35
|
+
#
|
|
36
|
+
def self.services(name, filter: nil)
|
|
37
|
+
bundle_context.getServiceReferences(name, filter)&.map do |reference|
|
|
38
|
+
bundle_context.getService(reference)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Get the bundle context
|
|
44
|
+
#
|
|
45
|
+
# @return [java::org::osgi::framework::BundleContext] OSGI bundle context
|
|
46
|
+
#
|
|
47
|
+
def self.bundle_context
|
|
48
|
+
@bundle_context ||= bundle.getBundleContext
|
|
49
|
+
end
|
|
50
|
+
private_class_method :bundle_context
|
|
51
|
+
|
|
52
|
+
# Get the OSGI Bundle for ScriptExtension Class
|
|
53
|
+
def self.bundle
|
|
54
|
+
# rubocop: disable Style/GlobalVars
|
|
55
|
+
@bundle ||= FrameworkUtil.getBundle($scriptExtension.class)
|
|
56
|
+
# rubocop: enable Style/GlobalVars
|
|
57
|
+
end
|
|
58
|
+
private_class_method :bundle
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'java'
|
|
4
|
+
require 'openhab/core/osgi'
|
|
5
|
+
|
|
6
|
+
module OpenHAB
|
|
7
|
+
module DSL
|
|
8
|
+
#
|
|
9
|
+
# Module to import and streamline access to OpenHAB actions
|
|
10
|
+
#
|
|
11
|
+
module Actions
|
|
12
|
+
java_import org.openhab.core.library.types.PercentType
|
|
13
|
+
include OpenHAB::Log
|
|
14
|
+
|
|
15
|
+
OpenHAB::Core::OSGI.services('org.openhab.core.model.script.engine.action.ActionService')&.each do |service|
|
|
16
|
+
java_import service.actionClass.to_s
|
|
17
|
+
logger.trace("Loaded ACTION: #{service.actionClass}")
|
|
18
|
+
end
|
|
19
|
+
# Import common actions
|
|
20
|
+
%w[Exec HTTP Ping].each { |action| java_import "org.openhab.core.model.script.actions.#{action}" }
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# Return an OpenHAB Action object for the given scope and thing
|
|
24
|
+
#
|
|
25
|
+
# @param scope [String] The action scope
|
|
26
|
+
# @param thing_uid [String] Thing UID
|
|
27
|
+
#
|
|
28
|
+
# @return [Object] OpenHAB action
|
|
29
|
+
#
|
|
30
|
+
def actions(scope, thing_uid)
|
|
31
|
+
# rubocop: disable Style/GlobalVars
|
|
32
|
+
$actions.get(scope, thing_uid)
|
|
33
|
+
# rubocop: enable Style/GlobalVars
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Gets the list of action objects associated with a specific ThingUID
|
|
38
|
+
#
|
|
39
|
+
# @param [Java::org::openhab::core::thing::ThingUID] thing_uid to get associated actions for
|
|
40
|
+
#
|
|
41
|
+
# @return [Array] of action objects associated with thing_uid, may be empty
|
|
42
|
+
#
|
|
43
|
+
def actions_for_thing(thing_uid)
|
|
44
|
+
thing_uid = thing_uid.to_s
|
|
45
|
+
# rubocop: disable Style/GlobalVars
|
|
46
|
+
action_keys = $actions.action_keys
|
|
47
|
+
# rubocop: enable Style/GlobalVars
|
|
48
|
+
logger.trace("Registered actions: '#{action_keys}' for thing '#{thing_uid}'")
|
|
49
|
+
action_keys.map { |action_key| action_key.split('-', 2) }
|
|
50
|
+
.select { |action_pair| action_pair.last == thing_uid }
|
|
51
|
+
.map(&:first)
|
|
52
|
+
.map { |scope| actions(scope, thing_uid) }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
#
|
|
56
|
+
# Send notification to an email or broadcast
|
|
57
|
+
#
|
|
58
|
+
# @param msg [String] The notification message to send
|
|
59
|
+
# @param email [String] The email address to send to. If nil, the message will be broadcasted
|
|
60
|
+
#
|
|
61
|
+
# @return [void]
|
|
62
|
+
#
|
|
63
|
+
def notify(msg, email: nil)
|
|
64
|
+
unless defined? NotificationAction
|
|
65
|
+
raise NoMethodError, 'NotificationAction is not available. Please install the OpenHAB cloud addon'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
if email
|
|
69
|
+
NotificationAction.sendNotification email, msg
|
|
70
|
+
else
|
|
71
|
+
NotificationAction.sendBroadcastNotification msg
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
#
|
|
76
|
+
# Say text via OpenHAB Text-To-Speech service, Voice.say()
|
|
77
|
+
#
|
|
78
|
+
# @param text [String] The text to say
|
|
79
|
+
# @param voice [String] Specify a particular voice to use
|
|
80
|
+
# @param sink [String] Specify a particular sink to output the speech
|
|
81
|
+
# @param volume [PercentType] Specify the volume for the speech
|
|
82
|
+
#
|
|
83
|
+
# @return [void]
|
|
84
|
+
#
|
|
85
|
+
def say(text, voice: nil, sink: nil, volume: nil)
|
|
86
|
+
volume = PercentType.new(volume&.to_i) unless volume.is_a?(PercentType) || volume.nil?
|
|
87
|
+
Voice.say text, voice, sink, volume
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
#
|
|
91
|
+
# Play an audio file via OpenHAB sound service, Audio.playSound()
|
|
92
|
+
#
|
|
93
|
+
# @param filename [String] The sound file to play
|
|
94
|
+
# @param sink [String] Specify a particular sink to output the speech
|
|
95
|
+
# @param volume [PercentType] Specify the volume for the speech
|
|
96
|
+
#
|
|
97
|
+
# @return [void]
|
|
98
|
+
#
|
|
99
|
+
def play_sound(filename, sink: nil, volume: nil)
|
|
100
|
+
volume = PercentType.new(volume&.to_i) unless volume.is_a?(PercentType) || volume.nil?
|
|
101
|
+
Audio.playSound sink, filename, volume
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'java'
|
|
4
|
+
require 'openhab/log/logger'
|
|
5
|
+
require 'openhab/dsl/monkey_patch/events/events'
|
|
6
|
+
require 'openhab/dsl/monkey_patch/ruby/ruby'
|
|
7
|
+
require 'openhab/dsl/monkey_patch/items/items'
|
|
8
|
+
require 'openhab/dsl/monkey_patch/types/types'
|
|
9
|
+
require 'openhab/dsl/monkey_patch/actions/actions'
|
|
10
|
+
require 'openhab/dsl/rules/rule'
|
|
11
|
+
require 'openhab/dsl/actions'
|
|
12
|
+
require 'openhab/dsl/timers'
|
|
13
|
+
require 'openhab/dsl/group'
|
|
14
|
+
require 'openhab/dsl/things'
|
|
15
|
+
require 'openhab/dsl/items/items'
|
|
16
|
+
require 'openhab/dsl/items/number_item'
|
|
17
|
+
require 'openhab/dsl/time_of_day'
|
|
18
|
+
require 'openhab/dsl/gems'
|
|
19
|
+
require 'openhab/dsl/persistence'
|
|
20
|
+
require 'openhab/dsl/units'
|
|
21
|
+
require 'openhab/dsl/types/quantity'
|
|
22
|
+
require 'openhab/dsl/states'
|
|
23
|
+
|
|
24
|
+
module OpenHAB
|
|
25
|
+
#
|
|
26
|
+
# Module to be extended to access the OpenHAB Ruby DSL
|
|
27
|
+
#
|
|
28
|
+
module DSL
|
|
29
|
+
# Extend the calling module/class with the DSL
|
|
30
|
+
# Disabling method length because they are all includes
|
|
31
|
+
# rubocop:disable Metrics/MethodLength
|
|
32
|
+
def self.extended(base)
|
|
33
|
+
base.send :include, OpenHAB::DSL::Actions
|
|
34
|
+
base.send :include, OpenHAB::DSL::Groups
|
|
35
|
+
base.send :include, OpenHAB::DSL::Items
|
|
36
|
+
base.send :include, OpenHAB::DSL::Persistence
|
|
37
|
+
base.send :include, OpenHAB::DSL::Rules
|
|
38
|
+
base.send :include, OpenHAB::DSL::States
|
|
39
|
+
base.send :include, OpenHAB::DSL::Things
|
|
40
|
+
base.send :include, OpenHAB::DSL::Timers
|
|
41
|
+
base.send :include, OpenHAB::DSL::TimeOfDay
|
|
42
|
+
base.send :include, OpenHAB::DSL::Types
|
|
43
|
+
base.send :include, OpenHAB::DSL::Units
|
|
44
|
+
end
|
|
45
|
+
# rubocop:enable Metrics/MethodLength
|
|
46
|
+
end
|
|
47
|
+
end
|