openhab-scripting 2.16.2 → 2.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab.rb +12 -16
  3. data/lib/openhab/core/entity_lookup.rb +173 -0
  4. data/lib/openhab/core/openhab_setup.rb +31 -0
  5. data/lib/openhab/core/osgi.rb +61 -0
  6. data/lib/openhab/dsl/actions.rb +105 -0
  7. data/lib/openhab/dsl/dsl.rb +49 -0
  8. data/lib/openhab/{core/dsl → dsl}/gems.rb +0 -1
  9. data/lib/openhab/dsl/group.rb +100 -0
  10. data/lib/openhab/dsl/items/datetime_item.rb +97 -0
  11. data/lib/openhab/dsl/items/items.rb +46 -0
  12. data/lib/openhab/dsl/items/number_item.rb +352 -0
  13. data/lib/openhab/dsl/items/rollershutter_item.rb +179 -0
  14. data/lib/openhab/dsl/items/string_item.rb +120 -0
  15. data/lib/openhab/dsl/monkey_patch/actions/actions.rb +4 -0
  16. data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +32 -0
  17. data/lib/openhab/dsl/monkey_patch/events/events.rb +5 -0
  18. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +23 -0
  19. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +35 -0
  20. data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +33 -0
  21. data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +61 -0
  22. data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +193 -0
  23. data/lib/openhab/dsl/monkey_patch/items/group_item.rb +37 -0
  24. data/lib/openhab/dsl/monkey_patch/items/items.rb +133 -0
  25. data/lib/openhab/dsl/monkey_patch/items/metadata.rb +281 -0
  26. data/lib/openhab/dsl/monkey_patch/items/persistence.rb +70 -0
  27. data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +95 -0
  28. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +39 -0
  29. data/lib/openhab/dsl/monkey_patch/ruby/range.rb +47 -0
  30. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +8 -0
  31. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -0
  32. data/lib/openhab/dsl/monkey_patch/ruby/time.rb +32 -0
  33. data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +70 -0
  34. data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +51 -0
  35. data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +36 -0
  36. data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +32 -0
  37. data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +69 -0
  38. data/lib/openhab/dsl/monkey_patch/types/types.rb +9 -0
  39. data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +33 -0
  40. data/lib/openhab/dsl/persistence.rb +25 -0
  41. data/lib/openhab/dsl/rules/automation_rule.rb +342 -0
  42. data/lib/openhab/dsl/rules/guard.rb +134 -0
  43. data/lib/openhab/dsl/rules/property.rb +102 -0
  44. data/lib/openhab/dsl/rules/rule.rb +116 -0
  45. data/lib/openhab/dsl/rules/rule_config.rb +151 -0
  46. data/lib/openhab/dsl/rules/triggers/changed.rb +143 -0
  47. data/lib/openhab/dsl/rules/triggers/channel.rb +53 -0
  48. data/lib/openhab/dsl/rules/triggers/command.rb +104 -0
  49. data/lib/openhab/dsl/rules/triggers/cron.rb +177 -0
  50. data/lib/openhab/dsl/rules/triggers/trigger.rb +124 -0
  51. data/lib/openhab/dsl/rules/triggers/updated.rb +98 -0
  52. data/lib/openhab/dsl/states.rb +61 -0
  53. data/lib/openhab/dsl/things.rb +91 -0
  54. data/lib/openhab/dsl/time_of_day.rb +232 -0
  55. data/lib/openhab/dsl/timers.rb +77 -0
  56. data/lib/openhab/dsl/types/datetime.rb +326 -0
  57. data/lib/openhab/dsl/types/quantity.rb +290 -0
  58. data/lib/openhab/dsl/units.rb +39 -0
  59. data/lib/openhab/log/configuration.rb +21 -0
  60. data/lib/openhab/log/logger.rb +172 -0
  61. data/lib/openhab/version.rb +1 -1
  62. metadata +60 -58
  63. data/lib/openhab/configuration.rb +0 -16
  64. data/lib/openhab/core/cron.rb +0 -27
  65. data/lib/openhab/core/debug.rb +0 -34
  66. data/lib/openhab/core/dsl.rb +0 -51
  67. data/lib/openhab/core/dsl/actions.rb +0 -107
  68. data/lib/openhab/core/dsl/entities.rb +0 -147
  69. data/lib/openhab/core/dsl/group.rb +0 -102
  70. data/lib/openhab/core/dsl/items/items.rb +0 -51
  71. data/lib/openhab/core/dsl/items/number_item.rb +0 -323
  72. data/lib/openhab/core/dsl/items/string_item.rb +0 -122
  73. data/lib/openhab/core/dsl/monkey_patch/actions/actions.rb +0 -4
  74. data/lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb +0 -22
  75. data/lib/openhab/core/dsl/monkey_patch/events.rb +0 -5
  76. data/lib/openhab/core/dsl/monkey_patch/events/item_command.rb +0 -13
  77. data/lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb +0 -25
  78. data/lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb +0 -26
  79. data/lib/openhab/core/dsl/monkey_patch/items/contact_item.rb +0 -54
  80. data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +0 -182
  81. data/lib/openhab/core/dsl/monkey_patch/items/group_item.rb +0 -27
  82. data/lib/openhab/core/dsl/monkey_patch/items/items.rb +0 -132
  83. data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +0 -283
  84. data/lib/openhab/core/dsl/monkey_patch/items/persistence.rb +0 -72
  85. data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +0 -87
  86. data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +0 -41
  87. data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +0 -47
  88. data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +0 -7
  89. data/lib/openhab/core/dsl/monkey_patch/ruby/string.rb +0 -43
  90. data/lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb +0 -60
  91. data/lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb +0 -41
  92. data/lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb +0 -25
  93. data/lib/openhab/core/dsl/monkey_patch/types/percent_type.rb +0 -23
  94. data/lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb +0 -58
  95. data/lib/openhab/core/dsl/monkey_patch/types/types.rb +0 -8
  96. data/lib/openhab/core/dsl/persistence.rb +0 -27
  97. data/lib/openhab/core/dsl/property.rb +0 -96
  98. data/lib/openhab/core/dsl/rule/automation_rule.rb +0 -345
  99. data/lib/openhab/core/dsl/rule/guard.rb +0 -136
  100. data/lib/openhab/core/dsl/rule/rule.rb +0 -117
  101. data/lib/openhab/core/dsl/rule/rule_config.rb +0 -153
  102. data/lib/openhab/core/dsl/rule/triggers/changed.rb +0 -145
  103. data/lib/openhab/core/dsl/rule/triggers/channel.rb +0 -55
  104. data/lib/openhab/core/dsl/rule/triggers/command.rb +0 -106
  105. data/lib/openhab/core/dsl/rule/triggers/cron.rb +0 -160
  106. data/lib/openhab/core/dsl/rule/triggers/trigger.rb +0 -126
  107. data/lib/openhab/core/dsl/rule/triggers/updated.rb +0 -100
  108. data/lib/openhab/core/dsl/states.rb +0 -63
  109. data/lib/openhab/core/dsl/things.rb +0 -93
  110. data/lib/openhab/core/dsl/time_of_day.rb +0 -231
  111. data/lib/openhab/core/dsl/timers.rb +0 -79
  112. data/lib/openhab/core/dsl/types/quantity.rb +0 -292
  113. data/lib/openhab/core/dsl/units.rb +0 -41
  114. data/lib/openhab/core/log.rb +0 -170
  115. data/lib/openhab/core/patch_load_path.rb +0 -7
  116. data/lib/openhab/core/startup_delay.rb +0 -23
  117. data/lib/openhab/osgi.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7471d207d040d9fb085fa45e4f6be88f7ad9d99b0987b6a6845f2bb85c8bf5ab
