openhab-jrubyscripting 5.0.0.rc5 → 5.0.0.rc8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) 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. metadata +7 -3
@@ -1,31 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "delegate"
4
- require "forwardable"
5
4
 
6
5
  module OpenHAB
7
6
  module Core
8
7
  module Items
9
- # Class is a proxy to underlying item
8
+ # Class is a proxy to underlying {Item}
10
9
  # @!visibility private
11
10
  class Proxy < Delegator
12
- extend Forwardable
13
- def_delegators :__getobj__, :class, :is_a?, :kind_of?
11
+ # Not really an Item, but pretends to be
12
+ # @!parse include Item
13
+
14
+ # @return [String]
15
+ attr_reader :name
14
16
 
15
17
  #
16
18
  # Set the proxy item (called by super)
17
19
  #
18
20
  def __setobj__(item)
19
- # Convert name to java version for faster lookups
20
- @item_name = item.name.to_java
21
+ @name = item.name
22
+ # Convert name to Java version for faster lookups
23
+ @java_name = item.name.to_java
21
24
  end
22
25
 
23
26
  #
24
27
  # Lookup item from item registry
25
28
  #
26
29
  def __getobj__
27
- $ir.get(@item_name)
30
+ r = $ir.get(@name)
31
+ return yield if r.nil? && block_given?
32
+
33
+ r
34
+ end
35
+
36
+ # @return [Module]
37
+ def class
38
+ return Item if __getobj__.nil?
39
+
40
+ __getobj__.class
41
+ end
42
+
43
+ # @return [true, false]
44
+ def is_a?(klass)
45
+ obj = __getobj__
46
+ # only claim to be a Delegator if we're backed by an actual item at the moment
47
+ klass == Item || obj.is_a?(klass) || klass == Proxy || (!obj.nil? && super)
28
48
  end
49
+ alias_method :kind_of?, :is_a?
29
50
 
30
51
  #
31
52
  # Need to check if `self` _or_ the delegate is an instance of the
@@ -63,6 +84,46 @@ module OpenHAB
63
84
  def !=(other)
64
85
  !(self == other) # rubocop:disable Style/InverseMethods
65
86
  end
87
+
88
+ # @return [GroupItem::Members]
89
+ # @raise [NoMethodError] if item is not a GroupItem, or a dummy.
90
+ def members
91
+ return super unless __getobj__.nil?
92
+
93
+ GroupItem::Members.new(self)
94
+ end
95
+
96
+ # @return [String]
97
+ def inspect
98
+ return super unless __getobj__.nil?
99
+
100
+ "#<OpenHAB::Core::Items::Proxy #{name}>"
101
+ end
102
+
103
+ #
104
+ # Supports inspect from IRB when we're a dummy item.
105
+ #
106
+ # @return [void]
107
+ # @!visibility private
108
+ def pretty_print(printer)
109
+ return super unless __getobj__.nil?
110
+
111
+ printer.text(inspect)
112
+ end
113
+
114
+ # needs to return `false` if we know we're not a {GroupItem}
115
+ def respond_to?(method, *)
116
+ return __getobj__.nil? if method.to_sym == :members
117
+
118
+ super
119
+ end
120
+
121
+ # needs to return `false` if we know we're not a {GroupItem}
122
+ def respond_to_missing?(method, *)
123
+ return __getobj__.nil? if method.to_sym == :members
124
+
125
+ super
126
+ end
66
127
  end
67
128
  end
68
129
  end
@@ -10,7 +10,7 @@ module OpenHAB
10
10
  module Core
11
11
  module Items
12
12
  #
13
- # Provides access to all OpenHAB {GenericItem items}, and acts like an array.
13
+ # Provides access to all openHAB {Item items}, and acts like an array.
14
14
  #
15
15
  class Registry
16
16
  include LazyArray
@@ -18,7 +18,7 @@ module OpenHAB
18
18
 
19
19
  # Fetches the named item from the the ItemRegistry
20
20
  # @param [String] name
