openhab-scripting 2.16.1 → 2.18.0

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