openhab-jrubyscripting 5.0.0.rc1 → 5.0.0.rc2

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/entity_lookup.rb +1 -12
  3. data/lib/openhab/core/items/generic_item.rb +2 -2
  4. data/lib/openhab/core/items/metadata/hash.rb +64 -5
  5. data/lib/openhab/core/items/metadata/namespace_hash.rb +17 -19
  6. data/lib/openhab/core/items/metadata/provider.rb +48 -0
  7. data/lib/openhab/core/items/provider.rb +40 -0
  8. data/lib/openhab/core/items/proxy.rb +10 -0
  9. data/lib/openhab/core/items/registry.rb +16 -7
  10. data/lib/openhab/core/items/state_storage.rb +3 -3
  11. data/lib/openhab/core/profile_factory.rb +1 -1
  12. data/lib/openhab/core/provider.rb +216 -0
  13. data/lib/openhab/core/registry.rb +30 -0
  14. data/lib/openhab/core/script_handling.rb +50 -0
  15. data/lib/openhab/core/things/links/provider.rb +40 -0
  16. data/lib/openhab/core/things/provider.rb +25 -0
  17. data/lib/openhab/core/things/proxy.rb +10 -0
  18. data/lib/openhab/core/things/registry.rb +25 -2
  19. data/lib/openhab/core/timer.rb +12 -0
  20. data/lib/openhab/core/types/quantity_type.rb +5 -2
  21. data/lib/openhab/core.rb +3 -14
  22. data/lib/openhab/core_ext/java/class.rb +34 -0
  23. data/lib/openhab/core_ext/java/local_time.rb +2 -1
  24. data/lib/openhab/core_ext/java/month.rb +2 -1
  25. data/lib/openhab/dsl/items/builder.rb +30 -97
  26. data/lib/openhab/dsl/rules/builder.rb +27 -0
  27. data/lib/openhab/dsl/rules/triggers/changed.rb +7 -4
  28. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +1 -1
  29. data/lib/openhab/dsl/rules/triggers/trigger.rb +1 -1
  30. data/lib/openhab/dsl/rules/triggers/updated.rb +7 -3
  31. data/lib/openhab/dsl/rules.rb +1 -1
  32. data/lib/openhab/dsl/script_handling.rb +0 -49
  33. data/lib/openhab/dsl/things/builder.rb +8 -31
  34. data/lib/openhab/dsl/thread_local.rb +1 -0
  35. data/lib/openhab/dsl/timer_manager.rb +13 -7
  36. data/lib/openhab/dsl/version.rb +1 -1
  37. data/lib/openhab/dsl.rb +132 -22
  38. data/lib/openhab/log.rb +1 -1
  39. data/lib/openhab/rspec/helpers.rb +8 -25
  40. data/lib/openhab/rspec/hooks.rb +15 -18
  41. data/lib/openhab/rspec/mocks/timer.rb +5 -0
  42. metadata +9 -3
  43. data/lib/openhab/rspec/mocks/metadata_provider.rb +0 -75
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ Registry = org.openhab.core.common.registry.AbstractRegistry
6
+
7
+ Registry.field_reader :elementToProvider, :elementReadLock, :identifierToElement
8
+
9
+ # @abstract
10
+ #
11
+ # The base class for all registries in openHAB.
12
+ #
13
+ class Registry
14
+ #
15
+ # Determines which provider an element is associated with.
16
+ #
17
+ # @param [Object] key
18
+ # @return [org.openhab.core.common.registry.Provider]
19
+ #
20
+ def provider_for(key)
21
+ elementReadLock.lock
22
+ return nil unless (element = identifierToElement[key])
23
+
24
+ elementToProvider[element]
25
+ ensure
26
+ elementReadLock.unlock
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,56 @@
2
2
 
3
3
  module OpenHAB
4
4
  module Core
