Skip to content

Commit

Permalink
testing: add helper to initialize missing thing types (#218)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer authored Jan 5, 2024
1 parent 90a9aac commit c563b17
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/openhab/rspec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ def autoupdate_all_items
end
end

#
# Force things to come online that are missing their thing type
#
# As of openHAB 4.0, things that are missing their thing type will not
# come online immediately. This especially impacts bindings that
# dynamically generate their thing types, but don't persist those
# thing types. You can use this method to force them to come online
# immediately.
#
# @return [void]
#
def initialize_missing_thing_types
thing_manager = OpenHAB::OSGi.service("org.openhab.core.thing.ThingManager")
thing_manager.class.field_reader :missingPrerequisites
first = true
thing_manager.missingPrerequisites.each_value do |prereq|
if first
prereq.class.field_accessor :timesChecked
first = false
end
prereq.timesChecked = 60
end
m = thing_manager.class.java_class.get_declared_method(:checkMissingPrerequisites)
m.accessible = true
suspend_rules do
m.invoke(thing_manager)
end
end

#
# Execute all pending timers
#
Expand Down

0 comments on commit c563b17

Please sign in to comment.