rspec-openhab-scripting 0.0.17-java → 0.0.18-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: a5541ba712d1a3fef9112f736b456309acb491aa0cdf075098abe04712a59940
4
- data.tar.gz: d75f2b90687529a2bbc63f6d456f639a23360e7636d8ea7c36ed4d2113c7b6d7
3
+ metadata.gz: 6ea44768dd3bccdfc7276944f329030e21182d161126e433126970f096543f46
4
+ data.tar.gz: 81be4550cd3ab271f43e15616959709bb9e5d1cf14a999dd8565e0b148d3a8d7
5
5
  SHA512:
6
- metadata.gz: f576f81ea3fea76dbb173e8aa7ad3d1439f24e518bcd8574597266fe4bc457e325b6ec2f214e9c15a9c6b4c681d7350f7845fe055962f3b1b68214c0433b6b4d
7
- data.tar.gz: 394f5a733ed2ddd02bf109f08fb80bbc35f8db5cebb340231a4b9bb17064ba17598ea1dbd90de18e16ff7d6ef52c387db001da6f6a3ae140c44928e71cef48c5
6
+ metadata.gz: 4d70a68375f21fab304d05b620125cf79b5767f3522d5e22a0608301b56e4ed3b2f6baba7942bdfcdb9ffed742378452720b79b7bfc5d7523544087a0bcb15bc
7
+ data.tar.gz: d2ce66901858dc37eb7c76b5f37f82da6147f1b471b8fc70097037099d677eb01c6e4e25d77e12105847e28156a919e059d5420271f9ce5cfcb0c9af933b4383
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Naming have to follow java interface names
4
+ module RSpec
5
+ module OpenHAB
6
+ module Core
7
+ module Mocks
8
+ class ThingHandler
9
+ include org.openhab.core.thing.binding.BridgeHandler
10
+
11
+ attr_reader :thing, :callback
12
+
13
+ def initialize(thing = nil)
14
+ # have to handle the interface method
15
+ if thing.nil?
16
+ status_info = org.openhab.core.thing.binding.builder.ThingStatusInfoBuilder
17
+ .create(org.openhab.core.thing.ThingStatus::ONLINE).build
18
+ @callback.status_updated(self.thing, status_info)
19
+ return
20
+ end
21
+
22
+ # ruby initializer here
23
+ @thing = thing
24
+ end
25
+
26
+ def handle_command(channel, command); end
27
+
28
+ def set_callback(callback)
29
+ @callback = callback
30
+ end
31
+
32
+ def child_handler_initialized(child_handler, child_thing); end
33
+ end
34
+
35
+ class ThingHandlerFactory < org.openhab.core.thing.binding.BaseThingHandlerFactory
36
+ def supportsThingType(_type)
37
+ true
38
+ end
39
+
40
+ def createHandler(thing)
41
+ ThingHandler.new(thing)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ # rubocop:enable Naming
@@ -71,7 +71,17 @@ module OpenHAB
71
71
  class BundleResolver
72
72
  include org.openhab.core.util.BundleResolver
73
73
 
74
- def resolve_bundle(klass); end
74
+ def initialize
75
+ @bundles = {}
76
+ end
77
+
78
+ def register(klass, bundle)
79
+ @bundles[klass] = bundle
80
+ end
81
+
82
+ def resolve_bundle(klass)
83
+ @bundles[klass]
84
+ end
75
85
  end
76
86
 
77
87
  # don't depend on org.openhab.core.test
@@ -104,13 +114,15 @@ module OpenHAB
104
114
  INSTALLED = 2
105
115
 
106
116
  def initialize(*jar_args)
117
+ return if jar_args.empty?
118
+
107
119
  file = Jars.find_jar(*jar_args)
108
120
  @jar = java.util.jar.JarFile.new(file)
109
121
  @symbolic_name = jar_args[1]
110
122
  @version = org.osgi.framework.Version.new(jar_args[2].tr("-", "."))
111
123
  end
112
124
 
113
- attr_reader :symbolic_name, :version
125
+ attr_accessor :symbolic_name, :version
114
126
 
115
127
  def state
116
128
  INSTALLED
@@ -313,6 +325,7 @@ module OpenHAB
313
325
  bc = BundleContext.new(em)
314
326
  cc = ComponentContext.new(bc)
315
327
  cc.properties["measurementSystem"] = api.measurement_system if api
328
+ resolver = BundleResolver.new
316
329
 
317
330
  # the registries!
318
331
  ss = VolatileStorageService.new
@@ -346,6 +359,7 @@ module OpenHAB
346
359
  ttr = org.openhab.core.thing.type.ThingTypeRegistry.new(ctr)
347
360
  OpenHAB::Core::OSGI.register_service(ttr)
348
361
  ttr.add_thing_type_provider(RSpec::OpenHAB::Core::Mocks::ThingTypeProvider.instance)
362
+ cgtr = org.openhab.core.thing.type.ChannelGroupTypeRegistry.new
349
363
 
350
364
  safe_emf = org.openhab.core.model.core.internal.SafeEMFImpl.new
351
365
  model_repository = org.openhab.core.model.core.internal.ModelRepositoryImpl.new(safe_emf)
@@ -410,18 +424,18 @@ module OpenHAB
410
424
 
411
425
  # link up event bus infrastructure
412
426
  iu = org.openhab.core.internal.items.ItemUpdater.new(ir)
413
- ief = org.openhab.core.items.events.ItemEventFactory.new
414
427
 
415
428
  sc = SafeCaller.new
416
429
  aum = org.openhab.core.thing.internal.AutoUpdateManager.new(
417
430
  { "enabled" => true, "sendOptimisticUpdates" => true }, ctr, ep, iclr, mr, tr
418
431
  )