5
+ #
6
+ # Provide callback mechanisms for script handling
7
+ #
8
+ module ScriptHandling
9
+ module_function
10
+
11
+ #
12
+ # Add a block of code to be executed once the rule script has finished loading.
13
+ #
14
+ # This can occur on OpenHAB start up, when the script is first created, or updated.
15
+ #
16
+ # Multiple hooks can be added by calling {#script_loaded} multiple times.
17
+ # They can be used to perform final initializations.
18
+ #
19
+ # @return [void]
20
+ #
21
+ # @example
22
+ # script_loaded do
23
+ # logger.info 'Hi, this script has just finished loading'
24
+ # end
25
+ #
26
+ # @example
27
+ # script_loaded do
28
+ # logger.info 'I will be called after the script finished loading too'
29
+ # end
30
+ #
31
+ def script_loaded(&block)
32
+ Core::ScriptHandlingCallbacks.script_loaded_hooks << block
33
+ end
34
+
35
+ #
36
+ # Add a block of code to be executed when the script is unloaded.
37
+ #
38
+ # This can occur when OpenHAB shuts down, or when the script is being reloaded.
39
+ #
40
+ # Multiple hooks can be added by calling {#script_unloaded} multiple times.
41
+ # They can be used to perform final cleanup.
42
+ #
43
+ # @return [void]
44
+ #
45
+ # @example
46
+ # script_unloaded do
47
+ # logger.info 'Hi, this script has been unloaded'
48
+ # end
49
+ #
50
+ def script_unloaded(&block)
51
+ Core::ScriptHandlingCallbacks.script_unloaded_hooks << block
52
+ end
53
+ end
54
+
5
55
  #
6
56
  # Manages script loading and unloading
7
57
  #
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Things
6
+ #
7
+ # Contains the link between a {Thing Thing's} {Channel Channels} and {GenericItem Items}.
8
+ #
9
+ module Links
10
+ #
11
+ # Provides {Items::GenericItem items} linked to {Channel channels} in Ruby to openHAB.
12
+ #
13
+ class Provider < Core::Provider
14
+ include org.openhab.core.thing.link.ItemChannelLinkProvider
15
+
16
+ class << self
17
+ #
18
+ # The ItemChannelLink registry
19
+ #
20
+ # @return [org.openhab.core.thing.link.ItemChanneLinkRegistry]
21
+ #
22
+ def registry
23
+ @registry ||= OSGi.service("org.openhab.core.thing.link.ItemChannelLinkRegistry")
24
+ end
25
+
26
+ # @!visibility private
27
+ def link(item, channel, config = {})
28
+ config = org.openhab.core.config.core.Configuration.new(config.transform_keys(&:to_s))
29
+ channel = ChannelUID.new(channel) if channel.is_a?(String)
30
+ channel = channel.uid if channel.is_a?(Channel)
31
+ link = org.openhab.core.thing.link.ItemChannelLink.new(item.name, channel, config)
32
+
33
+ current.add(link)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Things
6
+ #
7
+ # Provides {Thing Things} created in Ruby to openHAB
8
+ #
9
+ class Provider < Core::Provider
10
+ include org.openhab.core.thing.ThingProvider
11
+
12
+ class << self
13
+ #
14
+ # The Thing registry
15
+ #
16
+ # @return [org.openhab.core.thing.ThingRegistry]
17
+ #
18
+ def registry
19
+ $things
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -63,6 +63,16 @@ module OpenHAB
63
63
 
64
64
  super
65
65
  end
66
+
67
+ #
68
+ # Non equality comparison
69
+ #
70
+ # @return [true, false]
71
+ #
72
+ # @!visibility private
73
+ def !=(other)
74
+ !(self == other) # rubocop:disable Style/InverseMethods
75
+ end
66
76
  end
67
77
  end
68
78
  end
@@ -24,6 +24,8 @@ module OpenHAB
24
24
  end
25
25
  alias_method :include?, :[]
26
26
  alias_method :key?, :[]
27
+ # @deprecated
28
+ alias_method :has_key?, :[]
27
29
 
28
30
  #
29
31
  # Explicit conversion to array
@@ -34,11 +36,32 @@ module OpenHAB
34
36
  $things.all.map { |thing| Proxy.new(thing) }
35
37
  end
36
38
 
39
+ #
37
40
  # Enter the Thing Builder DSL.
41
+ # @param (see Core::Provider.current)
38
42
  # @yield Block executed in the context of a {DSL::Things::Builder}.
39
43
  # @return [Object] The result of the block.
