rspec-openhab-scripting 0.0.3-java → 0.0.6-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a757dc4165cbe3769b13d7a24b444d6d3d66fa7e6fdae117fa76bd87c230c03
4
- data.tar.gz: 0243f89dc45dad378693e7a73b3b842aa11563f18a464936a6b42971f4f76f07
3
+ metadata.gz: 36b9bb280e4fd6893f93a5ca0197dd4a7a08c286b4cc6835c44f81c487e497fe
4
+ data.tar.gz: 6390495a9d8ff5a522f86f4e1d50155bf93d45a14a59b9ba3b9147c49cd27548
5
5
  SHA512:
6
- metadata.gz: 6b6461bf0bfc7120efef2611e2d6ae18d09c1da6a33a9d9e1825ede880329475d9d0ccbfd445ebcc427eb265a68e785fa98c157e0676c62a772a814af586e076
7
- data.tar.gz: 600900bcceda586ea77aa16f6fd925b6a1960615ce64a6e0e3054250c2fb444c5cddfe73223341397f6f88d0eba4b6a2b3453b2f896d7572c7fed66c3c0251ee
6
+ metadata.gz: c571aa03ed3fc7521be9e65924b274204a7ab4382101467af88847350632a7cc159795cbb238765af6fd6b0abb41b2934b656037571de5a3936972905784255e
7
+ data.tar.gz: 757a9bcfbbe1d5361500413b5e6cd74b6a1eda00df2483abb22e200f4d1ae3845fa6bfafcb4501b3b1060f91710a721e1727db3a695447a90aa7f91ef3b8643a
@@ -15,12 +15,19 @@ module OpenHAB
15
15
  end
16
16
 
17
17
  def version
18
- body = @faraday.get.body
19
- version = body.dig("runtimeInfo", "version")
20
- version = "#{version}-SNAPSHOT" if body.dig("runtimeInfo", "buildString")&.start_with?("Build #")
18
+ version = root_data.dig("runtimeInfo", "version")
19
+ version = "#{version}-SNAPSHOT" if root_data.dig("runtimeInfo", "buildString")&.start_with?("Build #")
21
20
  version
22
21
  end
23
22
 
23
+ def locale
24
+ root_data["locale"]
25
+ end
26
+
27
+ def measurement_system
28
+ root_data["measurementSystem"]
29
+ end
30
+
24
31
  def items
25
32
  @faraday.get("items", metadata: ".*").body
26
33
  end
@@ -30,5 +37,11 @@ module OpenHAB
30
37
  rescue Faraday::ResourceNotFound
31
38
  nil
32
39
  end
40
+
41
+ private
42
+
43
+ def root_data
44
+ @root_data ||= @faraday.get.body
45
+ end
33
46
  end
34
47
  end
@@ -34,8 +34,11 @@ module OpenHAB
34
34
  class BundleContext
35
35
  include org.osgi.framework.BundleContext
36
36
 
37
+ attr_reader :bundles
38
+
37
39
  def initialize(event_manager)
38
40
  @event_manager = event_manager
41
+ @bundles = []
39
42
  end
40
43
 
41
44
  def register_service(klass, service, _properties)
@@ -46,6 +49,10 @@ module OpenHAB
46
49
 
47
50
  @event_manager.add_event_subscriber(service)
48
51
  end
52
+
53
+ def get_service_reference(klass); end
54
+ def get_service(klass); end
55
+ def add_bundle_listener(listener); end
49
56
  end
50
57
 
51
58
  # don't depend on org.openhab.core.test
@@ -100,6 +107,17 @@ module OpenHAB
100
107
  end
101
108
  end
102
109
 
110
+ class ComponentContext
111
+ include org.osgi.service.component.ComponentContext
112
+
113
+ attr_reader :properties, :bundle_context
114
+
115
+ def initialize(bundle_context)
116
+ @properties = java.util.Hashtable.new
117
+ @bundle_context = bundle_context
118
+ end
119
+ end
120
+
103
121
  # subclass to expose private fields
104
122
  class EventManager < org.openhab.core.internal.events.OSGiEventManager
105
123
  field_reader :typedEventFactories, :typedEventSubscribers
@@ -108,6 +126,8 @@ module OpenHAB
108
126
  @imported = false
109
127
 
110
128
  class << self
129
+ attr_accessor :api
130
+
111
131
  def import_presets
112
132
  return if @imported
113
133
 
@@ -127,6 +147,9 @@ module OpenHAB
127
147
  at_exit { eh.close }
128
148
  ea = EventAdmin.new(eh)
129
149
  ep = org.openhab.core.internal.events.OSGiEventPublisher.new(ea)
150
+ bc = BundleContext.new(em)
151
+ cc = ComponentContext.new(bc)
152
+ cc.properties["measurementSystem"] = api.measurement_system if api
130
153
 
131
154
  # the registries!
132
155
  ss = VolatileStorageService.new
@@ -137,6 +160,10 @@ module OpenHAB
137
160
  ir = org.openhab.core.internal.items.ItemRegistryImpl.new(mr)