4
- data.tar.gz: b000d8e9397d5556c4387f09e1ec247ccd8303cfa83b27722737e38324ac91b6
3
+ metadata.gz: 64cbcfa58ba3a4d63a88514b61fdbe811a317e3902c61e16119e0d97a89a3523
4
+ data.tar.gz: 075ca2dbc459da17c0c2f13b6a05bf6c8ffb829b5d0f96965b449820db59b216
5
5
  SHA512:
6
- metadata.gz: 13d1994d629262afc44f8c8e62c965e65e383e91224b8fbd12d83f9ec61fa707a0655060c805e3342b373adc5d3034f1744defca1803f84d52190aab055cd8de
7
- data.tar.gz: 368969daaa876bdebbd0b60b8818f9da333c2c6d9df96fa7f00abf99df4891f32cd2151d576a6819c2213630fd1ccf3e1a81a1ddc5aa48d2bfe20be776a3c91a
6
+ metadata.gz: 4ae006b45842d227600eaaeb094285800bddf16935388d6c686112c31bd596ddc8d7fa53eebc6d1b83c0e4053c379662fbfcebab441794bdc183143c27004f92
7
+ data.tar.gz: 0506ac926852a72f400d8c47d701205e27a22b3514878a366eba39812b5226358c1a5e11a95bce3376b03fef2adceac9ccc1f76e5d3dca0a079b2883d565e8ea
data/lib/openhab.rb CHANGED
@@ -1,12 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # First patch the $LOAD_PATH to include lib dir
4
- require 'openhab/core/patch_load_path'
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 Logging
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
- base.extend Logging
26
- base.extend Debug
27
- base.extend EntityLookup
28
- base.extend OpenHAB::Core::DSL
29
- base.extend OpenHAB::Core::DSL::Tod
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::Core::DSL::Tod
32
- base.send :include, OpenHAB::Core::DSL::Items
33
- base.send :include, OpenHAB::Core::DSL::Types
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,173 @@
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
+ require 'openhab/dsl/items/datetime_item'
11
+ require 'openhab/dsl/items/rollershutter_item'
12
+
13
+ # Automation lookup and injection of OpenHab entities
14
+ java_import org.openhab.core.items.GroupItem
15
+
16
+ module OpenHAB
17
+ module Core
18
+ #
19
+ # Manages access to OpenHAB entities
20
+ #
21
+ module EntityLookup
22
+ include OpenHAB::Log
23
+
24
+ #
25
+ # Automatically looks up OpenHAB items and things in appropriate registries
26
+ #
27
+ # @param [method] method Name of item to lookup
28
+ # @param [<Type>] args method arguments
29
+ # @param [<Type>] block supplied to missing method
30
+ #
31
+ # @return [Object] Item or Thing if found in registry
32
+ #
33
+ def method_missing(method, *args, &block)
34
+ return if method.to_s == 'scriptLoaded'
35
+ return if method.to_s == 'scriptUnloaded'
36
+
37
+ logger.trace("method missing, performing OpenHab Lookup for: #{method}")
38
+ EntityLookup.lookup_entity(method) || super
39
+ end
40
+
41
+ #
42
+ # Checks if this method responds to the missing method
43
+ #
44
+ # @param [String] method_name Name of the method to check
45
+ # @param [Boolean] _include_private boolean if private methods should be checked
46
+ #
47
+ # @return [Boolean] true if this object will respond to the supplied method, false otherwise
48
+ #
49
+ def respond_to_missing?(method_name, _include_private = false)
50
+ logger.trace("Checking if OpenHAB entites exist for #{method_name}")
51
+ method_name = method_name.to_s if method_name.is_a? Symbol
52
+
53
+ method_name == 'scriptLoaded' ||
54
+ method_name == 'scriptUnloaded' ||
55
+ EntityLookup.lookup_entity(method_name) ||
56
+ super
57
+ end
58
+
59
+ #
60
+ # Looks up an OpenHAB entity
61
+ # items are checked first, then things
62
+ #
63
+ # @param [String] name of entity to lookup in item or thing registry
64
+ #
65
+ # @return [Thing,Item] if found, nil otherwise
66
+ #
67
+ def self.lookup_entity(name)
68
+ lookup_item(name) || lookup_thing(name)
69
+ end
70
+
71
+ #
72
+ # Decorate items with Ruby wrappers
73
+ #
74
+ # @param [Array] items Array of items to decorate
75
+ #
76
+ # @return [Array] Array of decorated items
77
+ #
78
+ def self.decorate_items(*items)
79
+ items.flatten.map { |item| decorate_item(item) }
80
+ end
81
+
82
+ #
83
+ # Decorate item with Ruby wrappers
84
+ #
85
+ # @param [Object] item the item object to decorate
86
+ #
87
+ # @return [Object] the ruby wrapper for the item
88
+ #
89
+ # rubocop: disable Metrics/MethodLength
90
+ # rubocop: disable Metrics/AbcSize
91
+ # Disabled line length and branch size - case dispatch pattern
92
+ private_class_method def self.decorate_item(item)
93
+ case item
94
+ when GroupItem
95
+ decorate_group(item)
96
+ when Java::Org.openhab.core.library.items::NumberItem
97
+ OpenHAB::DSL::Items::NumberItem.new(item)
98
+ when Java::Org.openhab.core.library.items::StringItem
99
+ OpenHAB::DSL::Items::StringItem.new(item)
100
+ when Java::Org.openhab.core.library.items::DateTimeItem
101
+ OpenHAB::DSL::Items::DateTimeItem.new(item)
102
+ when Java::Org.openhab.core.library.items::RollershutterItem
103
+ OpenHAB::DSL::Items::RollershutterItem.new(item)
104
+ else
105
+ item
106
+ end
107
+ end
108
+ # rubocop: enable Metrics/AbcSize
109
+ # rubocop: enable Metrics/MethodLength
110
+
111
+ #
112
+ # Looks up a Thing in the OpenHAB registry replacing '_' with ':'
113
+ #
114
+ # @param [String] name of Thing to lookup in Thing registry
115
+ #
116
+ # @return [Thing] if found, nil otherwise
117
+ #
118
+ def self.lookup_thing(name)
119
+ logger.trace("Looking up thing(#{name})")
120
+ # Convert from : syntax to underscore
121
+ name = name.to_s if name.is_a? Symbol
122
+
123
+ # Thing UIDs have at least 3 segements
124
+ return if name.count('_') < 3
125
+
126
+ name = name.gsub('_', ':')
127
+ # rubocop: disable Style/GlobalVars
128
+ $things.get(Java::OrgOpenhabCoreThing::ThingUID.new(name))
129
+ # rubocop: enable Style/GlobalVars
130
+ end
131
+
132
+ #
133
+ # Lookup OpenHAB items in item registry
134
+ #
135
+ # @param [String] name of item to lookup
136
+ #
137
+ # @return [Item] OpenHAB item if registry contains a matching item, nil othewise
138
+ #
139
+ def self.lookup_item(name)
140
+ logger.trace("Looking up item(#{name})")
141
+ name = name.to_s if name.is_a? Symbol
142
+ # rubocop: disable Style/GlobalVars
143
+ item = $ir.get(name)
144
+ # rubocop: enable Style/GlobalVars
145
+ decorate_item(item)
146
+ end
147
+
148
+ #
149
+ # Decorate a group from an item base
150
+ #
151
+ # @param [OpenHAB item] item item to convert to a group item
152
+ #
153
+ # @return [OpenHAB::DSL::Groups::Group] Group created from supplied item
154
+ #
155
+ private_class_method def self.decorate_group(item)
156
+ group = OpenHAB::DSL::Groups::Group.new(Set.new(decorate_items(item.all_members.to_a)))
157
+ group.group = item
158
+ group
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ #
165
+ # Implements const_missing to return OpenHAB items or things if mapping to missing name if they exist
166
+ #
167
+ # @param [String] name Capital string that was not set as a constant and to be looked up
168
+ #
169
+ # @return [Object] OpenHAB Item or Thing if their name exist in OpenHAB item and thing regestries
170
+ #
171
+ def Object.const_missing(name)
172
+ OpenHAB::Core::EntityLookup.lookup_entity(name) || super
173
+ 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,49 @@
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/datetime_item'
17
+ require 'openhab/dsl/items/number_item'
18
+ require 'openhab/dsl/time_of_day'
19
+ require 'openhab/dsl/gems'
20
+ require 'openhab/dsl/persistence'
21
+ require 'openhab/dsl/units'
22
+ require 'openhab/dsl/types/datetime'
23
+ require 'openhab/dsl/types/quantity'
24
+ require 'openhab/dsl/states'
25
+
26
+ module OpenHAB
27
+ #
28
+ # Module to be extended to access the OpenHAB Ruby DSL
29
+ #
30
+ module DSL
31
+ # Extend the calling module/class with the DSL
32
+ # Disabling method length because they are all includes
33
+ # rubocop:disable Metrics/MethodLength
34
+ def self.extended(base)
35
+ base.send :include, OpenHAB::DSL::Actions
36
+ base.send :include, OpenHAB::DSL::Groups
37
+ base.send :include, OpenHAB::DSL::Items
38
+ base.send :include, OpenHAB::DSL::Persistence
39
+ base.send :include, OpenHAB::DSL::Rules
40
+ base.send :include, OpenHAB::DSL::States
41
+ base.send :include, OpenHAB::DSL::Things
42
+ base.send :include, OpenHAB::DSL::Timers
43
+ base.send :include, OpenHAB::DSL::TimeOfDay
44
+ base.send :include, OpenHAB::DSL::Types
45
+ base.send :include, OpenHAB::DSL::Units
46
+ end
47
+ # rubocop:enable Metrics/MethodLength
48
+ end
49
+ end