40
- def build(&block)
41
- DSL::Things::Builder.new.instance_eval(&block)
44
+ #
45
+ def build(preferred_provider = nil, &block)
46
+ DSL::Things::Builder.new(preferred_provider).instance_eval(&block)
47
+ end
48
+
49
+ #
50
+ # Remove a Thing.
51
+ #
52
+ # The thing must be a managed thing (typically created by Ruby or in the UI).
53
+ #
54
+ # @param [String, Thing, ThingUID] thing_uid
55
+ # @return [Thing, nil] The removed item, if found.
56
+ def remove(thing_uid)
57
+ thing_uid = thing.uid if thing_uid.is_a?(Thing)
58
+ thing_uid = ThingUID.new(thing_uid) if thing_uid.is_a?(String)
59
+ provider = Provider.registry.provider_for(thing_uid)
60
+ unless provider.is_a?(org.openhab.core.common.registry.ManagedProvider)
61
+ raise "Cannot remove thing #{thing_uid} from non-managed provider #{provider.inspect}"
62
+ end
63
+
64
+ provider.remove(thing_uid)
42
65
  end
43
66
  end
44
67
  end
@@ -96,6 +96,18 @@ module OpenHAB
96
96
  #
97
97
  def cancel
98
98
  DSL.timers.delete(self)
99
+ cancel!
100
+ end
101
+
102
+ #
103
+ # Cancel the timer but do not remove self from the timer manager
104
+ #
105
+ # To be used internally by {TimerManager} from inside ConcurrentHashMap's compute blocks
106
+ #
107
+ # @return [true,false] True if cancel was successful, false otherwise
108
+ #
109
+ # @!visibility private
110
+ def cancel!
99
111
  @timer.cancel
100
112
  end
101
113
 
@@ -15,6 +15,9 @@ module OpenHAB
15
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
+ # @see OpenHAB::DSL.unit unit: Implicit unit conversions
19
+ # @see OpenHAB::CoreExt::Ruby::QuantityTypeConversion Convert Numeric to QuantityType
20
+ #
18
21
  # @example QuantityTypes can perform math operations between them.
19
22
  # (50 | "°F") + (-25 | "°F") # => 25.0 °F
20
23
  # (100 | "°F") / (2 | "°F") # => 50
@@ -141,7 +144,7 @@ module OpenHAB
141
144
  return compare_to(QuantityType.new(other, unit))
142
145
  end
143
146
 
144
- return nil # don"t allow comparison with numeric outside a unit block
147
+ return nil # don't allow comparison with numeric outside a unit block
145
148
  end
146
149
 
147
150
  return nil unless other.respond_to?(:coerce)
@@ -308,7 +311,7 @@ module OpenHAB
308
311
  def multiply_quantity(other)
309
312
  lhs = deunitize
310
313
  rhs = other.deunitize
311
- # reverse the arguments if it's multiplication and the LHS isn"t a QuantityType
314
+ # reverse the arguments if it's multiplication and the LHS isn't a QuantityType
312
315
  lhs, rhs = rhs, lhs if lhs.is_a?(java.math.BigDecimal)
313
316
  # what a waste... using a QuantityType to multiply two dimensionless quantities
314
317
  # have to make sure lhs is still a QuantityType in order to return a new
data/lib/openhab/core.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # several classes rely on this, so force it to load earlier
4
+ require_relative "core/provider"
5
+
3
6
  Dir[File.expand_path("core/**/*.rb", __dir__)].sort.each do |f|
4
7
  require f
5
8
  end
@@ -42,20 +45,6 @@ module OpenHAB
42
45
  Pathname.new(org.openhab.core.OpenHAB.config_folder)
43
46
  end
44
47
 
45
- #
46
- # JRuby isn't respecting $RUBYLIB when run embedded inside of OpenHAB, so do it manually
47
- #
48
- # @return [void]
49
- #
50
- # @!visibility private
51
- def add_rubylib_to_load_path
52
- ENV["RUBYLIB"]&.split(File::PATH_SEPARATOR)&.each do |path|
53
- next if path.empty?
54
-
55
- $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
56
- end
57
- end
58
-
59
48
  #
60
49
  # @!attribute [r] automation_manager
61
50
  # @return [org.openhab.core.automation.module.script.rulesupport.shared.ScriptedAutomationManager]
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module CoreExt
5
+ module Java
6
+ Class = java.lang.Class
7
+
8
+ # Extensions to Class
9
+ class Class
10
+ #
11
+ # `self`, all superclasses and interfaces, recursively.
12
+ #
13
+ # @return [Array<Class>]
14
+ #
15
+ def ancestors
16
+ ([self] +
17
+ Array(superclass&.ancestors) +
18
+ interfaces.flat_map(&:ancestors)).uniq
19
+ end
20
+
21
+ #
22
+ # `self`, all superclasses and interfaces, recursively.
23
+ #
24
+ # @return [Array<java.reflect.Type>]
25
+ #
26
+ def generic_ancestors
27
+ ancestors.flat_map do |klass|
28
+ Array(klass.generic_superclass) + klass.generic_interfaces
29
+ end.uniq
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -33,7 +33,7 @@ module OpenHAB
33
33
  # end
