rspec-openhab-scripting 0.0.4-java → 0.0.5-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: 29dc9d000dc362c190a0bc94a93157b62d82ca884ab9294ebae673c3e83606ad
4
- data.tar.gz: c60c6ee40ba4cc183a5e73bb97140738e3af52b10661bb4aa86f8d519f385903
3
+ metadata.gz: 66ee3ecec1c902dcf931cb3e51a7cacdb4df1e3b0798fa973aabf0147787c72f
4
+ data.tar.gz: da69d9608f4242545a4e01b0ae22e0133b6a1868b518ad1a95dd5d67bcd94785
5
5
  SHA512:
6
- metadata.gz: d5d10546a4617918135c998db4e26d51a03519ac0ab48e41367c4da6064b2e771986af4aad1e5f2dcc757e152fa3a7791494517f58bd9de76faba22a6035395c
7
- data.tar.gz: d7eafd0592fe84c0dfd8753a783cf9639eeb28cd803a80237a15ec70e49f23afe00934ff65a63691b8c50d1ad07b2aff1f3085ea890f4b8f042436dbb50f1924
6
+ metadata.gz: 5160b3281ea2f567fd040f49cb0acf5b6c1b56ae050711ae049868ec645dc8a38799434c8c51c3c2a2fb806da98b5261b9c1e54119d3fd2c0d2888680cc2b762
7
+ data.tar.gz: c0ca81a870b864c45ba50d281fa9584421b36d64c48b86048765b32d6d0ab5aa64c92a49a4ddfcc6fa21d9b085b7e5a5baa63c95fcde295b090dd5967996d823
@@ -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
@@ -138,6 +161,9 @@ module OpenHAB
138
161
  ir.managed_provider = mip = org.openhab.core.items.ManagedItemProvider.new(ss, nil)
139
162
  ir.add_provider(mip)
140
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)
141
167
  tr = org.openhab.core.thing.internal.ThingRegistryImpl.new
142
168
  mtr = org.openhab.core.automation.internal.type.ModuleTypeRegistryImpl.new
143
169
  rr = org.openhab.core.automation.internal.RuleRegistryImpl.new
@@ -206,7 +232,6 @@ module OpenHAB
206
232
  em.add_event_factory(ief)
207
233
 
208
234
  # set up the rules engine part 2
209
- bc = BundleContext.new(em)
210
235
  k = org.openhab.core.automation.internal.module.factory.CoreModuleHandlerFactory
211
236
  # depending on OH version, this class is set up differently
212
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.4"
5
+ VERSION = "0.0.5"
6
6
  end
7
7
  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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: java
6
6
  authors:
7
7
  - Cody Cutrer
@@ -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: