Skip to content

Commit

Permalink
Drop openHAB 4.0 snapshot compatibility (#97)
Browse files Browse the repository at this point in the history
SemanticTags.add was only in core for a short time, and not during any
full release.

---------

Signed-off-by: Cody Cutrer <[email protected]>
Signed-off-by: Jimmy Tanagra <[email protected]>
Co-authored-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
ccutrer and jimtng authored Sep 18, 2023
1 parent 1bd2b5f commit e351398
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions lib/openhab/core/items/semantics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def const_missing(sym)
# @deprecated OH3.4 cannot add a tag
# this not in the class << self block above because YARD doesn't figure out
# it's a class method with the conditional
if Provider.registry || org.openhab.core.semantics.SemanticTags.respond_to?(:add)
if Provider.registry
class << self
#
# Adds custom semantic tags.
Expand Down Expand Up @@ -311,25 +311,16 @@ def add(label: nil, synonyms: "", description: "", **tags)
synonyms = Array.wrap(synonyms).map { |s| s.to_s.strip }

tags.map do |name, parent|
# @deprecated OH4.0.0.M4 missing registry
if Provider.registry
parent = lookup(parent) unless parent.is_a?(SemanticTag)
next if lookup(name)
next unless parent

new_tag = org.openhab.core.semantics.SemanticTagImpl.new("#{parent.uid}_#{name}",
label,
description,
synonyms)
Provider.instance.add(new_tag)
lookup(name)
else
parent_is_tag = parent.respond_to?(:java_class) && parent.java_class < Tag.java_class
parent = parent_is_tag ? parent.java_class : parent.to_s
org.openhab.core.semantics.SemanticTags
.add(name.to_s, parent, label, synonyms.join(","), description)
&.then { lookup(name) }
end
parent = lookup(parent) unless parent.is_a?(SemanticTag)
next if lookup(name)
next unless parent

new_tag = org.openhab.core.semantics.SemanticTagImpl.new("#{parent.uid}_#{name}",
label,
description,
synonyms)
Provider.instance.add(new_tag)
lookup(name)
end.compact
end
end
Expand Down

0 comments on commit e351398

Please sign in to comment.