34
34
  #
35
35
  class LocalTime
36
- include Time
36
+ # @!parse include Time
37
37
 
38
38
  # @!visibility private
39
39
  class << self
@@ -104,3 +104,4 @@ module OpenHAB
104
104
  end
105
105
 
106
106
  LocalTime = OpenHAB::CoreExt::Java::LocalTime unless Object.const_defined?(:LocalTime)
107
+ java.time.LocalTime.include(OpenHAB::CoreExt::Java::Time)
@@ -9,7 +9,7 @@ module OpenHAB
9
9
 
10
10
  # Extensions to Month
11
11
  class Month
12
- include Time
12
+ # @!parse include Time
13
13
 
14
14
  #
15
15
  # Returns the next month
@@ -57,3 +57,4 @@ module OpenHAB
57
57
  end
58
58
 
59
59
  Month = OpenHAB::CoreExt::Java::Month unless Object.const_defined?(:Month)
60
+ java.time.Month.include(OpenHAB::CoreExt::Java::Time)
@@ -6,100 +6,6 @@ module OpenHAB
6
6
  # Contains extensions to simplify working with [GenericItem]s.
7
7
  #
8
8
  module Items
9
- # Stores all items created in scripts, and notifies the ItemRegistry
10
- # of their existence
11
- # @!visibility private
12
- class ItemProvider < org.openhab.core.common.registry.AbstractProvider
13
- include org.openhab.core.items.ItemProvider
14
- include Singleton
15
-
16
- def initialize
17
- super
18
-
19
- @items = {}
20
-
21
- $ir.add_provider(self)
22
- ScriptHandling.script_unloaded { $ir.remove_provider(self) }
23
- end
24
-
25
- # Add an item to this provider
26
- def add(builder)
27
- item = builder.build
28
- raise "Item #{item.name} already exists" if @items.key?(item.name)
29
-
30
- @items[item.name] = item
31
- notify_listeners_about_added_element(item)
32
-
33
- # make sure to add the item to the registry before linking it
34
- builder.channels.each do |(channel, config)|
35
- if !channel.include?(":") &&
36
- (group = builder.groups.find { |g| g.is_a?(GroupItemBuilder) && g.thing })
37
- thing = group.thing
38
- thing = thing.uid if thing.is_a?(Core::Things::Thing)
39
- channel = "#{thing}:#{channel}"
40
- end
41
- ItemChannelLinkProvider.instance.link(item, channel, config)
42
- end
43
-
44
- item
45
- end
46
-
47
- # Remove an item from this provider
48
- #
49
- # @return [GenericItem, nil] The removed item, if found.
50
- def remove(item_name, recursive: false)
51
- return nil unless @items.key?(item_name)
52
-
53
- item = @items.delete(item_name)
54
- if recursive && item.is_a?(Core::Items::GroupItem)
55
- item.members.each { |member| remove(member.__getobj__, recursive: true) }
56
- end
57
-
58
- notify_listeners_about_removed_element(item)
59
- item
60
- end
61
-
62
- # Get all items in this provider
63
- def getAll # rubocop:disable Naming/MethodName required by java interface
64
- @items.values
65
- end
66
- end
67
-
68
- # @!visibility private
69
- class ItemChannelLinkProvider < org.openhab.core.common.registry.AbstractProvider
70
- include org.openhab.core.thing.link.ItemChannelLinkProvider
71
- include Singleton
72
-
73
- def initialize
74
- super
75
-
76
- @links = Hash.new { |h, k| h[k] = Set.new }
77
- registry = OSGi.service("org.openhab.core.thing.link.ItemChannelLinkRegistry")
78
- registry.add_provider(self)
79
- ScriptHandling.script_unloaded { registry.remove_provider(self) }
80
- end
81
-
82
- # @!visibility private
83
- def link(item, channel, config = {})
84
- config = org.openhab.core.config.core.Configuration.new(config.transform_keys(&:to_s))
85
- channel = org.openhab.core.thing.ChannelUID.new(channel) if channel.is_a?(String)
86
- channel = channel.uid if channel.is_a?(org.openhab.core.thing.Channel)
87
- link = org.openhab.core.thing.link.ItemChannelLink.new(item.name, channel, config)
88
-
89
- item_links = @links[item.name]
90
- if item_links.include?(link)
91
- notify_listeners_about_updated_element(link, link)
92
- else
93
- item_links << link
94
- notify_listeners_about_added_element(link)
95
- end
96
- end
97
-
98
- def getAll # rubocop:disable Naming/MethodName required by java interface
99
- @links.values.flatten
100
- end
101
- end
102
-
103
9
  # An item builder allows you to dynamically create OpenHAB items at runtime.
