openhab-jrubyscripting 5.0.0.rc5 → 5.0.0.rc6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/actions.rb +6 -6
  3. data/lib/openhab/core/dependency_tracking.rb +34 -0
  4. data/lib/openhab/core/entity_lookup.rb +132 -78
  5. data/lib/openhab/core/events/item_channel_link.rb +2 -2
  6. data/lib/openhab/core/events/item_command_event.rb +1 -1
  7. data/lib/openhab/core/events/item_event.rb +2 -2
  8. data/lib/openhab/core/events/item_state_changed_event.rb +1 -1
  9. data/lib/openhab/core/events/thing.rb +1 -1
  10. data/lib/openhab/core/items/accepted_data_types.rb +2 -2
  11. data/lib/openhab/core/items/contact_item.rb +1 -1
  12. data/lib/openhab/core/items/dimmer_item.rb +2 -2
  13. data/lib/openhab/core/items/generic_item.rb +45 -224
  14. data/lib/openhab/core/items/group_item.rb +5 -3
  15. data/lib/openhab/core/items/image_item.rb +2 -2
  16. data/lib/openhab/core/items/item.rb +219 -0
  17. data/lib/openhab/core/items/metadata/hash.rb +1 -1
  18. data/lib/openhab/core/items/persistence.rb +4 -5
  19. data/lib/openhab/core/items/provider.rb +2 -2
  20. data/lib/openhab/core/items/proxy.rb +68 -7
  21. data/lib/openhab/core/items/registry.rb +6 -6
  22. data/lib/openhab/core/items/semantics/enumerable.rb +6 -6
  23. data/lib/openhab/core/items/semantics.rb +8 -7
  24. data/lib/openhab/core/items.rb +2 -1
  25. data/lib/openhab/core/provider.rb +14 -7
  26. data/lib/openhab/core/rules/registry.rb +2 -2
  27. data/lib/openhab/core/rules.rb +1 -1
  28. data/lib/openhab/core/script_handling.rb +6 -6
  29. data/lib/openhab/core/things/channel.rb +1 -1
  30. data/lib/openhab/core/things/channel_uid.rb +2 -2
  31. data/lib/openhab/core/things/item_channel_link.rb +2 -2
  32. data/lib/openhab/core/things/links/provider.rb +2 -2
  33. data/lib/openhab/core/things/registry.rb +1 -1
  34. data/lib/openhab/core/things/thing.rb +1 -1
  35. data/lib/openhab/core/types/date_time_type.rb +4 -4
  36. data/lib/openhab/core/types/hsb_type.rb +2 -2
  37. data/lib/openhab/core/types/quantity_type.rb +1 -1
  38. data/lib/openhab/core/types.rb +1 -1
  39. data/lib/openhab/core/uid.rb +1 -1
  40. data/lib/openhab/core/value_cache.rb +188 -0
  41. data/lib/openhab/core.rb +57 -15
  42. data/lib/openhab/core_ext/ruby/symbol.rb +7 -0
  43. data/lib/openhab/dsl/items/builder.rb +17 -10
  44. data/lib/openhab/dsl/items/ensure.rb +5 -5
  45. data/lib/openhab/dsl/items/timed_command.rb +4 -4
  46. data/lib/openhab/dsl/rules/automation_rule.rb +53 -39
  47. data/lib/openhab/dsl/rules/builder.rb +128 -79
  48. data/lib/openhab/dsl/rules/guard.rb +5 -5
  49. data/lib/openhab/dsl/rules/name_inference.rb +20 -1
  50. data/lib/openhab/dsl/rules/rule_triggers.rb +3 -3
  51. data/lib/openhab/dsl/rules/terse.rb +1 -0
  52. data/lib/openhab/dsl/rules/triggers/changed.rb +26 -23
  53. data/lib/openhab/dsl/rules/triggers/command.rb +6 -5
  54. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +2 -2
  55. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +2 -2
  56. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +6 -6
  57. data/lib/openhab/dsl/rules/triggers/updated.rb +5 -5
  58. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +11 -12
  59. data/lib/openhab/dsl/things/builder.rb +73 -14
  60. data/lib/openhab/dsl/version.rb +2 -2
  61. data/lib/openhab/dsl.rb +43 -17
  62. data/lib/openhab/log.rb +5 -5
  63. data/lib/openhab/rspec/configuration.rb +5 -5
  64. data/lib/openhab/rspec/example_group.rb +1 -1
  65. data/lib/openhab/rspec/helpers.rb +4 -4
  66. data/lib/openhab/rspec/hooks.rb +19 -1
  67. data/lib/openhab/rspec/karaf.rb +12 -19
  68. data/lib/openhab/rspec/suspend_rules.rb +2 -1
  69. data/lib/openhab/yard/base_helper.rb +46 -0
  70. data/lib/openhab/yard/markdown_directive.rb +125 -0
  71. data/lib/openhab/yard/markdown_helper.rb +99 -0
  72. metadata +10 -3