21
- # @return [GenericItem] Item from registry, nil if item missing or requested item is a Group Type
21
+ # @return [Item] Item from registry, nil if item missing or requested item is a Group Type
22
22
  def [](name)
23
23
  EntityLookup.lookup_item(name)
24
24
  rescue org.openhab.core.items.ItemNotFoundException
@@ -49,7 +49,7 @@ module OpenHAB
49
49
  # @return [Object] The return value of the block.
50
50
  #
51
51
  def build(preferred_provider = nil, &block)
52
- DSL::Items::BaseBuilderDSL.new(preferred_provider).instance_eval(&block)
52
+ DSL::Items::BaseBuilderDSL.new(preferred_provider).instance_eval_with_dummy_items(&block)
53
53
  end
54
54
 
55
55
  #
@@ -57,11 +57,11 @@ module OpenHAB
57
57
  #
58
58
  # The item must be a managed item (typically created by Ruby or in the UI).
59
59
  #
60
- # @param [String, GenericItem] item_name
60
+ # @param [String, Item] item_name
61
61
  # @param recursive [true, false] Remove the item's members if it's a group
62
- # @return [GenericItem, nil] The removed item, if found.
62
+ # @return [Item, nil] The removed item, if found.
63
63
  def remove(item_name, recursive: false)
64
- item_name = item_name.name if item_name.is_a?(GenericItem)
64
+ item_name = item_name.name if item_name.is_a?(Item)
65
65
  provider = Provider.registry.provider_for(item_name)
66
66
  unless provider.is_a?(org.openhab.core.common.registry.ManagedProvider)
67
67
  raise "Cannot remove item #{item_name} from non-managed provider #{provider.inspect}"
@@ -40,31 +40,31 @@ module Enumerable
40
40
  #
41
41
 
42
42
  # Returns a new array of items that have at least one of the given tags
43
- # @return [Array<GenericItem>]
43
+ # @return [Array<Item>]
44
44
  def tagged(*tags)
45
45
  reject { |i| (tags & i.tags.to_a).empty? }
46
46
  end
47
47
 
48
48
  # Returns a new array of items that do not have any of the given tags
49
- # @return [Array<GenericItem>]
49
+ # @return [Array<Item>]
50
50
  def not_tagged(*tags)
51
51
  select { |i| (tags & i.tags.to_a).empty? }
52
52
  end
53
53
 
54
54
  # Returns a new array of items that are a member of at least one of the given groups
55
- # @return [Array<GenericItem>]
55
+ # @return [Array<Item>]
56
56
  def member_of(*groups)
57
57
  reject { |i| (groups.map(&:name) & i.group_names).empty? }
58
58
  end
59
59
 
60
60
  # Returns a new array of items that are not a member of any of the given groups
61
- # @return [Array<GenericItem>]
61
+ # @return [Array<Item>]
62
62
  def not_member_of(*groups)
63
63
  select { |i| (groups.map(&:name) & i.group_names).empty? }
64
64
  end
65
65
 
66
66
  # Returns the group members the elements
67
- # @return [Array<GenericItem>]
67
+ # @return [Array<Item>]
68
68
  def members
69
69
  grep(OpenHAB::Core::Items::GroupItem).flat_map(&:members)
70
70
  end
@@ -149,6 +149,6 @@ module Enumerable
149
149
  # can't use `include`, because Enumerable has already been included
150
150
  # in other classes
151
151
  def ensure
152
- OpenHAB::DSL::Items::Ensure::GenericItemDelegate.new(self)
152
+ OpenHAB::DSL::Items::Ensure::ItemDelegate.new(self)
153
153
  end
154
154
  end
@@ -9,7 +9,7 @@ require_relative "semantics/enumerable"
9
9
  module OpenHAB
10
10
  module Core
11
11
  module Items
12
- # Module for implementing semantics helper methods on {GenericItem} in order to easily navigate
12
+ # Module for implementing semantics helper methods on {Item} in order to easily navigate
13
13
  # the {https://www.openhab.org/docs/tutorial/model.html Semantic Model} in your scripts.