104
10
  # This can be useful either to create items as soon as the script loads,
105
11
  # or even later based on a rule executing.
@@ -196,10 +102,37 @@ module OpenHAB
196
102
  class BaseBuilderDSL
197
103
  include Builder
198
104
 
199
- private
105
+ # @!visibility private
106
+ class ProviderWrapper
107
+ attr_reader :provider
200
108
 
201
- def provider
202
- ItemProvider.instance
109
+ def initialize(provider)
110
+ @provider = provider
111
+ end
112
+
113
+ # @!visibility private
114
+ def add(builder)
115
+ item = builder.build
116
+ provider.add(item)
117
+ # make sure to add the item to the registry before linking it
118
+ builder.channels.each do |(channel, config)|
119
+ if !channel.include?(":") &&
120
+ (group = builder.groups.find { |g| g.is_a?(GroupItemBuilder) && g.thing })
121
+ thing = group.thing
122
+ channel = "#{thing}:#{channel}"
123
+ end
124
+ Core::Things::Links::Provider.link(item, channel, config)
125
+ end
126
+ item
127
+ end
128
+ end
129
+ private_constant :ProviderWrapper
130
+
131
+ # @return [org.openhab.core.items.ItemProvider]
132
+ attr_reader :provider
133
+
134
+ def initialize(provider)
135
+ @provider = ProviderWrapper.new(Core::Items::Provider.current(provider))
203
136
  end
204
137
  end
205
138
 
@@ -703,6 +703,16 @@ module OpenHAB
703
703
 
704
704
  @ruby_triggers << [:changed, items, { to: to, from: from, duration: duration }]
705
705
  items.each do |item|
706
+ case item
707
+ when Core::Things::Thing,
708
+ Core::Things::ThingUID,
709
+ Core::Items::GenericItem,
710
+ Core::Items::GroupItem::Members
711
+ nil
712
+ else
713
+ raise ArgumentError, "items must be a GenericItem, GroupItem::Members, Thing, or ThingUID"
714
+ end
715
+
706
716
  logger.trace("Creating changed trigger for entity(#{item}), to(#{to.inspect}), from(#{from.inspect})")
707
717
 
708
718
  Array.wrap(from).each do |from_state|
@@ -970,6 +980,13 @@ module OpenHAB
970
980
  @ruby_triggers << [:received_command, items, { command: commands }]
971
981
 
972
982
  items.each do |item|
983
+ case item
984
+ when Core::Items::GenericItem,
985
+ Core::Items::GroupItem::Members
986
+ nil
987
+ else
988
+ raise ArgumentError, "items must be a GenericItem or GroupItem::Members"
989
+ end
973
990
  commands.each do |cmd|
974
991
  logger.trace "Creating received command trigger for items #{item.inspect} and commands #{cmd.inspect}"
975
992
 
@@ -1160,6 +1177,16 @@ module OpenHAB
1160
1177
  updated = Updated.new(rule_triggers: @rule_triggers)
1161
1178
  @ruby_triggers << [:updated, items, { to: to }]
1162
1179
  items.map do |item|
1180
+ case item
1181
+ when Core::Things::Thing,
1182
+ Core::Things::ThingUID,
1183
+ Core::Items::GenericItem,
1184
+ Core::Items::GroupItem::Members
1185
+ nil
1186
+ else
1187
+ raise ArgumentError, "items must be a GenericItem, GroupItem::Members, Thing, or ThingUID"
1188
+ end
1189
+
1163
1190
  logger.trace("Creating updated trigger for item(#{item}) to(#{to})")
1164
1191
  [to].flatten.map do |to_state|
1165
1192
  updated.trigger(item: item, to: to_state, attach: attach)
@@ -107,10 +107,13 @@ module OpenHAB
107
107
  #
108
108
  def changed_trigger(item:, from:, to:, attach: nil, conditions: nil)
109
109
  type, config = case item
110
- when GroupItem::Members then group(group: item, from: from,
111
- to: to)
112
- when Core::Things::Thing then thing(thing: item, from: from, to: to)
113
- else item(item: item, from: from, to: to)
110
+ when GroupItem::Members
111
+ group(group: item, from: from, to: to)
112
+ when Core::Things::Thing,
113
+ Core::Things::ThingUID
114
+ thing(thing: item, from: from, to: to)
115
+ else
116
+ item(item: item, from: from, to: to)
114
117
  end
115
118
  append_trigger(type: type, config: config, attach: attach, conditions: conditions)
116
119
  end
@@ -11,7 +11,7 @@ module OpenHAB
11
11
  # Creates cron triggers
12
12
  #
13
13
  class Cron < Trigger
14
- # Trigger ID for Watch Triggers
14
+ # Trigger ID for Cron Triggers
15
15
  CRON_TRIGGER_MODULE_ID = "jsr223.jruby.CronTrigger"
16
16
 
17
17
  #
@@ -33,7 +33,7 @@ module OpenHAB
33
33
  # @return [Array] Trigger and config for thing
34
34
  #
35
35
  def trigger_for_thing(thing:, type:, to: nil, from: nil)
36
- config = { "thingUID" => thing.uid.to_s }
36
+ config = { "thingUID" => thing.to_s }
37
37
  config["status"] = trigger_state_from_symbol(to).to_s if to
38
38
  config["previousStatus"] = trigger_state_from_symbol(from).to_s if from
39
39
  [type, config]
@@ -74,9 +74,13 @@ module OpenHAB
74
74
  #
75
75
  def update_trigger(item:, to:, attach: nil, conditions: nil)
76
76
  type, config = case item
77
- when GroupItem::Members then group_update(item: item, to: to)
78
- when Core::Things::Thing then thing_update(thing: item, to: to)
79
- else item_update(item: item, to: to)
77
+ when GroupItem::Members
78
+ group_update(item: item, to: to)
79
+ when Core::Things::Thing,
80
+ Core::Things::ThingUID
81
+ thing_update(thing: item, to: to)
82
+ else
83
+ item_update(item: item, to: to)
80
84
  end
81
85
  append_trigger(type: type, config: config, attach: attach, conditions: conditions)
82
86
  end
@@ -23,7 +23,7 @@ module OpenHAB
23
23
  script_rules.each_value(&:cleanup)
24
24
  end
25
25
  end
26
- ScriptHandling.script_unloaded { cleanup_rules }
26
+ Core::ScriptHandling.script_unloaded { cleanup_rules }
27
27
  end
28
28
  end
29
29
  end
@@ -2,54 +2,5 @@
2
2
 
3
3
  module OpenHAB
4
4
  module DSL
5
- #
6
- # Provide callback mechanisms for script handling
7
- #
8
- module ScriptHandling
9
- module_function
10
-
11
- #
12
- # Add a block of code to be executed once the rule script has finished loading.
13
- #
14
- # This can occur on OpenHAB start up, when the script is first created, or updated.
15
- #
16
- # Multiple hooks can be added by calling {#script_loaded} multiple times.
17
- # They can be used to perform final initializations.
18
- #
19
- # @return [void]
20
- #
21
- # @example
22
- # script_loaded do
23
- # logger.info 'Hi, this script has just finished loading'
24
- # end
25
- #
26
- # @example
27
- # script_loaded do
28
- # logger.info 'I will be called after the script finished loading too'
29
- # end
30
- #
31
- def script_loaded(&block)
32
- Core::ScriptHandlingCallbacks.script_loaded_hooks << block
33
- end
34
-
35
- #
36
- # Add a block of code to be executed when the script is unloaded.
37
- #
38
- # This can occur when OpenHAB shuts down, or when the script is being reloaded.
39
- #
40
- # Multiple hooks can be added by calling {#script_unloaded} multiple times.
41
- # They can be used to perform final cleanup.
42
- #
43
- # @return [void]
44
- #
45
- # @example
46
- # script_unloaded do
47
- # logger.info 'Hi, this script has been unloaded'
48
- # end
49
- #
50
- def script_unloaded(&block)
51
- Core::ScriptHandlingCallbacks.script_unloaded_hooks << block
52
- end
53
- end
54
5
  end
55
6
  end