From e3513983bb6c04c322f5b518ffd0c25e50ace555 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Sun, 17 Sep 2023 19:48:17 -0600 Subject: [PATCH] Drop openHAB 4.0 snapshot compatibility (#97) SemanticTags.add was only in core for a short time, and not during any full release. --------- Signed-off-by: Cody Cutrer Signed-off-by: Jimmy Tanagra Co-authored-by: Jimmy Tanagra --- lib/openhab/core/items/semantics.rb | 31 ++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/openhab/core/items/semantics.rb b/lib/openhab/core/items/semantics.rb index cf9da16a2a..a9406c0f2d 100644 --- a/lib/openhab/core/items/semantics.rb +++ b/lib/openhab/core/items/semantics.rb @@ -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. @@ -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