14
14
  # This can be extremely useful to find related items in rules that are executed for any member of a group.
15
15
  #
@@ -161,6 +161,7 @@ module OpenHAB
161
161
  GenericItem.include(self)
162
162
  GroupItem.extend(Forwardable)
163
163
  GroupItem.def_delegators :members, :equipments, :locations
164
+
164
165
  # @!parse
165
166
  # class Items::GroupItem
166
167
  # #
@@ -273,7 +274,7 @@ module OpenHAB
273
274
  # Checks ancestor groups one level at a time, returning the first
274
275
  # {Location} Item found.
275
276
  #
276
- # @return [GenericItem, nil]
277
+ # @return [Item, nil]
277
278
  #
278
279
  def location
279
280
  Actions::Semantics.get_location(self)&.then(&Proxy.method(:new))
@@ -299,7 +300,7 @@ module OpenHAB
299
300
  #
300
301
  # Checks ancestor groups one level at a time, returning the first {Equipment} Item found.
301
302
  #
302
- # @return [GenericItem, nil]
303
+ # @return [Item, nil]
303
304
  #
304
305
  def equipment
305
306
  Actions::Semantics.get_equipment(self)&.then(&Proxy.method(:new))
@@ -379,7 +380,7 @@ module OpenHAB
379
380
  # Pass 1 or 2 classes that are sub-classes of {Point} or {Property}.
380
381
  # Note that when comparing against semantic tags, it does a sub-class check.
381
382
  # So if you search for [Control], you'll get items tagged with [Switch].
382
- # @return [Array<GenericItem>]
383
+ # @return [Array<Item>]
383
384
  #
384
385
  def points(*point_or_property_types)
385
386
  return members.points(*point_or_property_types) if equipment? || location?
@@ -403,7 +404,7 @@ module Enumerable
403
404
  #
404
405
 
405
406
  # Returns a new array of items that are a semantics Location (optionally of the given type)
406
- # @return [Array<GenericItem>]
407
+ # @return [Array<Item>]
407
408
  def locations(type = nil)
408
409
  if type && (!type.is_a?(Module) || !(type < Semantics::Location))
409
410
  raise ArgumentError, "type must be a subclass of Location"
@@ -423,7 +424,7 @@ module Enumerable
423
424
  # that belong to the {Semantics::Equipment equipments}, use {#members}
424
425
  # before calling {#points}. See the example with {#points}.
425
426
  #
426
- # @return [Array<GenericItem>]
427
+ # @return [Array<Item>]
427
428
  #
428
429
  # @example Get all TVs in a room
429
430
  # lGreatRoom.equipments(Semantics::Screen)
@@ -440,7 +441,7 @@ module Enumerable
440
441
 
441
442
  # Returns a new array of items that are semantics points (optionally of a given type)
442
443
  #
443
- # @return [Array<GenericItem>]
444
+ # @return [Array<Item>]
444
445
  #
445
446
  # @example Get all the power switch items for every equipment in a room
446
447
  # lGreatRoom.equipments.members.points(Semantics::Switch)
@@ -9,7 +9,7 @@ end
9
9
  module OpenHAB
10
10
  module Core
11
11
  #
12
- # Contains the core types that OpenHAB uses to represent items.
12
+ # Contains the core types that openHAB uses to represent items.
13
13
  # Items have states from the {Types} module.
14
14
  #
15
15
  # You may use an item or group name anywhere {DSL} (or just {Core::EntityLookup})
@@ -25,6 +25,7 @@ module OpenHAB
25
25
  Object.const_set(const_name, k) unless Object.const_defined?(const_name)
26
26
  end
27
27
  Object.const_set(:GenericItem, GenericItem) unless Object.const_defined?(:GenericItem)
28
+ Object.const_set(:Item, Item) unless Object.const_defined?(:Item)
28
29
  end
29
30
 
30
31
  private
@@ -154,7 +154,11 @@ module OpenHAB
154
154
 
155
155
  # @!visibility private
