Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop openHAB 3.4 support #98

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
if: "!contains(github.event.head_commit.message, 'ci skip')"
outputs:
openhab_matrix: |
["3.4.3", "4.0.0.RC1", "4.0.0-SNAPSHOT"]
["4.0.0"]
snapshot_date: |
${{ steps.snapshot-date.outputs.SNAPSHOT_DATE }}
steps:
Expand Down Expand Up @@ -126,12 +126,7 @@ jobs:
strategy:
matrix:
openhab_version: ${{ fromJson(needs.openhab-matrix.outputs.openhab_matrix) }}
jruby_version: ["jruby-9.3.10.0", "jruby-9.4.3.0"]
exclude:
- openhab_version: 4.0.0.RC1
jruby_version: jruby-9.3.10.0
- openhab_version: 4.0.0-SNAPSHOT
jruby_version: jruby-9.3.10.0
jruby_version: ["jruby-9.4.3.0"]
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
Expand Down
16 changes: 6 additions & 10 deletions lib/openhab/core/events/item_state_updated_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
module OpenHAB
module Core
module Events
begin
java_import org.openhab.core.items.events.ItemStateUpdatedEvent
java_import org.openhab.core.items.events.ItemStateUpdatedEvent

#
# {AbstractEvent} sent when an item's state has updated.
#
class ItemStateUpdatedEvent < ItemEvent
include ItemState
end
rescue NameError
# @deprecated OH3.4 OH3 will raise an error ItemStateUpdatedEvent is only in OH4
#
# {AbstractEvent} sent when an item's state has updated.
#
class ItemStateUpdatedEvent < ItemEvent
include ItemState
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions lib/openhab/core/items/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ def metadata
#
def tagged?(*tags)
tags.map! do |tag|
# @deprecated OH3.4
if tag.is_a?(Module)
tag.simple_name
elsif defined?(Semantics::SemanticTag) && tag.is_a?(Semantics::SemanticTag)
if tag.is_a?(Semantics::SemanticTag)
tag.name
else
tag
Expand Down
173 changes: 66 additions & 107 deletions lib/openhab/core/items/semantics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ module Items
# and {#property_type}. They can even be used with
# {DSL::Items::ItemBuilder#tag}.
#
# In openHAB 4.0, all of the tag objects implement {SemanticTag}.
#
# In openHAB 3.4, the constants in the {Semantics} module are enhanced with {TagClassMethods}
# to provide easy access to the tags' additional attributes: {TagClassMethods#label label},
# {TagClassMethods#synonyms synonyms}, and {TagClassMethods#description description}.
# All of the tag objects implement {SemanticTag}, which provides easy
# access to the tags' additional attributes: {SemanticTag#label label},
# {SemanticTag#synonyms synonyms}, and {SemanticTag#description description}.
# For example, to get the synonyms for `Semantics::Lightbulb` in German:
# `Semantics::Lightbulb.synonyms(java.util.Locale::GERMAN)`
# `Semantics::Lightbulb.localized(java.util.Locale::GERMAN).synonyms`
#
# @see https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.semantics/model/SemanticTags.csv Semantic Tags Table
#
Expand Down Expand Up @@ -176,11 +174,6 @@ module Semantics
GenericItem.include(self)
GroupItem.extend(Forwardable)
GroupItem.def_delegators :members, :equipments, :locations
# This is a marker interface for all semantic tag classes.
# @interface
# @deprecated Since openHAB 4.0, {SemanticTag} is the interface that all tags implement.
# Tags are simple instances, instead of another interface in a hierarchical structure.
Tag = org.openhab.core.semantics.Tag

class << self
# @!visibility private
Expand Down Expand Up @@ -209,6 +202,64 @@ def tags
end
end

#
# Adds custom semantic tags.
#
# @since openHAB 4.0
# @return [Array<SemanticTag>] An array of tags successfully added.
#
# @overload add(**tags)
# Quickly add one or more semantic tags using the default label, empty synonyms and descriptions.
#
# @param [kwargs] **tags Pairs of `tag` => `parent` where tag is either a `Symbol` or a `String`
# for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a `String` of an
# existing tag.
# @return [Array<SemanticTag>] An array of tags successfully added.
#
# @example Add one semantic tag `Balcony` whose parent is `Semantics::Outdoor` (Location)
# Semantics.add(Balcony: Semantics::Outdoor)
#
# @example Add multiple semantic tags
# Semantics.add(Balcony: Semantics::Outdoor,
# SecretRoom: Semantics::Room,
# Motion: Semantics::Property)
#
# @overload add(label: nil, synonyms: "", description: "", **tags)
# Add a custom semantic tag with extra details.
#
# @example
# Semantics.add(SecretRoom: Semantics::Room, label: "My Secret Room",
# synonyms: "HidingPlace", description: "A room that requires a special trick to enter")
#
# @param [String,nil] label Optional label. When `nil`, infer the label from the tag name,
# converting `CamelCase` to `Camel Case`
# @param [String,Symbol,Array<String,Symbol>] synonyms Additional synonyms to refer to this tag.
# @param [String] description A longer description of the tag.
# @param [kwargs] **tags Exactly one pair of `tag` => `parent` where tag is either a `Symbol` or a
# `String` for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a
# `String` of an existing tag.
# @return [Array<SemanticTag>] An array of tags successfully added.
#
def add(label: nil, synonyms: "", description: "", **tags)
raise ArgumentError, "Tags must be specified" if tags.empty?
if (tags.length > 1) && !(label.nil? && synonyms.empty? && description.empty?)
raise ArgumentError, "Additional options can only be specified when creating one tag"
end

