openhab-scripting 2.16.0 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab.rb +12 -16
  3. data/lib/openhab/core/entity_lookup.rb +162 -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 +47 -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/items.rb +46 -0
  11. data/lib/openhab/dsl/items/number_item.rb +352 -0
  12. data/lib/openhab/dsl/items/string_item.rb +120 -0
  13. data/lib/openhab/dsl/monkey_patch/actions/actions.rb +4 -0
  14. data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +32 -0
  15. data/lib/openhab/dsl/monkey_patch/events/events.rb +5 -0
  16. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +23 -0
  17. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +35 -0
  18. data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +33 -0
  19. data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +61 -0
  20. data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +193 -0
  21. data/lib/openhab/dsl/monkey_patch/items/group_item.rb +37 -0
  22. data/lib/openhab/dsl/monkey_patch/items/items.rb +133 -0
  23. data/lib/openhab/dsl/monkey_patch/items/metadata.rb +281 -0
  24. data/lib/openhab/dsl/monkey_patch/items/persistence.rb +70 -0
  25. data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +95 -0
  26. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +39 -0
  27. data/lib/openhab/dsl/monkey_patch/ruby/range.rb +47 -0
  28. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +7 -0
  29. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -0
  30. data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +70 -0
  31. data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +51 -0
  32. data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +36 -0
  33. data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +32 -0
  34. data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +69 -0
  35. data/lib/openhab/dsl/monkey_patch/types/types.rb +8 -0
  36. data/lib/openhab/dsl/persistence.rb +25 -0
  37. data/lib/openhab/dsl/rules/automation_rule.rb +342 -0
  38. data/lib/openhab/dsl/rules/guard.rb +134 -0
  39. data/lib/openhab/dsl/rules/property.rb +102 -0
  40. data/lib/openhab/dsl/rules/rule.rb +116 -0
  41. data/lib/openhab/dsl/rules/rule_config.rb +151 -0
  42. data/lib/openhab/dsl/rules/triggers/changed.rb +143 -0
  43. data/lib/openhab/dsl/rules/triggers/channel.rb +53 -0
  44. data/lib/openhab/dsl/rules/triggers/command.rb +104 -0
  45. data/lib/openhab/dsl/rules/triggers/cron.rb +177 -0
  46. data/lib/openhab/dsl/rules/triggers/trigger.rb +124 -0
  47. data/lib/openhab/dsl/rules/triggers/updated.rb +98 -0
  48. data/lib/openhab/dsl/states.rb +61 -0
  49. data/lib/openhab/dsl/things.rb +91 -0
  50. data/lib/openhab/dsl/time_of_day.rb +228 -0
  51. data/lib/openhab/dsl/timers.rb +77 -0
  52. data/lib/openhab/dsl/types/quantity.rb +290 -0
  53. data/lib/openhab/dsl/units.rb +39 -0
  54. data/lib/openhab/log/configuration.rb +21 -0
  55. data/lib/openhab/log/logger.rb +172 -0
  56. data/lib/openhab/version.rb +1 -1
  57. metadata +55 -58
  58. data/lib/openhab/configuration.rb +0 -16
  59. data/lib/openhab/core/cron.rb +0 -27
  60. data/lib/openhab/core/debug.rb +0 -34
  61. data/lib/openhab/core/dsl.rb +0 -51
  62. data/lib/openhab/core/dsl/actions.rb +0 -107
  63. data/lib/openhab/core/dsl/entities.rb +0 -140
  64. data/lib/openhab/core/dsl/group.rb +0 -93
  65. data/lib/openhab/core/dsl/items/items.rb +0 -51
  66. data/lib/openhab/core/dsl/items/number_item.rb +0 -323
  67. data/lib/openhab/core/dsl/items/string_item.rb +0 -122
  68. data/lib/openhab/core/dsl/monkey_patch/actions/actions.rb +0 -4
  69. data/lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb +0 -22
  70. data/lib/openhab/core/dsl/monkey_patch/events.rb +0 -5
  71. data/lib/openhab/core/dsl/monkey_patch/events/item_command.rb +0 -13
  72. data/lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb +0 -25
  73. data/lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb +0 -26
  74. data/lib/openhab/core/dsl/monkey_patch/items/contact_item.rb +0 -54
  75. data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +0 -182
  76. data/lib/openhab/core/dsl/monkey_patch/items/group_item.rb +0 -27
  77. data/lib/openhab/core/dsl/monkey_patch/items/items.rb +0 -132
  78. data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +0 -283
  79. data/lib/openhab/core/dsl/monkey_patch/items/persistence.rb +0 -72
  80. data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +0 -87
  81. data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +0 -41
  82. data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +0 -47
  83. data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +0 -7
  84. data/lib/openhab/core/dsl/monkey_patch/ruby/string.rb +0 -43
  85. data/lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb +0 -60
  86. data/lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb +0 -41
  87. data/lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb +0 -25
  88. data/lib/openhab/core/dsl/monkey_patch/types/percent_type.rb +0 -23
  89. data/lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb +0 -58
  90. data/lib/openhab/core/dsl/monkey_patch/types/types.rb +0 -8
  91. data/lib/openhab/core/dsl/persistence.rb +0 -27
  92. data/lib/openhab/core/dsl/property.rb +0 -96
  93. data/lib/openhab/core/dsl/rule/automation_rule.rb +0 -348
  94. data/lib/openhab/core/dsl/rule/guard.rb +0 -136
  95. data/lib/openhab/core/dsl/rule/rule.rb +0 -117
  96. data/lib/openhab/core/dsl/rule/rule_config.rb +0 -153
  97. data/lib/openhab/core/dsl/rule/triggers/changed.rb +0 -145
  98. data/lib/openhab/core/dsl/rule/triggers/channel.rb +0 -55
  99. data/lib/openhab/core/dsl/rule/triggers/command.rb +0 -106
  100. data/lib/openhab/core/dsl/rule/triggers/cron.rb +0 -160
  101. data/lib/openhab/core/dsl/rule/triggers/trigger.rb +0 -126
  102. data/lib/openhab/core/dsl/rule/triggers/updated.rb +0 -100
  103. data/lib/openhab/core/dsl/states.rb +0 -63
  104. data/lib/openhab/core/dsl/things.rb +0 -93
  105. data/lib/openhab/core/dsl/time_of_day.rb +0 -229
  106. data/lib/openhab/core/dsl/timers.rb +0 -79
  107. data/lib/openhab/core/dsl/types/quantity.rb +0 -292
  108. data/lib/openhab/core/dsl/units.rb +0 -41
  109. data/lib/openhab/core/log.rb +0 -170
  110. data/lib/openhab/core/patch_load_path.rb +0 -7
  111. data/lib/openhab/core/startup_delay.rb +0 -23
  112. data/lib/openhab/osgi.rb +0 -59
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '2.16.0'
8
+ VERSION = '2.17.0'
9
9
  end
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: 2.16.0
4
+ version: 2.17.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-02-10 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -32,62 +32,59 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - lib/openhab.rb
35
- - lib/openhab/configuration.rb
36
- - lib/openhab/core/cron.rb
37
- - lib/openhab/core/debug.rb
38
- - lib/openhab/core/dsl.rb
39
- - lib/openhab/core/dsl/actions.rb
40
- - lib/openhab/core/dsl/entities.rb
41
- - lib/openhab/core/dsl/gems.rb
42
- - lib/openhab/core/dsl/group.rb
43
- - lib/openhab/core/dsl/items/items.rb
44
- - lib/openhab/core/dsl/items/number_item.rb
45
- - lib/openhab/core/dsl/items/string_item.rb
46
- - lib/openhab/core/dsl/monkey_patch/actions/actions.rb
47
- - lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb
48
- - lib/openhab/core/dsl/monkey_patch/events.rb
49
- - lib/openhab/core/dsl/monkey_patch/events/item_command.rb
50
- - lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb
51
- - lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb
52
- - lib/openhab/core/dsl/monkey_patch/items/contact_item.rb
53
- - lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb
54
- - lib/openhab/core/dsl/monkey_patch/items/group_item.rb
55
- - lib/openhab/core/dsl/monkey_patch/items/items.rb
56
- - lib/openhab/core/dsl/monkey_patch/items/metadata.rb
57
- - lib/openhab/core/dsl/monkey_patch/items/persistence.rb
58
- - lib/openhab/core/dsl/monkey_patch/items/switch_item.rb
59
- - lib/openhab/core/dsl/monkey_patch/ruby/number.rb
60
- - lib/openhab/core/dsl/monkey_patch/ruby/range.rb
61
- - lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb
62
- - lib/openhab/core/dsl/monkey_patch/ruby/string.rb
63
- - lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb
64
- - lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb
65
- - lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb
66
- - lib/openhab/core/dsl/monkey_patch/types/percent_type.rb
67
- - lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb
68
- - lib/openhab/core/dsl/monkey_patch/types/types.rb
69
- - lib/openhab/core/dsl/persistence.rb
70
- - lib/openhab/core/dsl/property.rb
71
- - lib/openhab/core/dsl/rule/automation_rule.rb
72
- - lib/openhab/core/dsl/rule/guard.rb
73
- - lib/openhab/core/dsl/rule/rule.rb
74
- - lib/openhab/core/dsl/rule/rule_config.rb
75
- - lib/openhab/core/dsl/rule/triggers/changed.rb
76
- - lib/openhab/core/dsl/rule/triggers/channel.rb
77
- - lib/openhab/core/dsl/rule/triggers/command.rb
78
- - lib/openhab/core/dsl/rule/triggers/cron.rb
79
- - lib/openhab/core/dsl/rule/triggers/trigger.rb
80
- - lib/openhab/core/dsl/rule/triggers/updated.rb
81
- - lib/openhab/core/dsl/states.rb
82
- - lib/openhab/core/dsl/things.rb
83
- - lib/openhab/core/dsl/time_of_day.rb
84
- - lib/openhab/core/dsl/timers.rb
85
- - lib/openhab/core/dsl/types/quantity.rb
86
- - lib/openhab/core/dsl/units.rb
87
- - lib/openhab/core/log.rb
88
- - lib/openhab/core/patch_load_path.rb
89
- - lib/openhab/core/startup_delay.rb
90
- - lib/openhab/osgi.rb
35
+ - lib/openhab/core/entity_lookup.rb
36
+ - lib/openhab/core/openhab_setup.rb
37
+ - lib/openhab/core/osgi.rb
38
+ - lib/openhab/dsl/actions.rb
39
+ - lib/openhab/dsl/dsl.rb
40
+ - lib/openhab/dsl/gems.rb
41
+ - lib/openhab/dsl/group.rb
42
+ - lib/openhab/dsl/items/items.rb
43
+ - lib/openhab/dsl/items/number_item.rb
44
+ - lib/openhab/dsl/items/string_item.rb
45
+ - lib/openhab/dsl/monkey_patch/actions/actions.rb
46
+ - lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb
47
+ - lib/openhab/dsl/monkey_patch/events/events.rb
48
+ - lib/openhab/dsl/monkey_patch/events/item_command.rb
49
+ - lib/openhab/dsl/monkey_patch/events/item_state_changed.rb
50
+ - lib/openhab/dsl/monkey_patch/events/thing_status_info.rb
51
+ - lib/openhab/dsl/monkey_patch/items/contact_item.rb
52
+ - lib/openhab/dsl/monkey_patch/items/dimmer_item.rb
53
+ - lib/openhab/dsl/monkey_patch/items/group_item.rb
54
+ - lib/openhab/dsl/monkey_patch/items/items.rb
55
+ - lib/openhab/dsl/monkey_patch/items/metadata.rb
56
+ - lib/openhab/dsl/monkey_patch/items/persistence.rb
57
+ - lib/openhab/dsl/monkey_patch/items/switch_item.rb
58
+ - lib/openhab/dsl/monkey_patch/ruby/number.rb
59
+ - lib/openhab/dsl/monkey_patch/ruby/range.rb
60
+ - lib/openhab/dsl/monkey_patch/ruby/ruby.rb
61
+ - lib/openhab/dsl/monkey_patch/ruby/string.rb
62
+ - lib/openhab/dsl/monkey_patch/types/decimal_type.rb
63
+ - lib/openhab/dsl/monkey_patch/types/on_off_type.rb
64
+ - lib/openhab/dsl/monkey_patch/types/open_closed_type.rb
65
+ - lib/openhab/dsl/monkey_patch/types/percent_type.rb
66
+ - lib/openhab/dsl/monkey_patch/types/quantity_type.rb
67
+ - lib/openhab/dsl/monkey_patch/types/types.rb
68
+ - lib/openhab/dsl/persistence.rb
69
+ - lib/openhab/dsl/rules/automation_rule.rb
70
+ - lib/openhab/dsl/rules/guard.rb
71
+ - lib/openhab/dsl/rules/property.rb
72
+ - lib/openhab/dsl/rules/rule.rb
73
+ - lib/openhab/dsl/rules/rule_config.rb
74
+ - lib/openhab/dsl/rules/triggers/changed.rb
75
+ - lib/openhab/dsl/rules/triggers/channel.rb
76
+ - lib/openhab/dsl/rules/triggers/command.rb
77
+ - lib/openhab/dsl/rules/triggers/cron.rb
78
+ - lib/openhab/dsl/rules/triggers/trigger.rb
79
+ - lib/openhab/dsl/rules/triggers/updated.rb
80
+ - lib/openhab/dsl/states.rb
81
+ - lib/openhab/dsl/things.rb
82
+ - lib/openhab/dsl/time_of_day.rb
83
+ - lib/openhab/dsl/timers.rb
84
+ - lib/openhab/dsl/types/quantity.rb
85
+ - lib/openhab/dsl/units.rb
86
+ - lib/openhab/log/configuration.rb
87
+ - lib/openhab/log/logger.rb
91
88
  - lib/openhab/version.rb