156
156
  def add(element)
157
- @elements[element.uid] = element
157
+ @elements.compute(element.uid) do |_k, old_element|
158
+ raise ArgumentError, "Element #{element.uid} already exists, and cannot be added again" if old_element
159
+
160
+ element
161
+ end
158
162
  notify_listeners_about_added_element(element)
159
163
  element
160
164
  end
@@ -197,12 +201,15 @@ module OpenHAB
197
201
  # @!visibility private
198
202
  #
199
203
  def update(element)
200
- old_element = @elements[element.uid]
201
- if old_element
202
- @elements[element.uid] = element
203
- notify_listeners_about_updated_element(old_element, element)
204
+ old = nil
205
+ @elements.compute(element.uid) do |_k, old_element|
206
+ raise ArgumentError, "Element #{element.uid} does not exist to update" unless old_element
207
+
208
+ old = old_element
209
+ element
204
210
  end
205
- old_element
211
+ notify_listeners_about_updated_element(old, element)
212
+ old
206
213
  end
207
214
 
208
215
  # @!visibility private
@@ -214,7 +221,7 @@ module OpenHAB
214
221
 
215
222
  def initialize(script_unloaded_before: nil)
216
223
  super()
217
- @elements = {}
224
+ @elements = java.util.concurrent.ConcurrentHashMap.new
218
225
  self.class.registry.add_provider(self)
219
226
  ScriptHandling.script_unloaded(before: script_unloaded_before) { unregister }
220
227
  end
@@ -6,7 +6,7 @@ module OpenHAB
6
6
  module Core
7
7
  module Rules
8
8
  #
9
- # Provides access to all OpenHAB {Rule rules}, and acts like an array.
9
+ # Provides access to all openHAB {Rule rules}, and acts like an array.
10
10
  #
11
11
  class Registry
12
12
  include LazyArray
@@ -42,7 +42,7 @@ module OpenHAB
42
42
  # @return [Object] The result of the block.
43
43
  #
44
44
  def build(preferred_provider = nil, &block)
45
- DSL::Rules::Builder.new(preferred_provider).instance_eval(&block)
45
+ DSL::Rules::Builder.new(preferred_provider).instance_eval_with_dummy_items(&block)
46
46
  end
47
47
 
48
48
  #
@@ -14,7 +14,7 @@ module OpenHAB
14
14
  class << self
15
15
  #
16
16
  # @!attribute [r] rule_manager
17
- # @return [org.openhab.core.automation.RuleManager] The OpenHAB rule manager/engine
17
+ # @return [org.openhab.core.automation.RuleManager] The openHAB rule manager/engine
18
18
  #
19
19
  def manager
20
20
  @manager ||= OSGi.service("org.openhab.core.automation.RuleManager")
@@ -11,7 +11,7 @@ module OpenHAB
11
11
  #
12
12
  # Add a block of code to be executed once the rule script has finished loading.
13
13
  #
14
- # This can occur on OpenHAB start up, when the script is first created, or updated.
14
+ # This can occur on openHAB start up, when the script is first created, or updated.
15
15
  #
16
16
  # Multiple hooks can be added by calling {#script_loaded} multiple times.
17
17
  # They can be used to perform final initializations.
@@ -37,7 +37,7 @@ module OpenHAB
37
37
  #
38
38
  # Add a block of code to be executed when the script is unloaded.
39
39
  #
40
- # This can occur when OpenHAB shuts down, or when the script is being reloaded.
40
+ # This can occur when openHAB shuts down, or when the script is being reloaded.
41
41
  #
42
42
  # Multiple hooks can be added by calling {#script_unloaded} multiple times.
43
43
  # They can be used to perform final cleanup.
@@ -88,9 +88,9 @@ module OpenHAB
88
88
  self.script_loaded = false
89
89
 
90
90
  #
91
- # Executed when OpenHAB unloads a script file
91
+ # Executed when openHAB unloads a script file
92
92
  #