138
161
  ir.managed_provider = mip = org.openhab.core.items.ManagedItemProvider.new(ss, nil)
139
162
  ir.add_provider(mip)
163
+ ir.event_publisher = ep
164
+ up = org.openhab.core.internal.i18n.I18nProviderImpl.new(cc)
165
+ ir.unit_provider = up
166
+ ir.item_state_converter = org.openhab.core.internal.items.ItemStateConverterImpl.new(up)
140
167
  tr = org.openhab.core.thing.internal.ThingRegistryImpl.new
141
168
  mtr = org.openhab.core.automation.internal.type.ModuleTypeRegistryImpl.new
142
169
  rr = org.openhab.core.automation.internal.RuleRegistryImpl.new
@@ -205,7 +232,6 @@ module OpenHAB
205
232
  em.add_event_factory(ief)
206
233
 
207
234
  # set up the rules engine part 2
208
- bc = BundleContext.new(em)
209
235
  k = org.openhab.core.automation.internal.module.factory.CoreModuleHandlerFactory
210
236
  # depending on OH version, this class is set up differently
211
237
  cmhf = begin
@@ -15,11 +15,8 @@ module OpenHAB
15
15
  Timers.timer_manager.add(self)
16
16
  end
17
17
 
18
- def reschedule(duration = nil)
19
- duration ||= @duration
20
-
18
+ def reschedule(_duration = nil)
21
19
  Timers.timer_manager.add(self)
22
- reschedule(OpenHAB::DSL.to_zdt(duration))
23
20
  end
24
21
 
25
22
  #
@@ -34,6 +31,10 @@ module OpenHAB
34
31
  def terminated?; end
35
32
  alias_method :has_terminated, :terminated?
36
33
 
34
+ def is_active # rubocop:disable Naming/PredicateName
35
+ false
36
+ end
37
+
37
38
  private
38
39
 
39
40
  def timer_block
@@ -1,47 +1,79 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Style/GlobalVars
3
4
  module RSpec
4
5
  module OpenHAB
5
6
  module Items
6
- module_function
7
-
8
- # rubocop:disable Style/GlobalVars
9
- def populate_items_from_api(api)
10
- all_items = api.items
11
- all_items.each do |item_json|
12
- type, _dimension = item_json["type"].split(":")
13
- if type == "Group"
14
- if item_json["groupType"]
15
- type, _dimension = item_json["groupType"].split(":")
7
+ class << self
8
+ def populate_items_from_api(api)
9
+ all_items = api.items
10
+
11
+ gfh = org.openhab.core.internal.items.GroupFunctionHelper.new
12
+
13
+ all_items.each do |item_json|
14
+ type, _dimension = item_json["type"].split(":")
15
+ if type == "Group"
16
+ if item_json["groupType"]
17
+ type, _dimension = item_json["groupType"].split(":")
18
+ klass = ::OpenHAB::DSL::Items.const_get(:"#{type}Item")
19
+ base_item = klass.new(item_json["name"])
20
+ end
21
+ if item_json["function"]
22
+ dto = org.openhab.core.items.dto.GroupFunctionDTO.new
23
+ dto.name = item_json.dig("function", "name")
24
+ dto.params = item_json.dig("function", "params")
25
+ function = gfh.create_group_function(dto, base_item)
26
+ end
27
+ item = GroupItem.new(item_json["name"], base_item, function)
28
+ else
16
29
  klass = ::OpenHAB::DSL::Items.const_get(:"#{type}Item")
17
- base_item = klass.new(item_json["name"])
30
+ item = klass.new(item_json["name"])
18
31
  end
19
- # TODO: create group function
20
- item = GroupItem.new(item_json["name"], base_item)
21
- else
22
- klass = ::OpenHAB::DSL::Items.const_get(:"#{type}Item")
23
- item = klass.new(item_json["name"])
24
- end
25
32
 
26
- item.label = item_json["label"]
27
- item_json["tags"].each do |tag|
28
- item.add_tag(tag)
33
+ item.label = item_json["label"]
34
+ item_json["tags"].each do |tag|
35
+ item.add_tag(tag)
36
+ end
37
+ item_json["metadata"]&.each do |key, config|
38
+ item.meta[key] = config["value"], config["config"]
39
+ end
40
+
41
+ $ir.add(item)
29
42
  end
30
- item_json["metadata"]&.each do |key, config|
31
- item.meta[key] = config["value"], config["config"]
43
+ all_items.each do |item_json| # rubocop:disable Style/CombinableLoops
44
+ item_json["groupNames"].each do |group_name|
45
+ next unless (group = $ir.get(group_name))
46
+
47
+ group.add_member($ir.get(item_json["name"]))
48
+ end
32
49
  end
50
+ end
51
+ end
33
52
 
34
- $ir.add(item)
53
+ def autoupdate_all_items
54
+ @autoupdated_items ||= {}
55
+ $ir.for_each do |_provider, item|
56
+ @autoupdated_items[item] = item.meta.delete("autoupdate") if item.meta.key?("autoupdate")
35
57
  end