92
89
  homepage: https://boc-tothefuture.github.io/openhab-jruby/
93
90
  licenses: []
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This module holds global configuration values
4
- module Configuration
5
- # -*- coding: utf-8 -*-
6
- LOG_PREFIX = 'jsr223.jruby'
7
-
8
- #
9
- # Gets the log prefix
10
- #
11
- # @return [String] Prefix for all log entries
12
- #
13
- def self.log_prefix
14
- LOG_PREFIX
15
- end
16
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module Core
5
- #
6
- # Module for Cron related methods
7
- #
8
- module Cron
9
- #
10
- # Retruns a default map for cron expressions that fires every second
11
- # This map is usually updated via merge by other methods to refine cron type triggers.
12
- #
13
- # @return [Map] Map with symbols for :seconds, :minute, :hour, :dom, :month, :dow configured to fire every second
14
- #
15
- def cron_expression_map
16
- {
17
- second: '*',
18
- minute: '*',
19
- hour: '*',
20
- dom: '?',
21
- month: '*',
22
- dow: '?'
23
- }
24
- end
25
- end
26
- end
27
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pp'
4
- require 'core/log'
5
- require 'core/dsl/things'
6
-
7
- #
8
- # Module to support debugging information about the Ruby or OpenHAB environment
9
- #
10
- module Debug
11
- include Logging
12
- include OpenHAB::Core::DSL::Things
13
-
14
- #
15
- # Print the loadpath, instance and global variables
16
- #
17
- def debug_variables
18
- pp "Instance #{instance_variables}"
19
- pp "Global #{global_variables}"
20
- pp "Load Path #{$LOAD_PATH}"
21
- # pp "Constants #{Module.constants}"
22
- end
23
-
24
- #
25
- # Print information about the OpenHAB instance
26
- #
27
- def debug_openhab
28
- logger.debug { "Things - Count #{things.size}" }
29
- things.each do |thing|
30
- logger.debug { "Thing:(#{thing.label}) UID:(#{thing.uid}) Channels(#{thing.channels.map(&:uid).join(', ')})" }
31
- end
32
- # logger.debug { $things.getAll.join(", ") }
33
- end
34
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
- require 'core/log'
5
- require 'core/dsl/monkey_patch/events'
6
- require 'core/dsl/monkey_patch/ruby/ruby'
7
- require 'core/dsl/monkey_patch/items/items'
8
- require 'core/dsl/monkey_patch/types/types'
9
- require 'core/dsl/monkey_patch/actions/actions'
10
- require 'core/dsl/rule/rule'
11
- require 'core/dsl/actions'
12
- require 'core/dsl/timers'
13
- require 'core/dsl/group'
14
- require 'core/dsl/things'
15
- require 'core/dsl/items/items'
16
- require 'core/dsl/items/number_item'
17
- require 'core/dsl/time_of_day'
18
- require 'core/dsl/gems'
19
- require 'core/dsl/units'
20
- require 'core/dsl/types/quantity'
21
- require 'core/dsl/states'
22
- require 'core/dsl/persistence'
23
-
24
- module OpenHAB
25
- #
26
- # Holds core functions for OpenHAB Helper Library
27
- #
28
- module Core
29
- #
30
- # Module to be extended to access the OpenHAB Ruby DSL
31
- #
32
- module DSL
33
- # Extend the calling module/class with the DSL
34
- # rubocop: disable Metrics/MethodLength
35
- def self.extended(base)
36
- base.send :include, OpenHAB::Core::DSL::Rule
37
- base.send :include, OpenHAB::Core::DSL::Items
38
- base.send :include, OpenHAB::Core::DSL::Types
39
- base.send :include, OpenHAB::Core::DSL::Groups
40
- base.send :include, OpenHAB::Core::DSL::Units
41
- base.send :include, OpenHAB::Core::DSL::Actions
42
- base.send :include, OpenHAB::Core::DSL::Timers
43
- base.send :include, OpenHAB::Core::DSL::States
44
- base.send :include, OpenHAB::Core::DSL::Tod
45
- base.send :include, OpenHAB::Core::DSL::Persistence
46
- base.send :include, Things
47
- end
48
- # rubocop: enable Metrics/MethodLength
49
- end
50
- end
51
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'java'
4
- require 'openhab/osgi'
5
-
6
- module OpenHAB
7
- module Core
8
- module DSL
9
- #
10
- # Module to import and steramlime access to OpenHAB actions
11
- #
12
- module Actions
13
- java_import org.openhab.core.library.types.PercentType
14
- include Logging
15
-
16
- OpenHAB::OSGI.services('org.openhab.core.model.script.engine.action.ActionService')&.each do |service|
17
- java_import service.actionClass.to_s
18
- logger.trace("Loaded ACTION: #{service.actionClass}")
19
- end
20
- # Import common actions
21
- %w[Exec HTTP Ping].each { |action| java_import "org.openhab.core.model.script.actions.#{action}" }
22
-
23
- #
24
- # Return an OpenHAB Action object for the given scope and thing
25
- #
26
- # @param scope [String] The action scope
27
- # @param thing_uid [String] Thing UID
28
- #
29
- # @return [Object] OpenHAB action
30
- #
31
- def actions(scope, thing_uid)
32
- # rubocop: disable Style/GlobalVars
33
- $actions.get(scope, thing_uid)
34
- # rubocop: enable Style/GlobalVars
35
- end
36
-
37
- #
38
- # Gets the list of action objects associated with a specific ThingUID
39
- #
40
- # @param [Java::org::openhab::core::thing::ThingUID] thing_uid to get associated actions for
41
- #
42
- # @return [Array] of action objects associated with thing_uid, may be empty
43
- #
44
- def actions_for_thing(thing_uid)
45
- thing_uid = thing_uid.to_s
46
- # rubocop: disable Style/GlobalVars
47
- action_keys = $actions.action_keys
48
- # rubocop: enable Style/GlobalVars
49
- logger.trace("Registered actions: '#{action_keys}' for thing '#{thing_uid}'")
50
- action_keys.map { |action_key| action_key.split('-', 2) }
51
- .select { |action_pair| action_pair.last == thing_uid }
52
- .map(&:first)
53
- .map { |scope| actions(scope, thing_uid) }
54
- end
55
-
56
- #
57
- # Send notification to an email or broadcast
58
- #
59
- # @param msg [String] The notification message to send
60
- # @param email [String] The email address to send to. If nil, the message will be broadcasted
61
- #
62
- # @return [void]
63
- #
64
- def notify(msg, email: nil)
65
- unless defined? NotificationAction
66
- raise NoMethodError, 'NotificationAction is not available. Please install the OpenHAB cloud addon'
67
- end
68
-
69
- if email
70
- NotificationAction.sendNotification email, msg
71
- else
72
- NotificationAction.sendBroadcastNotification msg
73
- end
74
- end
75
-
76
- #
77
- # Say text via OpenHAB Text-To-Speech service, Voice.say()
78
- #
79
- # @param text [String] The text to say
80
- # @param voice [String] Specify a particular voice to use
81
- # @param sink [String] Specify a particular sink to output the speech
82
- # @param volume [PercentType] Specify the volume for the speech
83
- #
84
- # @return [void]
85
- #
86
- def say(text, voice: nil, sink: nil, volume: nil)
87
- volume = PercentType.new(volume&.to_i) unless volume.is_a?(PercentType) || volume.nil?
88
- Voice.say text, voice, sink, volume
89
- end
90
-
91
- #
92
- # Play an audio file via OpenHAB sound service, Audio.playSound()
93
- #
94
- # @param filename [String] The sound file to play
95
- # @param sink [String] Specify a particular sink to output the speech
96
- # @param volume [PercentType] Specify the volume for the speech
97
- #
98
- # @return [void]
99
- #
100
- def play_sound(filename, sink: nil, volume: nil)
101
- volume = PercentType.new(volume&.to_i) unless volume.is_a?(PercentType) || volume.nil?
102
- Audio.playSound sink, filename, volume
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,140 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pp'
4
- require 'java'
5
- require 'set'
6
- require 'core/dsl/group'
7
- require 'core/log'
8
- require 'core/dsl/items/number_item'
9
- require 'core/dsl/items/string_item'
10
-
11
- # Automation lookup and injection of OpenHab entities
12
- java_import org.openhab.core.items.GroupItem
13
-
14
- #
15
- # Implements const_missing to return OpenHAB items or things if mapping to missing name if they exist
16
- #
17
- # @param [String] name Capital string that was not set as a constant and to be looked up
18
- #
19
- # @return [Object] OpenHAB Item or Thing if their name exist in OpenHAB item and thing regestries
20
- #
21
- def Object.const_missing(name)
22
- EntityLookup.lookup_item(name) || EntityLookup.lookup_thing(name) || super
23
- end
24
-
25
- #
26
- # Manages access to OpenHAB entities
27
- #
28
- module EntityLookup
29
- include Logging
30
- #
31
- # Decorate items with Ruby wrappers
32
- #
33
- # @param [Array] items Array of items to decorate
34
- #
35
- # @return [Array] Array of decorated items
36
- #
37
- # rubocop: disable Metrics/MethodLength
38
- # Disabled line length - case dispatch pattern
39
- def self.decorate_items(*items)
40
- items.flatten.map do |item|
41
- case item
42
- when GroupItem
43
- decorate_group(item)
44
- when Java::Org.openhab.core.library.items::NumberItem
45
- OpenHAB::Core::DSL::Items::NumberItem.new(item)
46
- when Java::Org.openhab.core.library.items::StringItem
47
- OpenHAB::Core::DSL::Items::StringItem.new(item)
48
- else
49
- item
50
- end
51
- end
52
- end
53
- # rubocop: enable Metrics/MethodLength
54
-
55
- #
56
- # Loops up a Thing in the OpenHAB registry replacing '_' with ':'
57
- #
58
- # @param [String] name of Thing to lookup in Thing registry
59
- #
60
- # @return [Thing] if found, nil otherwise
61
- #
62
- def self.lookup_thing(name)
63
- logger.trace("Looking up thing(#{name})")
64
- # Convert from : syntax to underscore
65
- name = name.to_s if name.is_a? Symbol
66
-
67
- # Thing UIDs have at least 3 segements
68
- return if name.count('_') < 3
69
-
70
- name = name.gsub('_', ':')
71
- # rubocop: disable Style/GlobalVars
72
- $things.get(Java::OrgOpenhabCoreThing::ThingUID.new(name))
73
- # rubocop: enable Style/GlobalVars
74
- end
75
-
76
- #
77
- # Lookup OpenHAB items in item registry
78
- #
79
- # @param [String] name of item to lookup
80
- #
81
- # @return [Item] OpenHAB item if registry contains a matching item, nil othewise
82
- #
83
- def self.lookup_item(name)
84
- logger.trace("Looking up item(#{name})")
85
- name = name.to_s if name.is_a? Symbol
86
- # rubocop: disable Style/GlobalVars
87
- item = $ir.get(name)
88
- # rubocop: enable Style/GlobalVars
89
- EntityLookup.decorate_items(item).first
90
- end
91
-
92
- #
93
- # Automatically looks up OpenHAB items and things in appropriate registries
94
- #
95
- # @param [method] method Name of item to lookup
96
- # @param [<Type>] args method arguments
97
- # @param [<Type>] block supplied to missing method
98
- #
99
- # @return [Object] Item or Thing if found in registry
100
- #
101
- def method_missing(method, *args, &block)
102
- return if method.to_s == 'scriptLoaded'
103
- return if method.to_s == 'scriptUnloaded'
104
-
105
- logger.trace("method missing, performing OpenHab Lookup for: #{method}")
106
- EntityLookup.lookup_item(method) || EntityLookup.lookup_thing(method) || super
107
- end
108
-
109
- #
110
- # Checks if this method responds to the missing method
111
- #
112
- # @param [String] method_name Name of the method to check
113
- # @param [Boolean] _include_private boolean if private methods should be checked
114
- #
115
- # @return [Boolean] true if this object will respond to the supplied method, false otherwise
116
- #
117
- def respond_to_missing?(method_name, _include_private = false)
118
- logger.trace("Checking if OpenHAB entites exist for #{method_name}")
119
- method_name = method_name.to_s if method_name.is_a? Symbol
120
-
121
- method_name == 'scriptLoaded' ||
122
- method_name == 'scriptUnloaded' ||
123
- EntityLookup.lookup_item(method_name) ||
124
- EntityLookup.lookup_thing(method_name) ||
125
- super
126
- end
127
-
128
- #
129
- # Decorate a group from an item base
130
- #
131
- # @param [OpenHAB item] item item to convert to a group item
132
- #
133
- # @return [OpenHAB::Core::DSL::Groups::Group] Group created from supplied item
134
- #
135
- def self.decorate_group(item)
136
- group = OpenHAB::Core::DSL::Groups::Group.new(Set.new(EntityLookup.decorate_items(item.all_members.to_a)))
137
- group.group = item
138
- group
139
- end
140
- end