93
- def scriptUnloaded # rubocop:disable Naming/MethodName method name dictated by OpenHAB
93
+ def scriptUnloaded # rubocop:disable Naming/MethodName method name dictated by openHAB
94
94
  logger.trace("Script unloaded")
95
95
  ScriptHandlingCallbacks.script_unloaded_hooks.each do |hook|
96
96
  hook.call
@@ -116,9 +116,9 @@ module OpenHAB
116
116
  end
117
117
 
118
118
  #
119
- # Executed when OpenHAB loads a script file
119
+ # Executed when openHAB loads a script file
120
120
  #
121
- def scriptLoaded(filename) # rubocop:disable Naming/MethodName method name dictated by OpenHAB
121
+ def scriptLoaded(filename) # rubocop:disable Naming/MethodName method name dictated by openHAB
122
122
  logger.trace("Script loaded: #{filename}")
123
123
  ScriptHandlingCallbacks.script_loaded_hooks.each do |hook|
124
124
  hook.call
@@ -9,7 +9,7 @@ module OpenHAB
9
9
 
10
10
  #
11
11
  # {Channel} is a part of a {Thing} that represents a functionality of it.
12
- # Therefore {GenericItem Items} can be linked a to a channel.
12
+ # Therefore {Item Items} can be linked a to a channel.
13
13
  #
14
14
  # @!attribute [r] item
15
15
  # (see ChannelUID#item)
@@ -28,7 +28,7 @@ module OpenHAB
28
28
  # Return the item if this channel is linked with an item. If a channel is linked to more than one item,
29
29
  # this method only returns the first item.
30
30
  #
31
- # @return [GenericItem, nil]
31
+ # @return [Item, nil]
32
32
  #
33
33
  def item
34
34
  items.first
@@ -39,7 +39,7 @@ module OpenHAB
39
39
  #
40
40
  # Returns all of the channel's linked items.
41
41
  #
42
- # @return [Array<GenericItem>] An array of things or an empty array
42
+ # @return [Array<Item>] An array of things or an empty array
43
43
  #
44
44
  def items
45
45
  registry = OSGi.service("org.openhab.core.thing.link.ItemChannelLinkRegistry")
@@ -6,7 +6,7 @@ module OpenHAB
6
6
  java_import org.openhab.core.thing.link.ItemChannelLink
7
7
 
8
8
  #
9
- # Represents the link between a {GenericItem} and a {Thing Thing's}
9
+ # Represents the link between an {Item} and a {Thing Thing's}
10
10
  # {Channel}.
11
11
  #
12
12
  # @!attribute [r] thing
@@ -21,7 +21,7 @@ module OpenHAB
21
21
  def_delegator :linked_uid, :thing
22
22
 
23
23
  # @!attribute [r] item
24
- # @return [GenericItem]
24
+ # @return [Item]
25
25
  def item
26
26
  DSL.items[item_name]
27
27
  end
@@ -4,11 +4,11 @@ module OpenHAB
4
4
  module Core
5
5
  module Things
6
6
  #
7
- # Contains the link between a {Thing Thing's} {Channel Channels} and {GenericItem Items}.
7
+ # Contains the link between a {Thing Thing's} {Channel Channels} and {Item Items}.
8
8
  #
9
9
  module Links
10
10
  #
11
- # Provides {Items::GenericItem items} linked to {Channel channels} in Ruby to openHAB.
11
+ # Provides {Items::Item items} linked to {Channel channels} in Ruby to openHAB.
12
12
  #
13
13
  class Provider < Core::Provider
14
14
  include org.openhab.core.thing.link.ItemChannelLinkProvider
@@ -6,7 +6,7 @@ module OpenHAB
6
6
  module Core
7
7
  module Things
8
8
  #
9
- # Provides access to all OpenHAB {Thing things}, and acts like an array.
9
+ # Provides access to all openHAB {Thing things}, and acts like an array.
10
10
  #
11
11
  class Registry
12
12
  include LazyArray
@@ -9,7 +9,7 @@ module OpenHAB
9
9
  #