synonyms = Array.wrap(synonyms).map(&:to_s).map(&:strip)

tags.map do |name, parent|
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

#
# Finds a semantic tag using its name, label, or synonyms.
#
Expand All @@ -222,29 +273,11 @@ def tags
def lookup(id, locale = java.util.Locale.default)
id = id.to_s

# @deprecated OH3.4 - the Property tag had an ID of "MeasurementProperty" in OH3.4.
# This was corrected in OH4.
# Make sure we compare against pre-release versions
if id == "Property" && Gem::Version.new(Core::VERSION) < Gem::Version.new("4.0.0.M1")
id = "MeasurementProperty"
end
tag_class = service.get_by_label_or_synonym(id, locale).first ||
Provider.registry.get_tag_class_by_id(id)
return unless tag_class

# @deprecated OH3.4 missing registry
if Provider.registry
tag_class = service.get_by_label_or_synonym(id, locale).first ||
Provider.registry.get_tag_class_by_id(id)
return unless tag_class

Provider.registry.get(Provider.registry.class.build_id(tag_class))
else
tag = org.openhab.core.semantics.SemanticTags.get_by_label_or_synonym(id, locale).first ||
org.openhab.core.semantics.SemanticTags.get_by_id(id)
return unless tag

tag = tag.ruby_class
tag.singleton_class.include(TagClassMethods)
tag
end
Provider.registry.get(Provider.registry.class.build_id(tag_class))
end

#
Expand All @@ -257,80 +290,6 @@ def const_missing(sym)
end
end

# @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)
class << self
#
# Adds custom semantic tags.
#
# @since openHAB 4.0
# @return [Array<SemanticTag>] An array of tags successfully added.
#
# @overload add(**tags)
# Quickly add one or more semantic tags using the default label, empty synonyms and descriptions.
#
# @param [kwargs] **tags Pairs of `tag` => `parent` where tag is either a `Symbol` or a `String`
# for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a `String` of an
# existing tag.
# @return [Array<SemanticTag>] An array of tags successfully added.
#
# @example Add one semantic tag `Balcony` whose parent is `Semantics::Outdoor` (Location)
# Semantics.add(Balcony: Semantics::Outdoor)
#
# @example Add multiple semantic tags
# Semantics.add(Balcony: Semantics::Outdoor,
# SecretRoom: Semantics::Room,
# Motion: Semantics::Property)
#
# @overload add(label: nil, synonyms: "", description: "", **tags)
# Add a custom semantic tag with extra details.
#
# @example
# Semantics.add(SecretRoom: Semantics::Room, label: "My Secret Room",
# synonyms: "HidingPlace", description: "A room that requires a special trick to enter")
#
# @param [String,nil] label Optional label. When `nil`, infer the label from the tag name,
# converting `CamelCase` to `Camel Case`
# @param [String,Symbol,Array<String,Symbol>] synonyms Additional synonyms to refer to this tag.
# @param [String] description A longer description of the tag.
# @param [kwargs] **tags Exactly one pair of `tag` => `parent` where tag is either a `Symbol` or a
# `String` for the tag to be added, and parent is either a {SemanticTag}, a `Symbol` or a
# `String` of an existing tag.
# @return [Array<SemanticTag>] An array of tags successfully added.
#
def add(label: nil, synonyms: "", description: "", **tags)
raise ArgumentError, "Tags must be specified" if tags.empty?
if (tags.length > 1) && !(label.nil? && synonyms.empty? && description.empty?)
raise ArgumentError, "Additional options can only be specified when creating one tag"
end

synonyms = Array.wrap(synonyms).map(&:to_s).map(&: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
end.compact
end
end
end

# @!parse
# class Items::GroupItem
# #
Expand Down
6 changes: 1 addition & 5 deletions lib/openhab/core/items/semantics/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ module Semantics
# Provides {SemanticTag SemanticTags} created in Ruby to openHAB
#
class Provider < Core::Provider
begin
include org.openhab.core.semantics.SemanticTagProvider
rescue NameError
# @deprecated OH3.4
end
include org.openhab.core.semantics.SemanticTagProvider

class << self
#
Expand Down
3 changes: 0 additions & 3 deletions lib/openhab/core/items/semantics/semantic_tag.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

# @deprecated OH3.4
return unless OpenHAB::Core::Items::Semantics::Provider.registry

module OpenHAB
module Core
module Items
Expand Down
64 changes: 0 additions & 64 deletions lib/openhab/core/items/semantics/tag_class_methods.rb

This file was deleted.

6 changes: 2 additions & 4 deletions lib/openhab/core/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,15 @@ def update(element)

# @!visibility private
def unregister
# @deprecated OH3.4 safe navigation only required for missing Semantics registry
self.class.registry&.remove_provider(self)
self.class.registry.remove_provider(self)
end

private

def initialize(unload_priority: nil)
super()
@elements = java.util.concurrent.ConcurrentHashMap.new
# @deprecated OH3.4 safe navigation only required for missing Semantics registry
self.class.registry&.add_provider(self)
self.class.registry.add_provider(self)
ScriptHandling.script_unloaded(priority: unload_priority) { unregister }
end
end
Expand Down
Loading
Loading