rspec-openhab-scripting 1.0.5 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 116f3664ed9d88e87a4030cf7006dc82c3c517b7b6f54b2611989f5aa48f7988
4
- data.tar.gz: d257ff1821dad6bca67eaa1cb848d3cc55b1a05f7cb02d5f20e9e34d2b2c3c17
3
+ metadata.gz: 5e3e336c4b70557c83f8116331678ecc50f0ec67326049b70302893903d48f18
4
+ data.tar.gz: 7d10a10b19aeacbc89eba86b0c40875c7c6f43a0b1529fc9af7ec06ab569d0bc
5
5
  SHA512:
6
- metadata.gz: c29fdc081461392dcad67246de4b784c012c0963d971acc1ca4f2c4f78e9229698ef36c7c1946c1b14e290b7bf11c77977f4d20a0e39b41fa950b3e2609663b6
7
- data.tar.gz: 859f14916f43496a242adf17896a2d8bb5cd46027d101c5e3da70ebc215fba5bcecf9f71d0dd4eb41b9022e8879d427af3cbb4624a909af33864f5011ccdaeee
6
+ metadata.gz: 6f6eaf2489819f42da8e95f5a8095ead7314c62a6f338d4d605bb6e924848cafd318abe97fbd0503bf48ae43dc747f6663c917b3c597e5c6ec99515dd088a7c7
7
+ data.tar.gz: c3a04761c79f529c49b11597ae63bfd409ab2a117f24af666a2638d541690d908c4258efdaaec5f01921c7680f8c643f8bcfe5f99abc8c0d67b285c40df27a96
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module OpenHAB
5
+ module Configuration
6
+ class << self
7
+ # Copy binding configuration from the root OpenHAB instance
8
+ # Default `true`
9
+ # @return [true, false]
10
+ attr_accessor :include_bindings
11
+ # Copy the JSONDB (managed thing and item configuration) from the root
12
+ # OpenHAB instance
13
+ # Default `true`
14
+ # @return [true, false]
15
+ attr_accessor :include_jsondb
16
+ # Use a private (empty) confdir (scripts, rules, items, and things
17
+ # # files), instead of sharing with the root OpenHAB
18
+ # instance.
19
+ # Default `false`
20
+ # @return [true, false]
21
+ attr_accessor :private_confdir
22
+ # Use the root OpenHAB instance directly, rather than creating a
23
+ # private (but linked) instance.
24
+ # @default `false`
25
+ # @return [true, false]
26
+ attr_accessor :use_root_instance
27
+ end
28
+
29
+ self.include_bindings = true
30
+ self.include_jsondb = true
31
+ self.private_confdir = false
32
+ self.use_root_instance = false
33
+ end
34
+ end
35
+ end
@@ -13,6 +13,10 @@ module OpenHAB
13
13
  @proxies[item.name] = super
14
14
  end
15
15
  end
16
+
17
+ def reset_cache
18
+ @proxies = {}
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ module Things
6
+ class Thing
7
+ @proxies = {}
8
+
9
+ class << self
10
+ # ensure each item only has a single proxy, so that
11
+ # expect(item).to receive(:method) works
12
+ def new(thing)
13
+ @proxies.fetch(thing.uid.to_s) do
14
+ @proxies[thing.uid.to_s] = super
15
+ end
16
+ end
17
+
18
+ def reset_cache
19
+ @proxies = {}
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -75,7 +75,7 @@ module RSpec
75
75
  @rules.fetch(rule_name).execute(nil, { "event" => event })
76
76
  end
77
77
 
78
- def trigger_channel(channel, event)
78
+ def trigger_channel(channel, event = "")
79
79
  channel = org.openhab.core.thing.ChannelUID.new(channel) if channel.is_a?(String)
80
80
  channel = channel.uid if channel.is_a?(org.openhab.core.thing.Channel)
81
81
  thing = channel.thing