10
10
  # A {Thing} is a representation of a connected part (e.g. physical device
11
11
  # or cloud service) from the real world. It contains a list of
12
- # {Channel Channels}, which can be bound to {GenericItem Items}.
12
+ # {Channel Channels}, which can be bound to {Item Items}.
13
13
  #
14
14
  # @see OpenHAB::DSL.things things[]
15
15
  # @see EntityLookup
@@ -33,8 +33,8 @@ module OpenHAB
33
33
 
34
34
  class << self
35
35
  #
36
- # Parses a String representing a time into an OpenHAB DateTimeType. First tries to parse it
37
- # using java's DateTimeType's parser, then falls back to the Ruby Time.parse
36
+ # Parses a String representing a time into an {java.time.DateTimeType}. First tries to parse it
37
+ # using Java's parser, then falls back to the Ruby `Time.parse`.
38
38
  #
39
39
  # @param [String] time_string
40
40
  #
@@ -44,9 +44,9 @@ module OpenHAB
44
44
  time_string = "#{time_string}Z" if TIME_ONLY_REGEX.match?(time_string)
45
45
  DateTimeType.new(time_string)
46
46
  rescue java.lang.StringIndexOutOfBoundsException, java.lang.IllegalArgumentException => e
47
- # Try Ruby's Time.parse if OpenHAB's DateTimeType parser fails
47
+ # Try Ruby's Time.parse if DateTimeType parser fails
48
48
  begin
49
- DateTimeType.new(::Time.parse(time_string))
49
+ ::Time.parse(time_string).to_zoned_date_time
50
50
  rescue ArgumentError
51
51
  raise ArgumentError, e.message
52
52
  end
@@ -61,7 +61,7 @@ module OpenHAB
61
61
  if args.length == 1 && args.first.respond_to?(:to_str)
62
62
  value = args.first.to_str
63
63
 
64
- # parse some formats OpenHAB doesn't understand
64
+ # parse some formats openHAB doesn't understand
65
65
  # in this case, HTML hex format for rgb
66
66
  if (match = value.match(/^#(\h{2})(\h{2})(\h{2})$/))
67
67
  rgb = match.to_a[1..3].map { |v| v.to_i(16) }
@@ -77,7 +77,7 @@ module OpenHAB
77
77
  return super unless args.length == 3
78
78
 
79
79
  # convert from several numeric-like types to the exact types
80
- # OpenHAB needs
80
+ # openHAB needs
81
81
  hue = args[0]
82
82
  args[0] = if hue.is_a?(DecimalType)
83
83
  hue
@@ -12,7 +12,7 @@ module OpenHAB
12
12
  # {QuantityType} extends {DecimalType} to handle physical unit measurement.
13
13
  #
14
14
  # {QuantityType} is part of the [Units of Measurement](https://www.openhab.org/docs/concepts/units-of-measurement.html)
15
- # framework in OpenHAB. It is represented as a decimal number with a unit.
15
+ # framework in openHAB. It is represented as a decimal number with a unit.
16
16
  # You can construct a {QuantityType} object by using the pipe operator with any Numeric.
17
17
  #
18
18
  # @see OpenHAB::DSL.unit unit: Implicit unit conversions
@@ -7,7 +7,7 @@ end
7
7
  module OpenHAB
8
8
  module Core
9
9
  #
10
- # Contains the core types that OpenHAB uses as {State}s for items, and
10
+ # Contains the core types that openHAB uses as {State}s for items, and
11
11
  # {Command}s to be sent to control them.
12
12
  #
13
13
  # Types are the specific data types that commands and states are. They can be
@@ -4,7 +4,7 @@ module OpenHAB
4
4
  module Core
5
5
  java_import org.openhab.core.common.AbstractUID
6
6
 
7
- # Adds methods to core OpenHAB AbstractUID to make it more natural in Ruby
7
+ # Adds methods to core openHAB AbstractUID to make it more natural in Ruby
8
8
  class AbstractUID
9
9
  # implicit conversion to string
10
10
  alias_method :to_str, :to_s