36
- all_items.each do |item_json| # rubocop:disable Style/CombinableLoops
37
- item_json["groupNames"].each do |group_name|
38
- next unless (group = $ir.get(group_name))
58
+ end
39
59
 
40
- group.add_member($ir.get(item_json["name"]))
41
- end
60
+ private
61
+
62
+ def restore_autoupdate_items
63
+ return unless instance_variable_defined?(:@autoupdated_items)
64
+
65
+ @autoupdated_items.each do |(item, meta)|
66
+ item.meta["autoupdate"] = meta
67
+ end
68
+ end
69
+
70
+ ::RSpec.configure do |config|
71
+ config.include(self)
72
+ config.after do
73
+ restore_autoupdate_items
42
74
  end
43
75
  end
44
- # rubocop:enable Style/GlobalVars
45
76
  end
46
77
  end
47
78
  end
79
+ # rubocop:enable Style/GlobalVars
@@ -1,9 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
+ org.openhab.core.items.GenericItem.field_reader :eventPublisher
5
+
6
+ # rubocop:disable Style/GlobalVars
4
7
  config.before(:each) do
5
- $ir.for_each do |_provider, item| # rubocop:disable Style/GlobalVars
8
+ ep = $ir.eventPublisher
9
+
10
+ # stash event publishers to avoid triggering any rules
11
+ $ir.for_each do |_provider, item|
12
+ item.event_publisher = nil
13
+ end
14
+
15
+ $ir.for_each do |_provider, item| # rubocop:disable Style/CombinableLoops
6
16
  item.state = NULL # don't use update, to avoid triggering any rules
7
17
  end
18
+ ensure
19
+ $ir.for_each do |_provider, item|
20
+ item.event_publisher = ep
21
+ end
8
22
  end
23
+ # rubocop:enable Style/GlobalVars
9
24
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OpenHAB
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.6"
6
6
  end
7
7
  end
@@ -5,12 +5,11 @@ module RSpec
5
5
  module Wait
6
6
  def wait_for_rules
7
7
  loop do
8
- break if java.lang.Thread.all_stack_traces.keys.all? do |t|
9
- !t.name.match?(/^OH-rule-/) ||
10
- [java.lang.Thread::State::WAITING, java.lang.Thread::State::TIMED_WAITING].include?(t.state)
11
- end
12
-
13
8
  sleep(0.1)
9
+ break if java.lang.Thread.all_stack_traces.keys.all? do |t|
10
+ !t.name.match?(/^OH-rule-/) ||
11
+ [java.lang.Thread::State::WAITING, java.lang.Thread::State::TIMED_WAITING].include?(t.state)
12
+ end
14
13
  end
15
14
  end
16
15
  end
@@ -59,6 +59,7 @@ end
59
59
  require "openhab/log/logger"
60
60
  require "rspec/openhab/core/logger"
61
61
  require "openhab/dsl/imports"
62
+ OpenHAB::DSL::Imports.api = api
62
63
  OpenHAB::DSL::Imports.import_presets
63
64
 
64
65
  require "openhab"
@@ -78,10 +79,16 @@ require "rspec/openhab/items"
78
79
 
79
80
  RSpec::OpenHAB::Items.populate_items_from_api(api)
80
81
 
82
+ # make bundler/inline _not_ destroy the already existing load path
83
+ module Bundler
84
+ module SharedHelpers
85
+ def clean_load_path; end
86
+ end
87
+ end
88
+
81
89
  # load rules files
82
90
  OPENHAB_AUTOMATION_PATH = "#{org.openhab.core.OpenHAB.config_folder}/automation/jsr223/ruby/personal"
83
91
 
84
- # set up some environment the rules files expect
85
92
  Dir["#{OPENHAB_AUTOMATION_PATH}/*.rb"].each do |f|
86
93
  load f
87
94
  rescue Exception => e # rubocop:disable Lint/RescueException
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: 0.0.3
4
+ version: 0.0.6
5
5
  platform: java
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-30 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.42'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.11'
75
+ name: rspec-core
76
+ prerelease: false
77
+ type: :runtime
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.11'
69
83
  - !ruby/object:Gem::Dependency
70
84
  requirement: !ruby/object:Gem::Requirement
71
85
  requirements:
@@ -158,7 +172,6 @@ extra_rdoc_files: []
158
172
  files:
159
173
  - lib/rspec-openhab-scripting.rb
160
174
  - lib/rspec-openhab-scripting_jars.rb
161
- - lib/rspec/bundler/inline.rb
162
175
  - lib/rspec/openhab/api.rb
163
176
  - lib/rspec/openhab/core/cron_scheduler.rb
164
177
  - lib/rspec/openhab/core/load_path.rb
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bundler
4
- class DummyDsl
5
- def source(*); end
6
- end
7
- end
8
-
9
- def gemfile(*, &block)
10
- # needs to be a no-op, since we're already running in the context of bundler
11
- Bundler::DummyDsl.new.instance_eval(&block)
12
- end