@@ -18,7 +18,7 @@ module OpenHAB
18
18
  # @param [Object] command to check against
19
19
  # @param [Object] attach object to be attached to the trigger
20
20
  #
21
- # @return [Trigger] OpenHAB triggers
21
+ # @return [org.openhab.core.automation.Trigger]
22
22
  #
23
23
  def trigger(item:, command:, attach:)
24
24
  case command
@@ -31,9 +31,9 @@ module OpenHAB
31
31
  #
32
32
  # Creates a trigger with a range condition on the 'command' field
33
33
  # @param [Object] item to create changed trigger on
34
- # @param [Object] command to restrict trigger to
34
+ # @param [Range] command to restrict trigger to
35
35
  # @param [Object] attach object to be attached to the trigger
36
- # @return [Trigger] OpenHAB trigger
36
+ # @return [org.openhab.core.automation.Trigger]
37
37
  #
38
38
  def range_trigger(item:, command:, attach:)
39
39
  command_range, * = Conditions::Proc.range_procs(command)
@@ -45,7 +45,7 @@ module OpenHAB
45
45
  # @param [Object] item to create changed trigger on
46
46
  # @param [Object] command to restrict trigger to
47
47
  # @param [Object] attach object to be attached to the trigger
48
- # @return [Trigger] OpenHAB trigger
48
+ # @return [org.openhab.core.automation.Trigger]
49
49
  #
50
50
  def proc_trigger(item:, command:, attach:)
51
51
  conditions = Conditions::Proc.new(command: command)
@@ -58,6 +58,7 @@ module OpenHAB
58
58
  # @param [Object] item to create trigger for
59
59
  # @param [String] command to create trigger for
60
60
  # @param [Object] attach object to be attached to the trigger
61
+ # @return [org.openhab.core.automation.Trigger]
61
62
  #
62
63
  def command_trigger(item:, command:, attach: nil, conditions: nil)
63
64
  type, config = if item.is_a?(GroupItem::Members)
@@ -92,7 +93,7 @@ module OpenHAB
92
93
  #
93
94
  # Create trigger for group items
94
95
  #
95
- # @param [Group] group to create trigger for
96
+ # @param [GroupItem::Members] group to create trigger for
96
97
  #
97
98
  # @return [Array<Hash,Trigger>] first element is hash of trigger config properties
98
99
  # second element is trigger type
@@ -57,7 +57,7 @@ module OpenHAB
57
57
  #
58
58
  # Check if trigger guards prevent rule execution
59
59
  #
60
- # @param [Map] inputs OpenHAB map object describing rule trigger
60
+ # @param [java.util.Map] inputs map object describing rule trigger
61
61
  #
62
62
  # @return [true,false] True if the rule should execute, false if trigger guard prevents execution
63
63
  #
@@ -70,7 +70,7 @@ module OpenHAB
70
70
  # Rerieve the newState and oldState, alternatively newStatus and oldStatus
71
71
  # from the input map
72
72
  #
73
- # @param [Map] inputs OpenHAB map object describing rule trigger
73
+ # @param [java.util.Map] inputs map object describing rule trigger
74
74
  #
75
75
  # @return [Array] An array of the values for [newState, oldState] or [newStatus, oldStatus]
76
76
  #
@@ -33,7 +33,7 @@ module OpenHAB
33
33
  }.freeze
34
34
  private_constant :CRON_EXPRESSION_MAP
35
35
 
