Skip to content

Commit

Permalink
Support creating a trigger profile for the UI (#373)
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored Dec 28, 2024
1 parent 6f5bb23 commit d015527
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/openhab/core/profile_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def unregister
end

# @!visibility private
def register(id, block, label: nil, config_description: nil)
def register(id, block, label: nil, type: :state, config_description: nil)
uid = org.openhab.core.thing.profiles.ProfileTypeUID.new("ruby", id)
uri = java.net.URI.new("profile", uid.to_s, nil)
if config_description && config_description.uid != uri
Expand All @@ -155,6 +155,7 @@ def register(id, block, label: nil, config_description: nil)
@profiles[uid] = {
thread_locals: DSL::ThreadLocal.persist,
label: label,
type: type,
config_description: config_description,
block: block
}
Expand All @@ -177,7 +178,11 @@ def getProfileTypes(_locale)
@profiles.map do |uid, profile|
next if profile[:label].nil?

org.openhab.core.thing.profiles.ProfileTypeBuilder.new_state(uid, "RUBY #{profile[:label]}").build
if profile[:type] == :trigger
org.openhab.core.thing.profiles.ProfileTypeBuilder.new_trigger(uid, "RUBY #{profile[:label]}").build
else
org.openhab.core.thing.profiles.ProfileTypeBuilder.new_state(uid, "RUBY #{profile[:label]}").build
end
end.compact
end

Expand Down
5 changes: 3 additions & 2 deletions lib/openhab/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def script!(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs
#
# @param [String, Symbol] id The id for the profile.
# @param [String, nil] label The label for the profile. When nil, the profile will not be visible in the UI.
# @param [:state, :trigger] type The type of profile.
# @param [org.openhab.core.config.core.ConfigDescription, nil] config_description
# The configuration description for the profile so that it can be configured in the UI.
# @yield [event, command: nil, state: nil, trigger: nil, time_series: nil, callback:, link:, item:, channel_uid:, configuration:, context:]
Expand Down Expand Up @@ -191,13 +192,13 @@ def script!(name = nil, description: nil, id: nil, tag: nil, tags: nil, **kwargs
# (configuration["min"]..configuration["max"]).cover?(state)
# end
#
def profile(id, label: nil, config_description: nil, &block)
def profile(id, label: nil, type: :state, config_description: nil, &block)
raise ArgumentError, "Block is required" unless block

id = id.to_s

ThreadLocal.thread_local(openhab_rule_type: "profile", openhab_rule_uid: id) do
Core::ProfileFactory.instance.register(id, block, label: label, config_description: config_description)
Core::ProfileFactory.instance.register(id, block, label: label, type: type, config_description: config_description)
end
end

Expand Down

0 comments on commit d015527

Please sign in to comment.