rspec-openhab-scripting 0.0.2-java → 0.0.3-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: bb06cd0d4f2eb7710a678cf6b080ae636d81ef9faa4012a755ed8b73117a158a
4
- data.tar.gz: 3ed1a44e4cc9802054e6697807e75adafa75e6069647f917b809e20cbdb2e92a
3
+ metadata.gz: 2a757dc4165cbe3769b13d7a24b444d6d3d66fa7e6fdae117fa76bd87c230c03
4
+ data.tar.gz: 0243f89dc45dad378693e7a73b3b842aa11563f18a464936a6b42971f4f76f07
5
5
  SHA512:
6
- metadata.gz: 4ee95923dc2c84ca4253112fcb0d6b351cb14d3a1879dcbcdd5e67dfcf095fdfdd0ab8f3c9d4b617fe2db13393a727f2687194531436c9572857066fcc57a62d
7
- data.tar.gz: 05245aa976b20f462002b87c9451b16c9aa1609f145981f259ee1637270e82a9ca295a55fcb15c6bc66a295664e313e0ffb5b280f193e624fc411ccf3138be2d
6
+ metadata.gz: 6b6461bf0bfc7120efef2611e2d6ae18d09c1da6a33a9d9e1825ede880329475d9d0ccbfd445ebcc427eb265a68e785fa98c157e0676c62a772a814af586e076
7
+ data.tar.gz: 600900bcceda586ea77aa16f6fd925b6a1960615ce64a6e0e3054250c2fb444c5cddfe73223341397f6f88d0eba4b6a2b3453b2f896d7572c7fed66c3c0251ee
@@ -22,7 +22,7 @@ module OpenHAB
22
22
  end
23
23
 
24
24
  def items
25
- @faraday.get("items").body
25
+ @faraday.get("items", metadata: ".*").body
26
26
  end
27
27
 
28
28
  def item(name)
@@ -15,10 +15,37 @@ module OpenHAB
15
15
  levels.each { |level| const_set(level, ch.qos.logback.classic.Level.const_get(level)) }
16
16
 
17
17
  extend Forwardable
18
- delegate %i[level level=] => :@sl4fj_logger
18
+ delegate %i[level] => :@sl4fj_logger
19
+
20
+ def level=(level)
21
+ if level.is_a?(String) || level.is_a?(Symbol)
22
+ level = ch.qos.logback.classic.Level.const_get(level.to_s.upcase, false)
23
+ end
24
+ @sl4fj_logger.level = level
25
+ end
26
+ end
27
+ end
28
+
29
+ module Log
30
+ class << self
31
+ def root
32
+ logger(org.slf4j.Logger::ROOT_LOGGER_NAME)
33
+ end
34
+
35
+ def events
36
+ logger("openhab.event")
37
+ end
38
+
39
+ def logger(object)
40
+ logger_name = case object
41
+ when String then object
42
+ else logger_name(object)
43
+ end
44
+ @loggers[logger_name] ||= Core::Logger.new(logger_name)
45
+ end
19
46
  end
20
47
  end
21
48
  end
22
49
 
23
- root_logger = org.slf4j.LoggerFactory.get_logger(org.slf4j.Logger::ROOT_LOGGER_NAME)
24
- root_logger.level = OpenHAB::Core::Logger::INFO
50
+ OpenHAB::Log.root.level = :info
51
+ OpenHAB::Log.events.level = :warn
@@ -129,10 +129,12 @@ module OpenHAB
129
129
  ep = org.openhab.core.internal.events.OSGiEventPublisher.new(ea)
130
130
 
131
131
  # the registries!
132
+ ss = VolatileStorageService.new
132
133
  mr = org.openhab.core.internal.items.MetadataRegistryImpl.new
133
134
  OpenHAB::Core::OSGI.register_service("org.openhab.core.items.MetadataRegistry", mr)
135
+ mr.managed_provider = mmp = org.openhab.core.internal.items.ManagedMetadataProviderImpl.new(ss)
136
+ mr.add_provider(mmp)
134
137
  ir = org.openhab.core.internal.items.ItemRegistryImpl.new(mr)
135
- ss = VolatileStorageService.new
136
138
  ir.managed_provider = mip = org.openhab.core.items.ManagedItemProvider.new(ss, nil)
137
139
  ir.add_provider(mip)
138
140
  tr = org.openhab.core.thing.internal.ThingRegistryImpl.new
@@ -221,7 +223,12 @@ module OpenHAB
221
223
  re.add_module_handler_factory(cmhf)
222
224
  re.add_module_handler_factory(scmhf)
223
225
  re.add_module_handler_factory(spmhf)
