openhab-jrubyscripting 5.0.0.rc1 → 5.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -6,36 +6,6 @@ module OpenHAB
6
6
  # Contains extensions to simplify working with {Core::Things::Thing Thing}s.
7
7
  #
8
8
  module Things
9
- # Stores all things created in scripts, and notifies the ThingRegistry
10
- # of their existence
11
- # aa@!visibility private
12
- class ThingProvider < org.openhab.core.common.registry.AbstractProvider
13
- include org.openhab.core.thing.ThingProvider
14
- include Singleton
15
-
16
- def initialize
17
- super
18
-
19
- @things = []
20
-
21
- $things.add_provider(self)
22
- ScriptHandling.script_unloaded { $things.remove_provider(self) }
23
- end
24
-
25
- # Add a thing to this provider
26
- def add(thing)
27
- thing = thing.build
28
- @things << thing
29
- notify_listeners_about_added_element(thing)
30
- thing
31
- end
32
-
33
- # Get all items in this provider
34
- def getAll # rubocop:disable Naming/MethodName required by java interface
35
- @things
36
- end
37
- end
38
-
39
9
  # A thing builder allows you to dynamically create OpenHAB thing at runtime.
40
10
  # This can be useful either to create things as soon as the script loads,
41
11
  # or even later based on a rule executing.
@@ -45,6 +15,13 @@ module OpenHAB
45
15
  # thing "astro:sun:home", "Astro Sun Data", config: { "geolocation" => "0,0" }
46
16
  # end
47
17
  class Builder
18
+ # @return [org.openhab.core.things.ManagedThingProvider]
19
+ attr_reader :provider
20
+
21
+ def initialize(provider)
22
+ @provider = Core::Things::Provider.current(provider)
23
+ end
24
+
48
25
  # Create a new Bridge
49
26
  # @see BridgeBuilder#initialize
50
27
  def bridge(*args, **kwargs, &block)
@@ -62,7 +39,7 @@ module OpenHAB
62
39
  def build(klass, *args, **kwargs, &block)
63
40
  builder = klass.new(*args, **kwargs)
64
41
  builder.instance_eval(&block) if block
65
- thing = ThingProvider.instance.add(builder)
42
+ thing = provider.add(builder.build)
66
43
  thing = Core::Things::Proxy.new(thing)
67
44
  thing.enable(enabled: builder.enabled) unless builder.enabled.nil?
68
45
  thing
@@ -11,6 +11,7 @@ module OpenHAB
11
11
 
12
12
  # Keys to persist