36
- # @return [Hash] Map of days of the week from symbols to to OpenHAB cron strings
36
+ # @return [Hash] Map of days of the week from symbols to to openHAB cron strings
37
37
  DAY_OF_WEEK_MAP = {
38
38
  monday: "MON",
39
39
  tuesday: "TUE",
@@ -134,7 +134,7 @@ module OpenHAB
134
134
  #
135
135
  # @param [Map] map of cron expression
136
136
  #
137
- # @return [String] OpenHAB cron string
137
+ # @return [String] openHAB cron string
138
138
  #
139
139
  def self.map_to_cron(map)
140
140
  %i[second minute hour dom month dow year].map { |field| map.fetch(field) }.join(" ")
@@ -12,7 +12,7 @@ module OpenHAB
12
12
  #
13
13
  module CronHandler
14
14
  # Cron Trigger Handler that provides trigger IDs
15
- # Unfortunatly because the CronTriggerHandler in OpenHAB core is marked internal
15
+ # Unfortunatly because the CronTriggerHandler in openHAB core is marked internal
16
16
  # the entire thing must be recreated here
17
17
  class CronTriggerHandler < org.openhab.core.automation.handler.BaseTriggerModuleHandler
18
18
  include org.openhab.core.scheduler.SchedulerRunnable
@@ -22,7 +22,7 @@ module OpenHAB
22
22
  field_accessor :callback
23
23
 
24
24
  # Creates a new CronTriggerHandler
25
- # @param [Trigger] trigger OpenHAB trigger associated with handler
25
+ # @param [org.openhab.core.automation.Trigger] trigger openHAB trigger associated with handler
26
26
  #
27
27
  def initialize(trigger)
28
28
  @trigger = trigger
@@ -79,8 +79,8 @@ module OpenHAB
79
79
  class CronTriggerHandlerFactory
80
80
  include org.openhab.core.automation.module.script.rulesupport.shared.factories.ScriptedTriggerHandlerFactory
81
81
 
82
- # Invoked by the OpenHAB core to get a trigger handler for the supllied trigger
83
- # @param [Trigger] trigger OpenHAB trigger
82
+ # Invoked by openHAB core to get a trigger handler for the supllied trigger
83
+ # @param [org.openhab.core.automation.Trigger] trigger
84
84
  #
85
85
  # @return [WatchTriggerHandler] trigger handler for supplied trigger
86
86
  def get(trigger)
@@ -92,7 +92,7 @@ module OpenHAB
92
92
  private
93
93
 
94
94
  #
95
- # Creates trigger types and trigger type factories for OpenHAB
95
+ # Creates trigger types and trigger type factories for openHAB
96
96
  #
97
97
  def add_script_cron_handler
98
98
  Core.automation_manager.add_trigger_handler(
@@ -105,7 +105,7 @@ module OpenHAB
105
105
  end
106
106
 
107
107
  #
108
- # Creates trigger types and trigger type factories for OpenHAB
108
+ # Creates trigger types and trigger type factories for openHAB
109
109
  #
110
110
  def cron_trigger_type
111
111
  org.openhab.core.automation.type.TriggerType.new(
@@ -18,7 +18,7 @@ module OpenHAB
18
18
  # @param [Item State] to state to restrict trigger to
19
19
  # @param [Object] attach object to be attached to the trigger
20
20
  #
21
- # @return [Trigger] OpenHAB triggers
21
+ # @return [org.openhab.core.automation.Trigger]
22
22
  #
23
23
  def trigger(item:, to:, attach:)
24
24
  case to
@@ -44,7 +44,7 @@ module OpenHAB
44
44
  # @param [Object] item to create changed trigger on
45
45
  # @param [Object] to state restrict trigger to
46
46
  # @param [Object] attach object to be attached to the trigger
47
- # @return [Trigger] OpenHAB trigger
47
+ # @return [org.openhab.core.automation.Trigger]
48
48
  #
49
49
  def range_trigger(item:, to:, attach:)
50
50
  to, * = Conditions::Proc.range_procs(to)
@@ -56,7 +56,7 @@ module OpenHAB
56
56
  # @param [Object] item to create changed trigger on
57
57
  # @param [Object] to state restrict trigger to
58
58
  # @param [Object] attach object to be attached to the trigger
59
- # @return [Trigger] OpenHAB trigger
59
+ # @return [org.openhab.core.automation.Trigger]
60
60
  #
61
61
  def proc_trigger(item:, to:, attach:)
62
62
  conditions = Conditions::Proc.new(to: to)
@@ -70,7 +70,7 @@ module OpenHAB
70
70
  # @param [State] to state restriction on trigger
71
71
  # @param [Object] attach object to be attached to the trigger
72
72
  #
73
- # @return [Trigger] OpenHAB triggers
73
+ # @return [org.openhab.core.automation.Trigger]
74
74
  #
75
75
  def update_trigger(item:, to:, attach: nil, conditions: nil)
76
76
  type, config = case item
@@ -103,7 +103,7 @@ module OpenHAB
103
103
  #
104
104
  # Create an update trigger for a group
105
105
  #
106
- # @param [Item] item to create trigger for
106
+ # @param [GroupItem::Members] item to create trigger for
107
107
  # @param [State] to optional state restriction for target
108
108
  #
109
109
  # @return [Array<Hash,String>] first element is a String specifying trigger type
@@ -10,7 +10,7 @@ module OpenHAB
10
10
  #
11
11
  module WatchHandler
12
12
  #
13
- # Creates trigger types and trigger type factories for OpenHAB
13
+ # Creates trigger types and trigger type factories for openHAB
14
14
  #
15
15
  private_class_method def self.watch_trigger_type
16
16
  org.openhab.core.automation.type.TriggerType.new(
@@ -27,7 +27,7 @@ module OpenHAB
27
27
  # Trigger ID for Watch Triggers
28
28
  WATCH_TRIGGER_MODULE_ID = "jsr223.jruby.WatchTrigger"
29
29
 
30
- # Extends the OpenHAB watch service to watch directories
30
+ # Extends the openHAB watch service to watch directories
31
31
  #
32
32
  # Must match java method name style
33
33
  # rubocop:disable Naming/MethodName
@@ -75,12 +75,12 @@ module OpenHAB
75
75
  end
76
76
  # rubocop:enable Naming/MethodName
77
77
 
78
- # Implements the OpenHAB TriggerHandler interface to process Watch Triggers
78
+ # Implements the openHAB TriggerHandler interface to process Watch Triggers
79
79
  class WatchTriggerHandler
80
80
  include org.openhab.core.automation.handler.TriggerHandler
81
81
 
82
82
  # Creates a new WatchTriggerHandler
83
- # @param [Trigger] trigger OpenHAB trigger associated with handler
83
+ # @param [org.openhab.core.automation.Trigger] trigger
84
84
  #
85
85
  def initialize(trigger)
86
86
  @trigger = trigger
@@ -94,21 +94,20 @@ module OpenHAB
94
94
  # Create a lambda to use to invoke rule engine when file watch notification happens
95
95
  # @param [String] glob to match for notification events
96
96
  #
97
- # @return [Lambda] lambda to execute on notification events
97
+ # @return [Proc] lambda to execute on notification events
98
98
  #
99
99
  def watch_event_handler(glob)
100
- lambda { |watch_event|
100
+ lambda do |watch_event|
101
101
  if watch_event.path.fnmatch?(glob)
102
102
  logger.trace("Received event(#{watch_event})")
103
103
  @rule_engine_callback&.triggered(@trigger, { "event" => watch_event })
104
104
  else
105
105
  logger.trace("Event #{watch_event} did not match glob(#{glob})")
106
106
  end
107
- }
107
+ end
108
108
  end
109
109
 
110
- # Called by OpenHAB to set the rule engine to invoke when triggered
111
- # Must match java method name style
110
+ # Called by openHAB to set the rule engine to invoke when triggered
112
111
  def setCallback(callback) # rubocop:disable Naming/MethodName
113
112
  @rule_engine_callback = callback
114
113
  end
@@ -126,8 +125,8 @@ module OpenHAB
126
125
  class WatchTriggerHandlerFactory
127
126
  include org.openhab.core.automation.module.script.rulesupport.shared.factories.ScriptedTriggerHandlerFactory
128
127
 
129
- # Invoked by the OpenHAB core to get a trigger handler for the supllied trigger
130
- # @param [Trigger] trigger OpenHAB trigger
128
+ # Invoked by openHAB core to get a trigger handler for the supllied trigger
129
+ # @param [org.openhab.core.automation.Trigger] trigger
131
130
  #
132
131
  # @return [WatchTriggerHandler] trigger handler for supplied trigger
133
132
  def get(trigger)
@@ -136,7 +135,7 @@ module OpenHAB
136
135
  end
137
136
 
138
137
  #
139
- # Creates trigger types and trigger type factories for OpenHAB
138
+ # Creates trigger types and trigger type factories for openHAB
140
139
  #
141
140
  def self.add_watch_handler
142
141
  Core.automation_manager.add_trigger_handler(
@@ -6,14 +6,36 @@ module OpenHAB
6
6
  # Contains extensions to simplify working with {Core::Things::Thing Thing}s.
7
7
  #
8
8
  module Things
9
- # A thing builder allows you to dynamically create OpenHAB thing at runtime.
9
+ # A thing builder allows you to dynamically create openHAB things at runtime.
10
10
  # This can be useful either to create things as soon as the script loads,
11
11
  # or even later based on a rule executing.
12
12
  #
13
- # @example
13
+ # @example Create a Thing from the Astro Binding
14
14
  # things.build do
15
15
  # thing "astro:sun:home", "Astro Sun Data", config: { "geolocation" => "0,0" }
16
16
  # end
17
+ #
18
+ # @example Create a Thing with Channels
19
+ # thing_config = {
20
+ # availabilityTopic: "my-switch/status",
21
+ # payloadAvailable: "online",
22
+ # payloadNotAvailable: "offline"
23
+ # }
24
+ # things.build do
25
+ # thing("mqtt:topic:my-switch", "My Switch", bridge: "mqtt:bridge:mosquitto", config: thing_config) do
26
+ # channel("switch1", "switch", config: {
27
+ # stateTopic: "stat/my-switch/switch1/state", commandTopic="cmnd/my-switch/switch1/command"
28
+ # })
29
+ # channel("button1", "string", config: {
30
+ # stateTopic: "stat/my-switch/button1/state", commandTopic="cmnd/my-switch/button1/command"
31
+ # })
32
+ # end
33
+ # end
34
+ #
35
+ # @see ThingBuilder#initialize ThingBuilder#initialize for #thing's parameters
36
+ # @see ChannelBuilder#initialize ChannelBuilder#initialize for #channel's parameters
37
+ # @see Items::Builder
38
+ #
17
39
  class Builder
18
40
  # @return [org.openhab.core.things.ManagedThingProvider]
19
41
  attr_reader :provider
@@ -96,6 +118,26 @@ module OpenHAB
96
118
  end
97
119
  end
98
120
 
121
+ #
122
+ # Constructor for ThingBuilder
123
+ #
124
+ # @param [String] uid The ThingUID for the created Thing.
125
+ # This can consist one or more segments separated by a colon. When the uid contains:
126
+ # - One segment: When the uid contains one segment, `binding` or `bridge` id must be provided.
127
+ # - Two segments: `typeid:thingid` The `binding` or `bridge` id must be provided.
128
+ # - Three or more segments: `bindingid:typeid:[bridgeid...]:thingid`. The `type` and `bridge` can be omitted
129
+ # @param [String] label The Thing's label.
130
+ # @param [String] binding The binding id. When this argument is not provided,
131
+ # the binding id must be deducible from the `uid`, `type`, or `bridge`.
132
+ # @param [String] type The type id. When this argument is not provided,
133
+ # it will be deducible from the `uid` if it contains two or more segments.
134
+ # To create a Thing with a blank type id, use one segment for `uid` and provide the binding id.
135
+ # @param [String, BridgeBuilder] bridge The bridge uid, if the Thing should belong to a bridge.
136
+ # @param [String, Item] location The location of this Thing.
137
+ # When given an Item, use the item's label as the location.
138
+ # @param [Hash] config The Thing's configuration, as required by the binding. The key can be strings or symbols.
139
+ # @param [true,false] enabled Whether the Thing should be enabled or disabled.
140
+ #
99
141
  def initialize(uid, label = nil, binding: nil, type: nil, bridge: nil, location: nil, config: {}, enabled: nil)
100
142
  @channels = []
101
143
  uid = uid.to_s
@@ -117,13 +159,18 @@ module OpenHAB
117
159
  @bridge_uid = org.openhab.core.thing.ThingUID.new(*bridge_segments)
118
160
  end
119
161
 
120
- @uid = org.openhab.core.thing.ThingUID.new(*[binding, type, @bridge_uid&.id,
121
- uid_segments.last].compact)
162
+ thinguid = if uid_segments.length > 2
163
+ [binding, type, uid_segments.last].compact
164
+ else
165
+ [binding, type, @bridge_uid&.id, uid_segments.last].compact
166
+ end
167
+
168
+ @uid = org.openhab.core.thing.ThingUID.new(*thinguid)
122
169
  @thing_type_uid = org.openhab.core.thing.ThingTypeUID.new(*@uid.all_segments[0..1])
123
170
  @label = label
124
171
  @location = location
125
- @location = location.label if location.is_a?(GenericItem)
126
- @config = config
172
+ @location = location.label if location.is_a?(Item)
173
+ @config = config.transform_keys(&:to_s)
127
174
  @enabled = enabled
128
175
  end
129
176
 
@@ -132,7 +179,7 @@ module OpenHAB
132
179
  def channel(*args, **kwargs, &block)
133
180
  channel = ChannelBuilder.new(*args, thing: self, **kwargs)
134
181
  channel.instance_eval(&block) if block
135
- @channels << channel
182
+ @channels << channel.build
136
183
  end
137
184
 
138
185
  # @!visibility private
@@ -190,9 +237,22 @@ module OpenHAB
190
237
  # The ChannelBuilder DSL allows you to customize a channel
191
238
  class ChannelBuilder
192
239
  attr_accessor :label
193
- attr_reader :uid, :parameters
240
+ attr_reader :uid, :config, :type
194
241
 
195
- def initialize(uid, type, label, thing:, group: nil, **parameters)
242
+ #
243
+ # Constructor for ChannelBuilder
244
+ #
245
+ # This class is instantiated by the {ThingBuilder#channel #channel} method inside a {Builder#thing} block.
246
+ #
247
+ # @param [String] uid The channel's ID.
248
+ # @param [String, ChannelTypeUID, :trigger] type The concrete type of the channel.
249
+ # @param [String] label The channel label.
250
+ # @param [thing] thing The thing associated with this channel.
251
+ # This parameter is not needed for the {ThingBuilder#channel} method.
252
+ # @param [String] group The group name.
253
+ # @param [Hash] config Channel configuration. The keys can be strings or symbols.
254
+ #
255
+ def initialize(uid, type, label = nil, thing:, group: nil, config: {})
196
256
  @thing = thing
197
257
 
198
258
  uid = uid.to_s
@@ -207,13 +267,12 @@ module OpenHAB
207
267
  uid_segments[-1] = group_segments.join(org.openhab.core.thing.ChannelUID::CHANNEL_GROUP_SEPARATOR)
208
268
  end
209
269
  @uid = org.openhab.core.thing.ChannelUID.new(thing.uid, uid_segments.last)
210
- unless type.is_a?(org.openhab.core.thing.ChannelTypeUID)
211
- type = org.openhab.core.thing.ChannelTypeUID.new(thing.uid.binding_id,
212
- type)
270
+ unless type.is_a?(org.openhab.core.thing.type.ChannelTypeUID)
271
+ type = org.openhab.core.thing.type.ChannelTypeUID.new(thing.uid.binding_id, type)
213
272
  end
214
273
  @type = type
215
274
  @label = label
216
- @parameters = parameters
275
+ @config = config.transform_keys(&:to_s)
217
276
  end
218
277
 
219
278
  # @!visibility private
@@ -221,7 +280,7 @@ module OpenHAB
221
280
  org.openhab.core.thing.binding.builder.ChannelBuilder.create(uid)
222
281
  .with_kind(kind)
223
282
  .with_type(type)
224
- .with_configuration(org.openhab.core.config.core.Configuration.new(parameters))
283
+ .with_configuration(org.openhab.core.config.core.Configuration.new(config))
225
284
  .build
226
285
  end
227
286
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  module OpenHAB
4
4
  module DSL
5
- # Version of OpenHAB helper libraries
5
+ # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.0.0.rc5"
7
+ VERSION = "5.0.0.rc6"
8
8
  end
9
9
  end
data/lib/openhab/dsl.rb CHANGED
@@ -16,7 +16,7 @@ end
16
16
  require_relative "core_ext"
17
17
 
18
18
  #
19
- # Main OpenHAB Module
19
+ # Main openHAB Module
20
20
  #
21
21
  module OpenHAB
22
22
  #
@@ -69,7 +69,7 @@ module OpenHAB
69
69
  # The state being sent for `:state_from_item` and `:state_from_handler` events.
70
70
  # @yieldparam [Core::Things::ItemChannelLink] link
71
71
  # The link between the item and the channel, including its configuration.
72
- # @yieldparam [GenericItem] item The linked item.
72
+ # @yieldparam [Item] item The linked item.
73
73
  # @yieldparam [Core::Things::ChannelUID] channel_uid The linked channel.
74
74
  # @yieldparam [Hash] configuration The profile configuration.
75
75
  # @yieldparam [org.openhab.core.thing.profiles.ProfileContext] context The profile context.
@@ -106,6 +106,19 @@ module OpenHAB
106
106
 
107
107
  # @!group Object Access
108
108
 
109
+ #
110
+ # (see Core::ValueCache)
111
+ #
112
+ # @return [Core::ValueCache] the cache shared among all scripts and UI rules in all languages.
113
+ #
114
+ # @see Core::ValueCache ValueCache
115
+ #
116
+ # @since openHAB 3.4.0
117
+ #
118
+ def shared_cache
119
+ $sharedCache
120
+ end
121
+
109
122
  #
110
123
  # Fetches all rules from the rule registry.
111
124
  #
@@ -141,7 +154,7 @@ module OpenHAB
141
154
  #
142
155
  # @example
143
156
  # rule 'search for a suitable item' do
144
- # on_start
157
+ # on_load
145
158
  # triggered do
146
159
  # # Send ON to DimmerTest if it exists, otherwise send it to SwitchTest
147
160
  # (items['DimmerTest'] || items['SwitchTest'])&.on
@@ -153,9 +166,9 @@ module OpenHAB
153
166
  end
154
167
 
155
168
  #
156
- # Get all things known to OpenHAB
169
+ # Get all things known to openHAB
157
170
  #
158
- # @return [Core::Things::Registry] all Thing objects known to OpenHAB
171
+ # @return [Core::Things::Registry] all Thing objects known to openHAB
159
172
  #
160
173
  # @example
161
174
  # things.each { |thing| logger.info("Thing: #{thing.uid}")}
@@ -171,7 +184,7 @@ module OpenHAB
171
184
  end
172
185
 
173
186
  #
174
- # Provides access to timers created by {after}
187
+ # Provides access to timers created by {after after}
175
188
  #
176
189
  # @return [TimerManager]
177
190
  def timers
@@ -186,7 +199,8 @@ module OpenHAB
186
199
  # ### Reentrant Timers
187
200
  #
188
201
  # Timers with an id are reentrant by id. Reentrant means that when the same id is encountered,
189
- # the timer is rescheduled rather than creating a second new timer.
202
+ # the timer is rescheduled rather than creating a second new timer. Note that the timer will
203
+ # execute the block provided in the latest call.
190
204
  #
191
205
  # This removes the need for the usual boilerplate code to manually keep track of timer objects.
192
206
  #
@@ -194,7 +208,7 @@ module OpenHAB
194
208
  #
195
209
  # When a timer is cancelled, it will be removed from the object.
196
210
  #
197
- # Be sure that your ids are unique. For example, if you're using {GenericItem items} as your
211
+ # Be sure that your ids are unique. For example, if you're using {Item items} as your
198
212
  # ids, you either need to be sure you don't use the same item for multiple logical contexts,
199
213
  # or you need to make your id more specific, by doing something like embedding the item in
200
214
  # array with a symbol of the timer's purpose, like `[:vacancy, item]`. But also note that
@@ -221,7 +235,7 @@ module OpenHAB
221
235
  # logger.info("Timer Fired")
222
236
  # end
223
237
  #
224
- # @example Timers delegate methods to OpenHAB timer objects
238
+ # @example Timers delegate methods to openHAB timer objects
225
239
  # after 1.second do |timer|
226
240
  # logger.info("Timer is active? #{timer.active?}")
227
241
  # end
@@ -267,9 +281,21 @@ module OpenHAB
267
281
  # end
268
282
  #
269
283
  # @example Only create a new timer if it isn't already scheduled
270
- # after(1.minute, id: :foo, reschedule: false) do
271
- # logger.info("Timer fired")
272
- # end
284
+ # after(1.minute, id: :foo, reschedule: false) do
285
+ # logger.info("Timer fired")
286
+ # end
287
+ #
288
+ # @example Reentrant timers will execute the block from the most recent call
289
+ # # In the following example, if Item1 received a command, followed by Item2,
290
+ # # the timer will execute the block referring to Item2.
291
+ # rule "Execute The Most Recent Block" do
292
+ # received_command Item1, Item2
293
+ # run do |event|
294
+ # after(10.minutes, id: :common_timer) do
295
+ # logger.info "The latest command was received from #{event.item}"
296
+ # end
297
+ # end
298
+ # end
273
299
  #
274
300
  def after(duration, id: nil, reschedule: true, &block)
275
301
  raise ArgumentError, "Block is required" unless block
@@ -313,10 +339,10 @@ module OpenHAB
313
339
  # Store states of supplied items
314
340
  #
315
341
  # Takes one or more items and returns a map `{Item => State}` with the
316
- # current state of each item. It is implemented by calling OpenHAB's
342
+ # current state of each item. It is implemented by calling openHAB's
317
343
  # [events.storeStates()](https://www.openhab.org/docs/configuration/actions.html#event-bus-actions).
318
344
  #
319
- # @param [GenericItem] items Items to store states of.
345
+ # @param [Item] items Items to store states of.
320
346
  #
321
347
  # @return [Core::Items::StateStorage] item states
322
348
  #
@@ -603,7 +629,7 @@ module OpenHAB
603
629
  # Otherwise it's applied to all types.
604
630
  # @param [Hash] providers_by_type
605
631
  # A list of providers by type. Type can be `:items`, `:metadata`, `:things`, `:links`,
606
- # a {GenericItem} applying the provider to all metadata on that item, or a String or Symbol
632
+ # an {Item} applying the provider to all metadata on that item, or a String or Symbol
607
633
  # applying the provider to all metadata of that namespace.
608
634
  #
609
635
  # The provider can be a {org.openhab.core.common.registry.Provider Provider}, `:persistent`,
@@ -667,7 +693,7 @@ module OpenHAB
667
693
  thread_providers[type] = provider
668
694
  when Symbol, String
669
695
  (thread_providers[:metadata_namespaces] ||= {})[type.to_s] = provider
670
- when GenericItem
696
+ when Item
671
697
  (thread_providers[:metadata_items] ||= {})[type.name] = provider
672
698
  else
673
699
  raise ArgumentError, "#{type.inspect} is not provider type"
@@ -702,4 +728,4 @@ OpenHAB::Core::Items.import_into_global_namespace
702
728
  # Extend `main` with DSL methods
703
729
  singleton_class.include(OpenHAB::DSL)
704
730
 
705
- logger.debug "OpenHAB JRuby Scripting Library Version #{OpenHAB::DSL::VERSION} Loaded"
731
+ logger.debug "openHAB JRuby Scripting Library Version #{OpenHAB::DSL::VERSION} Loaded"
data/lib/openhab/log.rb CHANGED
@@ -6,7 +6,7 @@ module OpenHAB
6
6
  # rubocop:disable Layout/LineLength
7
7
 
8
8
  #
9
- # Provides access to the OpenHAB logging facilities using Ruby logging methods
9
+ # Provides access to the openHAB logging facilities using Ruby logging methods
10
10
  #
11
11
  # Logging is available everywhere through the {#logger} object.
12
12
  #
@@ -26,7 +26,7 @@ module OpenHAB
26
26
  # @example The following entries are in a file named 'log_test.rb'
27
27
  # rule 'foo' do
28
28
  # run { logger.trace('Test logging at trace') } # 2020-12-03 18:05:20.903 [TRACE] [org.openhab.automation.jrubyscripting.foo] - Test logging at trace
29
- # on_start
29
+ # on_load
30
30
  # end
31
31
  #
32
32
  #
@@ -122,7 +122,7 @@ module OpenHAB
122
122
  end
123
123
 
124
124
  #
125
- # Ruby Logger that forwards messages at appropriate levels to OpenHAB Logger
125
+ # Ruby Logger that forwards messages at appropriate levels to openHAB Logger
126
126
  #
127
127
  class Logger
128
128
  # The base prefix for all loggers from this gem.
@@ -150,7 +150,7 @@ module OpenHAB
150
150
  private_constant :JAVA_INTERNAL_CALL_REGEX
151
151
 
152
152
  class << self
153
- # The root logger (all of OpenHAB)
153
+ # The root logger (all of openHAB)
154
154
  # @return [Logger]
155
155
  def root
156
156
  Log.logger(org.slf4j.Logger::ROOT_LOGGER_NAME)
@@ -299,7 +299,7 @@ module OpenHAB
299
299
  end
300
300
 
301
301
  #
302
- # Log a message to the OpenHAB Logger
302
+ # Log a message to the openHAB Logger
303
303
  #
304
304
  # @param [Symbol] severity Severity to log message at
305
305
  # @param [Object] msg to log, if no msg supplied and a block is provided,
@@ -3,13 +3,13 @@
3
3
  module OpenHAB
4
4
  module RSpec
5
5
  #
6
- # Contains configuration for how the OpenHAB instance should be set
6
+ # Contains configuration for how the openHAB instance should be set
7
7
  # up for the testing environment.
8
8
  #
9
9
  module Configuration
10
10
  class << self
11
11
  #
12
- # Copy binding configuration from the root OpenHAB instance.
12
+ # Copy binding configuration from the root openHAB instance.
13
13
  #
14
14
  # Default `true`.
15
15
  # @return [true, false]
@@ -18,7 +18,7 @@ module OpenHAB
18
18
 
19
19
  #
20
20
  # Copy the JSONDB (managed thing and item configuration) from the root
21
- # OpenHAB instance.
21
+ # openHAB instance.
22
22
  #
23
23
  # Default `true`.
24
24
  #
@@ -28,7 +28,7 @@ module OpenHAB
28
28
 
29
29
  #
30
30
  # Use a private (empty) confdir (scripts, rules, items, and things
31
- # files), instead of sharing with the root OpenHAB instance.
31
+ # files), instead of sharing with the root openHAB instance.
32
32
  #
33
33
  # Default `false`.
34
34
  #
@@ -37,7 +37,7 @@ module OpenHAB
37
37
  attr_accessor :private_confdir
38
38
 
39
39
  #
40
- # Use the root OpenHAB instance directly, rather than creating a
40
+ # Use the root openHAB instance directly, rather than creating a
41
41
  # private (but linked) instance.
42
42
  #
43
43
  # Default `false`.
@@ -94,7 +94,7 @@ module OpenHAB
94
94
  # it "logs exceptions in rule execution" do
95
95
  # expect(self.class.propagate_exceptions?).to be false
96
96
  # rule do
97
- # on_start
97
+ # on_load
98
98
  # run { raise "exception is logged" }
99
99
  # end
100
100
  # expect(spec_log_lines).to include(match(/exception is logged/))