419
- spf = org.openhab.core.thing.internal.profiles.SystemProfileFactory.new(ctr, nil, BundleResolver.new)
432
+ spf = org.openhab.core.thing.internal.profiles.SystemProfileFactory.new(ctr, nil, resolver)
420
433
  cm = org.openhab.core.thing.internal.CommunicationManager.new(aum, ctr, spf, iclr, ir, isc, ep, sc, tr)
421
434
 
422
435
  em.add_event_subscriber(iu)
423
436
  em.add_event_subscriber(cm)
424
- em.add_event_factory(ief)
437
+ em.add_event_factory(org.openhab.core.items.events.ItemEventFactory.new)
438
+ em.add_event_factory(org.openhab.core.thing.events.ThingEventFactory.new)
425
439
 
426
440
  # set up the rules engine part 2
427
441
  k = org.openhab.core.automation.internal.module.factory.CoreModuleHandlerFactory
@@ -464,6 +478,31 @@ module OpenHAB
464
478
  pm = org.openhab.core.persistence.internal.PersistenceManagerImpl.new(nil, ir, sc, rs)
465
479
  pm.add_persistence_service(ps)
466
480
  pm.on_ready_marker_added(nil)
481
+
482
+ # set up ThingManager so we can trigger channels
483
+ localizer = org.openhab.core.thing.i18n.ThingStatusInfoI18nLocalizationService.new
484
+ tm = org.openhab.core.thing.internal.ThingManagerImpl.new(
485
+ resolver,
486
+ cgtr,
487
+ ctr,
488
+ cm,
489
+ nil,
490
+ nil,
491
+ ep,
492
+ iclr,
493
+ rs,
494
+ sc,
495
+ ss,
496
+ tr,
497
+ localizer,
498
+ ttr
499
+ )
500
+ thf = RSpec::OpenHAB::Core::Mocks::ThingHandlerFactory.new
501
+ this_bundle = Bundle.new
502
+ this_bundle.symbolic_name = "org.openhab.automation.jrubyscripting.rspec"
503
+ resolver.register(thf.class.java_class, this_bundle)
504
+ tm.add_thing_handler_factory(thf)
505
+ tm.on_ready_marker_added(org.openhab.core.service.ReadyMarker.new(nil, this_bundle.symbolic_name))
467
506
  end
468
507
  end
469
508
  end
@@ -24,6 +24,13 @@ module RSpec
24
24
  @rules.fetch(rule_name).execute(nil, { "event" => event })
25
25
  end
26
26
 
27
+ def trigger_channel(channel, event)
28
+ channel = org.openhab.core.thing.ChannelUID.new(channel) if channel.is_a?(String)
29
+ channel = channel.uid if channel.is_a?(org.openhab.core.thing.Channel)
30
+ thing = channel.thing
31
+ thing.handler.callback.channel_triggered(nil, channel, event)
32
+ end
33
+
27
34
  private
28
35
 
29
36
  def restore_autoupdate_items
@@ -3,18 +3,6 @@
3
3
  module RSpec
4
4
  module OpenHAB
5
5
  module Items
6
- class ThingHandler
7
- include org.openhab.core.thing.binding.ThingHandler
8
-
9
- attr_reader :thing
10
-
11
- def initialize(thing)
12
- @thing = thing
13
- end
14
-
15
- def handle_command(channel, command); end
16
- end
17
-
18
6
  class << self
19
7
  def populate_items_from_api(api)
20
8
  all_items = api.items
@@ -103,14 +91,7 @@ module RSpec
103
91
  end
104
92
  end
105
93
 
106
- thing = builder.build
107
- # pretend everything is online so that AutoUpdateManager won't reject updates
108
- # to items linked to offline channels
109
- thing.status_info = org.openhab.core.thing.binding.builder.ThingStatusInfoBuilder
110
- .create(org.openhab.core.thing.ThingStatus::ONLINE).build
111
- handler = ThingHandler.new(thing)
112
- thing.handler = handler
113
- $things.add(thing)
94
+ $things.add(builder.build)
114
95
  end
115
96
  end
116
97
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OpenHAB
5
- VERSION = "0.0.17"
5
+ VERSION = "0.0.18"
6
6
  end
7
7
  end
@@ -70,6 +70,7 @@ OpenHAB::Log.logger("org.openhab.automation.jruby.logger").level = :warn
70
70
  require "rspec/openhab/core/mocks/channel_type_provider"
71
71
  require "rspec/openhab/core/mocks/item_channel_link_provider"
72
72
  require "rspec/openhab/core/mocks/persistence_service"
73
+ require "rspec/openhab/core/mocks/thing_handler"
73
74
  require "rspec/openhab/core/mocks/thing_type_provider"
74
75
  require "openhab/dsl/imports"
75
76
  OpenHAB::DSL::Imports.api = api
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.17
4
+ version: 0.0.18
5
5
  platform: java
6
6
  authors:
7
7
  - Cody Cutrer
@@ -195,6 +195,7 @@ files:
195
195
  - lib/rspec/openhab/core/mocks/channel_type_provider.rb
196
196
  - lib/rspec/openhab/core/mocks/item_channel_link_provider.rb
197
197
  - lib/rspec/openhab/core/mocks/persistence_service.rb
198
+ - lib/rspec/openhab/core/mocks/thing_handler.rb
198
199
  - lib/rspec/openhab/core/mocks/thing_type_provider.rb
199
200
  - lib/rspec/openhab/core/openhab_setup.rb
200
201
  - lib/rspec/openhab/core/osgi.rb