13
13
  KNOWN_KEYS = %i[
14
+ openhab_providers
14
15
  openhab_rule_uid
15
16
  openhab_rule_type
16
17
  openhab_units
@@ -11,7 +11,7 @@ module OpenHAB
11
11
  class TimerManager
12
12
  include Singleton
13
13
 
14
- ScriptHandling.script_unloaded { instance.cancel_all }
14
+ Core::ScriptHandling.script_unloaded { instance.cancel_all }
15
15
 
16
16
  # @!visibility private
17
17
  def initialize
@@ -31,7 +31,10 @@ module OpenHAB
31
31
  # timer when one doesn't already exist
32
32
  next old_timer if !reschedule && old_timer
33
33
 
34
- old_timer&.cancel
34
+ if old_timer
35
+ old_timer.cancel!
36
+ @timers.remove(old_timer)
37
+ end
35
38
  Core::Timer.new(duration, id: id, thread_locals: thread_locals, block: block)
36
39
  end
37
40
  end
@@ -55,7 +58,7 @@ module OpenHAB
55
58
  @timers.remove(timer)
56
59
  return unless timer.id
57
60
 
58
- @timers_by_id.delete(timer.id)
61
+ @timers_by_id.remove(timer.id)
59
62
  end
60
63
 
61
64
  #
@@ -67,7 +70,9 @@ module OpenHAB
67
70
  def cancel(id)
68
71
  result = false
69
72
  @timers_by_id.compute_if_present(id) do |_key, timer|
70
- result = timer.cancel
73
+ result = timer.cancel!
74
+ @timers.remove(timer)
75
+
71
76
  nil
72
77
  end
73
78
  result
@@ -127,7 +132,7 @@ module OpenHAB
127
132
  def schedule(id)
128
133
  @timers_by_id.compute(id) do |_key, timer|
129
134
  new_timer = yield timer
130
- raise ArgumentError, "Block must return a timer or nil" unless timer.is_a?(Core::Timer) || timer.nil?
135
+ raise ArgumentError, "Block must return a timer or nil" unless new_timer.is_a?(Core::Timer) || new_timer.nil?
131
136
 
132
137
  if !new_timer.equal?(timer) && new_timer&.id
133
138
  raise ArgumentError,
@@ -136,8 +141,9 @@ module OpenHAB
136
141
 
137
142
  if timer&.cancelled?
138
143
  new_timer = nil
139
- elsif new_timer.nil? && !timer&.cancelled?
140
- timer&.cancel
144
+ elsif new_timer.nil? && timer && !timer.cancelled?
145
+ timer.cancel!
146
+ @timers.remove(timer)
141
147
  end
142
148
  next unless new_timer
143
149
 
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of OpenHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.0.0.rc1"
7
+ VERSION = "5.0.0.rc2"
8
8
  end
9
9
  end
data/lib/openhab/dsl.rb CHANGED
@@ -30,7 +30,7 @@ module OpenHAB
30
30
  # include this before Core::Actions so that Core::Action's method_missing
31
31
  # takes priority
32
32
  include Core::EntityLookup
33
- [Core::Actions, Rules::Terse, ScriptHandling].each do |mod|
33
+ [Core::Actions, Core::ScriptHandling, Rules::Terse].each do |mod|
34
34
  # make these available both as regular and class methods
35
35
  include mod
36
36
  singleton_class.include mod
@@ -84,14 +84,6 @@ module OpenHAB
84
84
  builder.name(name)
85
85
  logger.trace { builder.inspect }
86
86
  builder.build(script)
87
- rescue Exception => e
88
- if (defined?(::RSpec::Expectations::ExpectationNotMetError) &&
89
- e.is_a?(::RSpec::Expectations::ExpectationNotMetError)) ||
90
- (defined?(::RSpec::Mocks::MockExpectationError) && e.is_a?(::RSpec::Mocks::MockExpectationError))
91
- raise e
92
- end
93
-
94
- builder.send(:logger).log_exception(e)
95
87
  end
96
88
  end
97
89
 
@@ -115,17 +107,13 @@ module OpenHAB
115
107
 
116
108
  builder = nil
117
109
  ThreadLocal.thread_local(openhab_rule_type: "script", openhab_rule_uid: id) do
118
- begin
119
- builder = Rules::Builder.new(block.binding)
120
- builder.uid(id)
121
- builder.tags(["Script"])
122
- builder.name(name)
123
- builder.script(&block)
124
- logger.trace { builder.inspect }
125
- builder.build(script)
126
- end
127
- rescue Exception => e
128
- builder.send(:logger).log_exception(e)
110
+ builder = Rules::Builder.new(block.binding)
111
+ builder.uid(id)
112
+ builder.tags(["Script"])
113
+ builder.name(name)
114
+ builder.script(&block)
115
+ logger.trace { builder.inspect }
116
+ builder.build(script)
129
117
  end
130
118
  end
131
119
 
@@ -614,7 +602,7 @@ module OpenHAB
614
602
  # properly restored.
615
603
  #
616
604
  # {unit!} calls are cumulative - additional calls will not erase the effects
617
- # previous calls unless they are for the same dimension.
605
+ # of previous calls unless they are for the same dimension.
618
606
  #
619
607
  # @return [Hash<javax.measure.Dimension=>javax.measure.Unit>]
620
608
  # the prior unit configuration
@@ -657,6 +645,129 @@ module OpenHAB
657
645
  old_units
658
646
  end
659
647
 
648
+ #
649
+ # Sets the implicit provider(s) for operations inside the block.
650
+ #
651
+ # @param (see #provider!)
652
+ # @yield [] The block will be executed in the context of the specified unit(s).
653
+ # @return [Object] the result of the block
654
+ #
655
+ # @example
656
+ # provider(metadata: :persistent) do
657
+ # Switch1.metadata[:last_status_from_service] = status
658
+ # end
659
+ #
660
+ # provider!(metadata: { last_status_from_service: :persistent }, Switch2: :persistent)
661
+ # Switch1.metadata[:last_status_from_service] = status # this will persist in JSONDB
662
+ # Switch1.metadata[:homekit] = "Lightbulb" # this will be removed when the script is deleted
663
+ # Switch2.metadata[:homekit] = "Lightbulb" # this will persist in JSONDB
664
+ #
665
+ # @see provider!
666
+ # @see OpenHAB::Core::Provider.current Provider.current for how the current provider is calculated
667
+ #
668
+ def provider(*args, **kwargs)
669
+ raise ArgumentError, "You must give a block to set the provider for the duration of" unless block_given?
670
+
671
+ begin
672
+ old_providers = provider!(*args, **kwargs)
673
+ yield
674
+ ensure
675
+ Thread.current[:openhab_providers] = old_providers
676
+ end
677
+ end
678
+
679
+ #
680
+ # Permanently set the implicit provider(s) for this thread.
681
+ #
682
+ # @note This method is only intended for use at the top level of rule
683
+ # scripts. If it's used within library methods, or hap-hazardly within
684
+ # rules, things can get very confusing because the prior state won't be
685
+ # properly restored.
686
+ #
687
+ # {provider!} calls are cumulative - additional calls will not erase the effects
688
+ # of previous calls unless they are for the same provider type.
689
+ #
690
+ # @overload provider!(things: nil, items: nil, metadata: nil, links: nil, **metadata_items)
691
+ #
692
+ # @param [Core::Provider, org.openhab.core.registry.common.ManagedProvider, :persistent, :transient, Proc] providers
693
+ # An explicit provider to use. If it's a {Core::Provider}, the type will be inferred automatically.
694
+ # Otherwise it's applied to all types.
695
+ # @param [Hash] providers_by_type
696
+ # A list of providers by type. Type can be `:items`, `:metadata`, `:things`, `:links`,
697
+ # a {GenericItem} applying the provider to all metadata on that item, or a String or Symbol
698
+ # applying the provider to all metadata of that namespace.
699
+ #
700
+ # The provider can be a {org.openhab.core.common.registry.Provider Provider}, `:persistent`,
701
+ # `:transient`, or a Proc returning one of those types. When the Proc is called for metadata
702
+ # elements, the {Core::Items::Metadata::Hash} will be passed as an argument. Therefore it's
703
+ # recommended that you use a Proc, not a Lambda, for permissive argument matching.
704
+ #
705
+ # @return [void]
706
+ #
707
+ # @see provider
708
+ # @see OpenHAB::Core::Provider.current Provider.current for how the current provider is calculated
709
+ #
710
+ def provider!(*providers, **providers_by_type)
711
+ thread_providers = Thread.current[:openhab_providers] ||= {}
712
+ old_providers = thread_providers.dup
713
+
714
+ providers.each do |provider|
715
+ case provider
716
+ when Core::Provider
717
+ thread_providers[provider.class.type] = provider
718
+ when org.openhab.core.common.registry.ManagedProvider
719
+ type = provider.type
720
+ unless type
721
+ raise ArgumentError, "#{provider.inspect} is for objects which are not supported by openhab-jrubyscripting"
722
+ end
723
+
724
+ thread_providers[type] = provider
725
+ when Proc,
726
+ :transient,
727
+ :persistent
728
+ Core::Provider::KNOWN_TYPES.each do |known_type|
729
+ thread_providers[known_type] = provider
730
+ end
731
+ when Hash
732
+ # non-symbols can't be used as kwargs, so Item keys show up as a separate hash here
733
+ # just merge it in, and allow it to be handled below
734
+ providers_by_type.merge!(provider)
735
+ else
736
+ raise ArgumentError, "#{provider.inspect} is not a valid provider"
737
+ end
738
+ end
739
+
740
+ providers_by_type.each do |type, provider|
741
+ case provider
742
+ when Proc,
743
+ org.openhab.core.common.registry.ManagedProvider,
744
+ :transient,
745
+ :persistent,
746
+ nil
747
+ nil
748
+ else
749
+ raise ArgumentError, "#{provider.inspect} is not a valid provider"
750
+ end
751
+
752
+ case type
753
+ when :items, :metadata, :things, :links
754
+ if provider.is_a?(org.openhab.core.common.registry.ManagedProvider) && provider.type != type
755
+ raise ArgumentError, "#{provider.inspect} is not a provider for #{type}"
756
+ end
757
+
758
+ thread_providers[type] = provider
759
+ when Symbol, String
760
+ (thread_providers[:metadata_namespaces] ||= {})[type.to_s] = provider
761
+ when GenericItem
762
+ (thread_providers[:metadata_items] ||= {})[type.name] = provider
763
+ else
764
+ raise ArgumentError, "#{type.inspect} is not provider type"
765
+ end
766
+ end
767
+
768
+ old_providers
769
+ end
770
+
660
771
  # @!visibility private
661
772
  def try_parse_time_like(string)
662
773
  return string unless string.is_a?(String)
@@ -675,7 +786,6 @@ module OpenHAB
675
786
  end
676
787
 
677
788
  OpenHAB::Core.wait_till_openhab_ready
678
- OpenHAB::Core.add_rubylib_to_load_path
679
789
 
680
790
  # import Items classes into global namespace
681
791
  OpenHAB::Core::Items.import_into_global_namespace
data/lib/openhab/log.rb CHANGED
@@ -264,7 +264,7 @@ module OpenHAB
264
264
  def log_exception(exception)
265
265
  exception = clean_backtrace(exception)
266
266
  error do
267
- "#{exception.message} (#{exception.class})\n#{name}#{exception.backtrace&.join("\n")}"
267
+ "#{exception.message} (#{exception.class})\n#{exception.backtrace&.join("\n")}"
268
268
  end
269
269
  end
270
270
 
@@ -208,7 +208,6 @@ module OpenHAB
208
208
  require "openhab/dsl"
209
209
 
210
210
  require_relative "mocks/persistence_service"
211
- require_relative "mocks/metadata_provider"
212
211
  require_relative "mocks/timer"
213
212
 
214
213
  # override several DSL methods
@@ -400,34 +399,18 @@ module OpenHAB
400
399
  # need to transfer autoupdate metadata from GenericMetadataProvider to ManagedMetadataProvider
401
400
  # so that we can mutate it in the future
402
401
  def set_up_autoupdates
403
- gmp = OSGi.service("org.openhab.core.model.item.internal.GenericMetadataProvider")
404
- mr = Core::Items::Metadata::NamespaceHash.registry
405
- mmp = mr.managed_provider.get
406
- to_add = []
407
- gmp.all.each do |metadata|
402
+ registry = Core::Items::Metadata::Provider.registry
403
+ registry.class.field_reader :identifierToElement
404
+
405
+ autoupdate_provider = Core::Items::Metadata::Provider.send(:new)
406
+ registry.all.each do |metadata|
408
407
  next unless metadata.uid.namespace == "autoupdate"
409
408
 
410
- to_add << metadata
411
- end
412
- gmp.remove_metadata_by_namespace("autoupdate")
413
-
414
- to_add.each do |m|
415
- # we can't just update; we need to remove and add
416
- # because this was a duplicate key, so the ManagedProvider
417
- # knows about it, but the registry does not. So
418
- # removing and adding gets it to notify the registry
419
- # that it has it
420
- mmp.remove(m.uid) if mmp.get(m.uid)
421
- mmp.add(m)
409
+ # tweak the registry to allow us to overwrite this element
410
+ registry.identifierToElement.delete(metadata.uid)
411
+ autoupdate_provider.add(metadata)
422
412
  end
423
413
  end
424
-
425
- def restore_autoupdate_items
426
- return unless instance_variable_defined?(:@autoupdated_items)
427
-
428
- @autoupdated_items&.each(&:commit)
429
- @autoupdated_items = nil
430
- end
431
414
  end
432
415
 
433
416
  if defined?(::RSpec)
@@ -41,28 +41,32 @@ module OpenHAB
41
41
  @known_rules = Core.rule_registry.all.map(&:uid)
42
42
  end
43
43
 
44
+ # Each spec gets temporary providers
45
+ [Core::Items::Provider,
46
+ Core::Items::Metadata::Provider,
47
+ Core::Things::Provider,
48
+ Core::Things::Links::Provider].each do |klass|
49
+ config.around do |example|
50
+ klass.new(&example)
51
+ end
52
+ end
53
+
44
54
  config.before do |example|
45
- @item_provider = DSL::Items::ItemProvider.send(:new)
46
- allow(DSL::Items::ItemProvider).to receive(:instance).and_return(@item_provider)
47
- @thing_provider = DSL::Things::ThingProvider.send(:new)
48
- allow(DSL::Things::ThingProvider).to receive(:instance).and_return(@thing_provider)
49
- @item_channel_link_provider = DSL::Items::ItemChannelLinkProvider.send(:new)
50
- allow(DSL::Items::ItemChannelLinkProvider).to receive(:instance).and_return(@item_channel_link_provider)
51
- mr = Core::Items::Metadata::NamespaceHash.registry
52
- @metadata_provider = Mocks::MetadataProvider.new(mr.managed_provider.get)
53
- mr.add_provider(@metadata_provider)
54
- mr.set_managed_provider(@metadata_provider)
55
+ # clear persisted thing status
55
56
  tm = OSGi.service("org.openhab.core.thing.ThingManager")
56
57
  tm.class.field_reader :storage
57
58
  tm.storage.keys.each { |k| tm.storage.remove(k) } # rubocop:disable Style/HashEachMethods not a hash
58
- @log_index = File.size(log_file)
59
+
59
60
  profile_factory = Core::ProfileFactory.send(:new)
60
61
  @profile_factory_registration = OSGi.register_service(profile_factory)
61
62
  allow(Core::ProfileFactory).to receive(:instance).and_return(profile_factory)
63
+
62
64
  stub_const("OpenHAB::Core::Timer", Mocks::Timer) if self.class.mock_timers?
65
+
63
66
  log_line = "rspec #{example.location} # #{example.full_description}"
64
67
  logger.info(log_line)
65
68
  Logger.events.info(log_line)
69
+ @log_index = File.size(log_file)
66
70
  end
67
71
 
68
72
  config.after do
@@ -70,21 +74,14 @@ module OpenHAB
70
74
  (Core.rule_registry.all.map(&:uid) - @known_rules).each do |uid|
71
75
  remove_rule(uid) if defined?(remove_rule)
72
76
  end
73
- $ir.remove_provider(@item_provider)
74
77
  Core::Items::Proxy.reset_cache
75
- $things.remove_provider(@thing_provider)
76
78
  Core::Things::Proxy.reset_cache
77
- registry = OSGi.service("org.openhab.core.thing.link.ItemChannelLinkRegistry")
78
- registry.remove_provider(@item_channel_link_provider)
79
- Core::Items::Metadata::NamespaceHash.registry.remove_provider(@metadata_provider)
80
- @metadata_provider.restore_parent
81
79
  @profile_factory_registration.unregister
82
80
  timers.cancel_all
83
81
  # timers and rules have already been canceled, so we can safely just
84
82
  # wipe this
85
83
  DSL::Items::TimedCommand.timed_commands.clear
86
84
  Timecop.return
87
- restore_autoupdate_items
88
85
  Mocks::PersistenceService.instance.reset
89
86
  end
90
87
  end
@@ -70,6 +70,11 @@ module OpenHAB
70
70
  return false if terminated? || cancelled?
71
71
 
72
72
  DSL::TimerManager.instance.delete(self)
73
+ cancel!
74
+ true
75
+ end
76
+
77
+ def cancel!
73
78
  @execution_time = nil
74
79
  true
75
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-jrubyscripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc1
4
+ version: 5.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -336,10 +336,12 @@ files:
336
336
  - lib/openhab/core/items/metadata.rb
337
337
  - lib/openhab/core/items/metadata/hash.rb
338
338
  - lib/openhab/core/items/metadata/namespace_hash.rb
339
+ - lib/openhab/core/items/metadata/provider.rb
339
340
  - lib/openhab/core/items/number_item.rb
340
341
  - lib/openhab/core/items/numeric_item.rb
341
342
  - lib/openhab/core/items/persistence.rb
342
343
  - lib/openhab/core/items/player_item.rb
344
+ - lib/openhab/core/items/provider.rb
343
345
  - lib/openhab/core/items/proxy.rb
344
346
  - lib/openhab/core/items/registry.rb
345
347
  - lib/openhab/core/items/rollershutter_item.rb
@@ -350,12 +352,16 @@ files:
350
352
  - lib/openhab/core/items/switch_item.rb
351
353
  - lib/openhab/core/lazy_array.rb
352
354
  - lib/openhab/core/profile_factory.rb
355
+ - lib/openhab/core/provider.rb
356
+ - lib/openhab/core/registry.rb
353
357
  - lib/openhab/core/script_handling.rb
354
358
  - lib/openhab/core/things.rb
355
359
  - lib/openhab/core/things/channel.rb
356
360
  - lib/openhab/core/things/channel_uid.rb
357
361
  - lib/openhab/core/things/item_channel_link.rb
362
+ - lib/openhab/core/things/links/provider.rb
358
363
  - lib/openhab/core/things/profile_callback.rb
364
+ - lib/openhab/core/things/provider.rb
359
365
  - lib/openhab/core/things/proxy.rb
360
366
  - lib/openhab/core/things/registry.rb
361
367
  - lib/openhab/core/things/thing.rb
@@ -384,6 +390,7 @@ files:
384
390
  - lib/openhab/core/types/up_down_type.rb
385
391
  - lib/openhab/core/uid.rb
386
392
  - lib/openhab/core_ext.rb
393
+ - lib/openhab/core_ext/java/class.rb
387
394
  - lib/openhab/core_ext/java/duration.rb
388
395
  - lib/openhab/core_ext/java/local_date.rb
389
396
  - lib/openhab/core_ext/java/local_time.rb
@@ -444,7 +451,6 @@ files:
444
451
  - lib/openhab/rspec/mocks/bundle_install_support.rb
445
452
  - lib/openhab/rspec/mocks/bundle_resolver.rb
446
453
  - lib/openhab/rspec/mocks/event_admin.rb
447
- - lib/openhab/rspec/mocks/metadata_provider.rb
448
454
  - lib/openhab/rspec/mocks/persistence_service.rb
449
455
  - lib/openhab/rspec/mocks/safe_caller.rb
450
456
  - lib/openhab/rspec/mocks/synchronous_executor.rb
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module RSpec
5
- module Mocks
6
- class MetadataProvider
7
- org.openhab.core.common.registry.Identifiable
8
- include org.openhab.core.items.ManagedMetadataProvider
9
-
10
- def initialize(parent)
11
- @metadata = {}
12
- @listeners = []
13
- @parent = parent
14
- @removed_from_parent = []
15
- end
16
-
17
- def addProviderChangeListener(listener) # rubocop:disable Naming/MethodName required by java interface
18
- @listeners << listener
19
- end
20
-
21
- def removeProviderChangeListener(listener) # rubocop:disable Naming/MethodName required by java interface
22
- old = @listeners.delete(listener)
23
- return unless old
24
-
25
- @listeners.each { |l| l.removed(self, old) }
26
- end
27
-
28
- def add(metadata)
29
- @metadata[metadata.uid] = metadata
30
- @listeners.each { |l| l.added(self, metadata) }
31
- end
32
-
33
- def update(metadata)
34
- old_element = @metadata[metadata.uid]
35
- raise ArgumentError if old_element.nil?
36
-
37
- @metadata[metadata.uid] = metadata
38
- @listeners.each { |l| l.updated(self, old_element, metadata) }
39
- metadata
40
- end
41
-
42
- def remove(key)
43
- m = @parent.remove(key)
44
- @removed_from_parent << m if m
45
- m = @metadata.delete(key)
46
- @listeners.each { |l| l.removed(self, m) } if m
47
- m
48
- end
49
-
50
- def restore_parent
51
- @removed_from_parent.each do |m|
52
- @parent.add(m)
53
- end
54
- end
55
-
56
- def get(key)
57
- @metadata[key]
58
- end
59
-
60
- def getAll # rubocop:disable Naming/MethodName required by java interface
61
- @metadata.values
62
- end
63
-
64
- def removeItemMetadata(item_name) # rubocop:disable Naming/MethodName required by java interface
65
- @metadata.delete_if do |k, v|
66
- next unless k.item_name == item_name
67
-
68
- @listeners.each { |l| l.removed(self, v) }
69
- true
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end