rspec-openhab-scripting 0.0.7-java → 0.0.10-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec/openhab/dsl/imports.rb +18 -0
- data/lib/rspec/openhab/items.rb +10 -9
- data/lib/rspec/openhab/timer.rb +2 -0
- data/lib/rspec/openhab/version.rb +1 -1
- data/lib/rspec/openhab/wait.rb +66 -5
- data/lib/rspec-openhab-scripting.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec06e2cfb8832f84f5bd953e22904dbf99ec22a97e5ba0b900ee0e09a163a566
|
4
|
+
data.tar.gz: 959d078c55a2147e8b1899a8efabc6e8d8065fa9c869cda1c1d5ff057784de3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d806b85fd33ce2c42b09f5442bd7dc752327a21c1aae8df5fa57b615dd4935a96c62274ffab8d5dcad9bc94fe034c3073d0af20221cd59e647e00568ae7acc64
|
7
|
+
data.tar.gz: a2565829aa4ddd62cdd1e3ac34e23f55ec9794dcbdeac806bb7175c546f2dcca483cddd72116b1f7726d249c983b7407939de8906e0ec442320d2f2b7b515947
|
@@ -157,6 +157,8 @@ module OpenHAB
|
|
157
157
|
OpenHAB::Core::OSGI.register_service("org.openhab.core.items.MetadataRegistry", mr)
|
158
158
|
mr.managed_provider = mmp = org.openhab.core.internal.items.ManagedMetadataProviderImpl.new(ss)
|
159
159
|
mr.add_provider(mmp)
|
160
|
+
gmp = org.openhab.core.model.item.internal.GenericMetadataProvider.new
|
161
|
+
mr.add_provider(gmp)
|
160
162
|
ir = org.openhab.core.internal.items.ItemRegistryImpl.new(mr)
|
161
163
|
ir.managed_provider = mip = org.openhab.core.items.ManagedItemProvider.new(ss, nil)
|
162
164
|
ir.add_provider(mip)
|
@@ -171,6 +173,22 @@ module OpenHAB
|
|
171
173
|
rr.managed_provider = mrp = org.openhab.core.automation.ManagedRuleProvider.new(ss)
|
172
174
|
rr.add_provider(mrp)
|
173
175
|
iclr = org.openhab.core.thing.link.ItemChannelLinkRegistry.new(tr, ir)
|
176
|
+
ctr = org.openhab.core.thing.type.ChannelTypeRegistry.new
|
177
|
+
ttr = org.openhab.core.thing.type.ThingTypeRegistry.new(ctr)
|
178
|
+
|
179
|
+
safe_emf = org.openhab.core.model.core.internal.SafeEMFImpl.new
|
180
|
+
model_repository = org.openhab.core.model.core.internal.ModelRepositoryImpl.new(safe_emf)
|
181
|
+
|
182
|
+
# set up state descriptions
|
183
|
+
sds = org.openhab.core.internal.service.StateDescriptionServiceImpl.new
|
184
|
+
gip = org.openhab.core.model.item.internal.GenericItemProvider.new(model_repository, gmp, {})
|
185
|
+
sds.add_state_description_fragment_provider(gip)
|
186
|
+
msdfp = org.openhab.core.internal.items.MetadataStateDescriptionFragmentProvider.new(mr, {})
|
187
|
+
sds.add_state_description_fragment_provider(msdfp)
|
188
|
+
csdp = org.openhab.core.thing.internal.ChannelStateDescriptionProvider.new(iclr, ttr, tr)
|
189
|
+
csdp.activate(org.osgi.framework.Constants::SERVICE_RANKING => java.lang.Integer.new(-1))
|
190
|
+
sds.add_state_description_fragment_provider(csdp)
|
191
|
+
ir.state_description_service = sds
|
174
192
|
|
175
193
|
# set up stuff accessed from rules
|
176
194
|
preset = org.openhab.core.automation.module.script.internal.defaultscope
|
data/lib/rspec/openhab/items.rb
CHANGED
@@ -8,25 +8,24 @@ module RSpec
|
|
8
8
|
all_items = api.items
|
9
9
|
|
10
10
|
gfh = org.openhab.core.internal.items.GroupFunctionHelper.new
|
11
|
+
item_factory = org.openhab.core.library.CoreItemFactory.new
|
11
12
|
|
12
13
|
all_items.each do |item_json|
|
13
|
-
|
14
|
+
full_type = item_json["type"]
|
15
|
+
name = item_json["name"]
|
16
|
+
|
17
|
+
type, _dimension = full_type.split(":")
|
14
18
|
if type == "Group"
|
15
|
-
if item_json["groupType"]
|
16
|
-
type, _dimension = item_json["groupType"].split(":")
|
17
|
-
klass = ::OpenHAB::DSL::Items.const_get(:"#{type}Item")
|
18
|
-
base_item = klass.new(item_json["name"])
|
19
|
-
end
|
19
|
+
base_item = item_factory.create_item(item_json["groupType"], name) if item_json["groupType"]
|
20
20
|
if item_json["function"]
|
21
21
|
dto = org.openhab.core.items.dto.GroupFunctionDTO.new
|
22
22
|
dto.name = item_json.dig("function", "name")
|
23
23
|
dto.params = item_json.dig("function", "params")
|
24
24
|
function = gfh.create_group_function(dto, base_item)
|
25
25
|
end
|
26
|
-
item = GroupItem.new(
|
26
|
+
item = GroupItem.new(name, base_item, function)
|
27
27
|
else
|
28
|
-
|
29
|
-
item = klass.new(item_json["name"])
|
28
|
+
item = item_factory.create_item(full_type, name)
|
30
29
|
end
|
31
30
|
|
32
31
|
item.label = item_json["label"]
|
@@ -36,6 +35,8 @@ module RSpec
|
|
36
35
|
item_json["metadata"]&.each do |key, config|
|
37
36
|
item.meta[key] = config["value"], config["config"]
|
38
37
|
end
|
38
|
+
item.meta["stateDescription"] = item_json["stateDescription"] if item_json["stateDescription"]
|
39
|
+
item.category = item_json["category"] if item_json["category"]
|
39
40
|
|
40
41
|
$ir.add(item)
|
41
42
|
end
|
data/lib/rspec/openhab/timer.rb
CHANGED
data/lib/rspec/openhab/wait.rb
CHANGED
@@ -4,14 +4,75 @@ module RSpec
|
|
4
4
|
module OpenHAB
|
5
5
|
module Wait
|
6
6
|
def wait_for_rules
|
7
|
+
wait_for_background_tasks(timers: false)
|
8
|
+
end
|
9
|
+
|
10
|
+
def wait_for_timers
|
11
|
+
wait_for_background_tasks(rules: false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def wait_for_background_tasks(rules: true, timers: true)
|
7
15
|
loop do
|
8
|
-
sleep
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
16
|
+
sleep 0.1
|
17
|
+
next if java.lang.Thread.all_stack_traces.any? do |(t, stack)|
|
18
|
+
# this is just an estimate. I see 9 when it's parked waiting
|
19
|
+
# for an event, but once it hits ruby it gets real big real quick
|
20
|
+
min_frames = 15
|
21
|
+
|
22
|
+
case t.name
|
23
|
+
when /^OH-scheduler-/
|
24
|
+
# timer thread; born and die for each timer
|
25
|
+
if thread_running?(t) || stack.length > min_frames
|
26
|
+
logger.debug "thread #{t.name} is running (#{stack.length})"
|
27
|
+
stack.each do |frame|
|
28
|
+
logger.trace " #{frame}"
|
29
|
+
end
|
30
|
+
next timers
|
31
|
+
end
|
32
|
+
when /^OH-rule-/
|
33
|
+
|
34
|
+
if thread_running?(t) || stack.length > min_frames
|
35
|
+
logger.debug "thread #{t.name} is running (#{stack.length})"
|
36
|
+
stack.each do |frame|
|
37
|
+
logger.trace " #{frame}"
|
38
|
+
end
|
39
|
+
|
40
|
+
next rules
|
41
|
+
end
|
42
|
+
when /^OH-(?:eventwatcher|eventexecutor)-/
|
43
|
+
# an event is making its way through the system
|
44
|
+
if thread_running?(t)
|
45
|
+
logger.debug "thread #{t.name} is running"
|
46
|
+
next rules
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# no need to retry if there were no timers
|
52
|
+
break unless timers && wait_for_next_timer
|
13
53
|
end
|
14
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def thread_running?(thread)
|
59
|
+
![java.lang.Thread::State::WAITING,
|
60
|
+
java.lang.Thread::State::TIMED_WAITING].include?(thread.state)
|
61
|
+
end
|
62
|
+
|
63
|
+
def wait_for_next_timer
|
64
|
+
latest = ::OpenHAB::DSL::Timers.timer_manager.instance_variable_get(:@timers).min_by(&:execution_time)
|
65
|
+
return false unless latest
|
66
|
+
|
67
|
+
delta = (latest.execution_time.to_instant.to_epoch_milli - java.time.Instant.now.to_epoch_milli) / 1000.0
|
68
|
+
# in the past? it's probably executing
|
69
|
+
return true if delta.negative?
|
70
|
+
|
71
|
+
logger.info("Waiting #{delta}s for next timer") if delta > 5
|
72
|
+
|
73
|
+
sleep(delta)
|
74
|
+
true
|
75
|
+
end
|
15
76
|
end
|
16
77
|
end
|
17
78
|
end
|
@@ -40,6 +40,7 @@ maven_require do
|
|
40
40
|
require "jar org.openhab.core.bundles, org.openhab.core.config.core, #{openhab_version}"
|
41
41
|
require "jar org.openhab.core.bundles, org.openhab.core.io.monitor, #{openhab_version}"
|
42
42
|
require "jar org.openhab.core.bundles, org.openhab.core.model.core, #{openhab_version}"
|
43
|
+
require "jar org.openhab.core.bundles, org.openhab.core.model.item, #{openhab_version}"
|
43
44
|
require "jar org.openhab.core.bundles, org.openhab.core.model.script, #{openhab_version}"
|
44
45
|
require "jar org.openhab.core.bundles, org.openhab.core.semantics, #{openhab_version}"
|
45
46
|
require "jar org.openhab.core.bundles, org.openhab.core.thing, #{openhab_version}"
|
@@ -58,6 +59,8 @@ end
|
|
58
59
|
# global variables need to be set up before openhab-scripting loads
|
59
60
|
require "openhab/log/logger"
|
60
61
|
require "rspec/openhab/core/logger"
|
62
|
+
# during testing, we don't want "regular" output from rules
|
63
|
+
OpenHAB::Log.logger("org.openhab.automation.jruby.runtime").level = :warn
|
61
64
|
require "openhab/dsl/imports"
|
62
65
|
OpenHAB::DSL::Imports.api = api
|
63
66
|
OpenHAB::DSL::Imports.import_presets
|
@@ -70,10 +73,14 @@ require "rspec/openhab/core/cron_scheduler"
|
|
70
73
|
# RSpec additions
|
71
74
|
require "rspec/core"
|
72
75
|
require "rspec/openhab/dsl/rules/rspec"
|
76
|
+
require "rspec/openhab/items"
|
73
77
|
require "rspec/openhab/state"
|
78
|
+
require "rspec/openhab/timer"
|
74
79
|
require "rspec/openhab/trigger"
|
75
80
|
require "rspec/openhab/wait"
|
76
|
-
|
81
|
+
RSpec.configure do |config|
|
82
|
+
config.include OpenHAB::Core::EntityLookup
|
83
|
+
end
|
77
84
|
|
78
85
|
RSpec::OpenHAB::Items.populate_items_from_api(api)
|
79
86
|
|
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.
|
4
|
+
version: 0.0.10
|
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-07-
|
11
|
+
date: 2022-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|