224
- re.onReadyMarkerAdded(nil)
226
+ re.on_ready_marker_added(nil)
227
+
228
+ # enable event logging
229
+ el = org.openhab.core.io.monitor.internal.EventLogger.new(rs)
230
+ em.add_event_subscriber(el)
231
+ el.on_ready_marker_added(nil)
225
232
  end
226
233
  end
227
234
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module OpenHAB
5
+ 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(":")
16
+ klass = ::OpenHAB::DSL::Items.const_get(:"#{type}Item")
17
+ base_item = klass.new(item_json["name"])
18
+ 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
+
26
+ item.label = item_json["label"]
27
+ item_json["tags"].each do |tag|
28
+ item.add_tag(tag)
29
+ end
30
+ item_json["metadata"]&.each do |key, config|
31
+ item.meta[key] = config["value"], config["config"]
32
+ end
33
+
34
+ $ir.add(item)
35
+ 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))
39
+
40
+ group.add_member($ir.get(item_json["name"]))
41
+ end
42
+ end
43
+ end
44
+ # rubocop:enable Style/GlobalVars
45
+ end
46
+ end
47
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OpenHAB
5
- VERSION = "0.0.2"
5
+ VERSION = "0.0.3"
6
6
  end
7
7
  end
@@ -38,6 +38,7 @@ maven_require do
38
38
  require "jar org.openhab.core.bundles, org.openhab.core.automation, #{openhab_version}"
39
39
  require "jar org.openhab.core.bundles, org.openhab.core.automation.module.script, #{openhab_version}"
40
40
  require "jar org.openhab.core.bundles, org.openhab.core.automation.module.script.rulesupport, #{openhab_version}"
41
+ require "jar org.openhab.core.bundles, org.openhab.core.io.monitor, #{openhab_version}"
41
42
  require "jar org.openhab.core.bundles, org.openhab.core.model.core, #{openhab_version}"
42
43
  require "jar org.openhab.core.bundles, org.openhab.core.model.script, #{openhab_version}"
43
44
  require "jar org.openhab.core.bundles, org.openhab.core.semantics, #{openhab_version}"
@@ -68,46 +69,14 @@ require "rspec/openhab/core/cron_scheduler"
68
69
  OpenHAB::DSL.send(:remove_const, :Timer)
69
70
  require_relative "rspec/openhab/dsl/timers/timer"
70
71
 
71
- # rubocop:disable Style/GlobalVars
72
-
73
72
  # RSpec additions
74
73
  require "rspec/openhab/dsl/rules/rspec"
75
74
  require "rspec/openhab/state"
76
75
  require "rspec/openhab/trigger"
77
76
  require "rspec/openhab/wait"
77
+ require "rspec/openhab/items"
78
78
 
79
- # populate item registry
80
- all_items = api.items
81
- all_items.each do |item_json|
82
- type, _dimension = item_json["type"].split(":")
83
- if type == "Group"
84
- if item_json["groupType"]
85
- type, _dimension = item_json["groupType"].split(":")
86
- klass = OpenHAB::DSL::Items.const_get(:"#{type}Item")
87
- base_item = klass.new(item_json["name"])
88
- end
89
- # TODO: create group function
90
- item = GroupItem.new(item_json["name"], base_item)
91
- else
92
- klass = OpenHAB::DSL::Items.const_get(:"#{type}Item")
93
- item = klass.new(item_json["name"])
94
- end
95
-
96
- item.label = item_json["label"]
97
- item_json["tags"].each do |tag|
98
- item.add_tag(tag)
99
- end
100
- $ir.add(item)
101
- end
102
- all_items.each do |item_json| # rubocop:disable Style/CombinableLoops
103
- item_json["groupNames"].each do |group_name|
104
- next unless (group = $ir.get(group_name))
105
-
106
- group.add_member($ir.get(item_json["name"]))
107
- end
108
- end
109
-
110
- # rubocop:enable Style/GlobalVars
79
+ RSpec::OpenHAB::Items.populate_items_from_api(api)
111
80
 
112
81
  # load rules files
113
82
  OPENHAB_AUTOMATION_PATH = "#{org.openhab.core.OpenHAB.config_folder}/automation/jsr223/ruby/personal"
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.2
4
+ version: 0.0.3
5
5
  platform: java
6
6
  authors:
7
7
  - Cody Cutrer
@@ -169,6 +169,7 @@ files:
169
169
  - lib/rspec/openhab/dsl/imports.rb
170
170
  - lib/rspec/openhab/dsl/rules/rspec.rb
171
171
  - lib/rspec/openhab/dsl/timers/timer.rb
172
+ - lib/rspec/openhab/items.rb
172
173
  - lib/rspec/openhab/state.rb
173
174
  - lib/rspec/openhab/trigger.rb
174
175
  - lib/rspec/openhab/version.rb