@@ -112,6 +112,7 @@ module RSpec
112
112
  require_relative "actions"
113
113
  require_relative "core/item_proxy"
114
114
  require_relative "dsl/timers/timer"
115
+ require_relative "dsl/things/thing"
115
116
  # TODO: still needed?
116
117
  require_relative "dsl/rules/triggers/watch"
117
118
 
@@ -174,6 +175,19 @@ module RSpec
174
175
  end
175
176
  end
176
177
 
178
+ def install_addon(addon_id, wait: true)
179
+ addon_service = ::OpenHAB::Core::OSGI.service("org.openhab.core.addon.AddonService")
180
+ addon_service.install(addon_id)
181
+ return unless wait
182
+
183
+ loop do
184
+ addon = addon_service.get_addon(addon_id, nil)
185
+ return if addon.installed?
186
+
187
+ sleep 0.25
188
+ end
189
+ end
190
+
177
191
  private
178
192
 
179
193
  def jrubyscripting_config
@@ -4,20 +4,18 @@ module RSpec
4
4
  module OpenHAB
5
5
  Object.include RSpec::OpenHAB::Helpers if defined?(IRB)
6
6
 
7
+ Helpers.launch_karaf(
8
+ include_bindings: Configuration.include_bindings,
9
+ include_jsondb: Configuration.include_jsondb,
10
+ private_confdir: Configuration.private_confdir,
11
+ use_root_instance: Configuration.use_root_instance
12
+ )
13
+
7
14
  if RSpec.respond_to?(:configure)
8
15
  RSpec.configure do |config|
9
- config.add_setting :include_openhab_bindings, default: true
10
- config.add_setting :include_openhab_jsondb, default: true
11
- config.add_setting :private_openhab_confdir, default: false
12
- config.add_setting :use_root_openhab_instance, default: false
13
-
14
16
  config.before(:suite) do
15
- Helpers.launch_karaf(include_bindings: config.include_openhab_bindings,
16
- include_jsondb: config.include_openhab_jsondb,
17
- private_confdir: config.private_openhab_confdir,
18
- use_root_instance: config.use_root_openhab_instance)
19
17
  config.include ::OpenHAB::Core::EntityLookup
20
- Helpers.autorequires unless config.private_openhab_confdir
18
+ Helpers.autorequires unless Configuration.private_confdir
21
19
  Helpers.send(:set_up_autoupdates)
22
20
  Helpers.load_transforms
23
21
  Helpers.load_rules
@@ -35,10 +33,14 @@ module RSpec
35
33
  end
36
34
 
37
35
  config.before do
38
- next unless defined?(::OpenHAB::DSL::Items::ItemProvider)
39
-
40
- @item_provider = ::OpenHAB::DSL::Items::ItemProvider.send(:new)
41
- allow(::OpenHAB::DSL::Items::ItemProvider).to receive(:instance).and_return(@item_provider)
36
+ if defined?(::OpenHAB::DSL::Items::ItemProvider)
37
+ @item_provider = ::OpenHAB::DSL::Items::ItemProvider.send(:new)
38
+ allow(::OpenHAB::DSL::Items::ItemProvider).to receive(:instance).and_return(@item_provider)
39
+ end
40
+ if defined?(::OpenHAB::DSL::Things::ThingProvider)
41
+ @thing_provider = ::OpenHAB::DSL::Things::ThingProvider.send(:new)
42
+ allow(::OpenHAB::DSL::Things::ThingProvider).to receive(:instance).and_return(@thing_provider)
43
+ end
42
44
  end
43
45
 
44
46
  config.after do
@@ -47,6 +49,9 @@ module RSpec
47
49
  ::OpenHAB::Core.rule_registry.remove(uid)
48
50
  end
49
51
  $ir.remove_provider(@item_provider) if instance_variable_defined?(:@item_provider) && @item_provider
52
+ ::OpenHAB::Core::ItemProxy.reset_cache
53
+ $things.remove_provider(@thing_provider) if instance_variable_defined?(:@thing_provider) && @thing_provider
54
+ ::OpenHAB::DSL::Things::Thing.reset_cache
50
55
  ::OpenHAB::DSL::Timers.timer_manager.cancel_all
51
56
  Timecop.return
52
57
  restore_autoupdate_items
@@ -304,7 +304,6 @@ module RSpec
304
304
  BLOCKED_COMPONENTS = {
305
305
  "org.openhab.core" => %w[
306
306
  org.openhab.core.addon.AddonEventFactory
307
- org.openhab.core.binding.BindingInfoRegistry
308
307
  org.openhab.core.binding.i18n.BindingI18nLocalizationService
309
308
  org.openhab.core.internal.auth.ManagedUserProvider
310
309
  org.openhab.core.internal.auth.UserRegistryImpl
@@ -675,6 +674,7 @@ module RSpec
675
674
  def cleanup_instance
676
675
  cleanup_clone
677
676
  minimize_installed_features
677
+ filter_addons
678
678
  end
679
679
 
680
680
  def cleanup_clone
@@ -685,10 +685,23 @@ module RSpec
685
685
  "#{oh_userdata}/tmp/*",
686
686
  "#{oh_userdata}/jsondb/org.openhab.marketplace.json",
687
687
  "#{oh_userdata}/jsondb/org.openhab.jsonaddonservice.json",
688
+ "#{path}/config/org/apache/felix/fileinstall",
688
689
  "#{felix_cm}/org/openhab/jsonaddonservice.config"])
689
690
  FileUtils.rm_rf("#{oh_userdata}/jsondb") unless include_jsondb
690
691
  end
691
692
 
693
+ def filter_addons
694
+ config_file = "#{path}/etc/org.apache.felix.fileinstall-deploy.cfg"
695
+ return unless File.exist?(config_file)
696
+
697
+ config = File.read(config_file)
698
+ new_config = config.sub(/^(felix\.fileinstall\.filter\s+=)[^\n]+$/, "\\1 .*/openhab-addons-[^/]+\\.kar")
699
+
700
+ return if config == new_config
701
+
702
+ File.write(config_file, new_config)
703
+ end
704
+
692
705
  def prune_startlevels
693
706
  config_file = java.lang.System.get_property("openhab.servicecfg")
694
707
  return unless File.exist?(config_file)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OpenHAB
5
- VERSION = "1.0.5"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -12,6 +12,7 @@ $LOAD_PATH.unshift("#{__dir__}/rspec")
12
12
 
13
13
  require "diff/lcs"
14
14
 
15
+ require "rspec/openhab/configuration"
15
16
  require "rspec/openhab/helpers"
16
17
  require "rspec/openhab/karaf"
17
18
  require "rspec/openhab/hooks"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
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-09-27 00:00:00.000000000 Z
11
+ date: 2022-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -187,6 +187,7 @@ files:
187
187
  - lib/rspec-openhab-scripting.rb
188
188
  - lib/rspec/openhab/actions.rb
189
189
  - lib/rspec/openhab/api.rb
190
+ - lib/rspec/openhab/configuration.rb
190
191
  - lib/rspec/openhab/core/item_proxy.rb
191
192
  - lib/rspec/openhab/core/logger.rb
192
193
  - lib/rspec/openhab/core/mocks/bundle_install_support.rb
@@ -197,6 +198,7 @@ files:
197
198
  - lib/rspec/openhab/core/mocks/thing_handler.rb
198
199
  - lib/rspec/openhab/core/openhab_setup.rb
199
200
  - lib/rspec/openhab/dsl/rules/triggers/watch.rb
201
+ - lib/rspec/openhab/dsl/things/thing.rb
200
202
  - lib/rspec/openhab/dsl/timers/timer.rb
201
203
  - lib/rspec/openhab/helpers.rb
202
204
  - lib/rspec/openhab/hooks.rb