-
-
Notifications
You must be signed in to change notification settings - Fork 471
Apply default semantic tags from linked channels to items #4913
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
Merged
kaikreuzer
merged 60 commits into
openhab:main
from
andrewfg:apply-tags-from-items-file
Sep 28, 2025
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
8fafb61
work in progress
andrewfg 3a24e64
work in progress
andrewfg 30677ee
work in progress
andrewfg 3af3e83
add integration tests and fix code so the tests pass
andrewfg 49867e4
move to item registry
andrewfg 128190e
remove bat file
andrewfg e4524b2
tweak
andrewfg 4d975ac
revised pom
andrewfg c9c73e3
work in progress
andrewfg 9616f54
work in progress
andrewfg 673f9f3
work in progress
andrewfg 1fd05a7
work in progress
andrewfg b213720
refactoring, added javadoc, added test cases
andrewfg 0359524
check if osgi tests are being run
andrewfg 78f8f04
support removal of channel links
andrewfg 1f27164
Update ItemChannelLinkAssignDefaultTagsOSGiTest.java
andrewfg de82a01
formally update the item registry
andrewfg 207b666
handle pre-orphaned links, and refactoring
andrewfg f8205b4
Update bundles/org.openhab.core.thing/src/main/java/org/openhab/core/…
andrewfg c77e441
fix tag removal edge case
andrewfg b6000b0
default useTags=true; clear tagsLinked on item removal
andrewfg eea1bc9
java doc
andrewfg 172f9e2
adjust tests for useTags opt-out model
andrewfg 8084d1f
add TODO
andrewfg e6e08f4
fix item registry update and notification process
andrewfg 5f85893
revert to opt-in model
andrewfg a220197
fix build
andrewfg b674de6
change log level to info
andrewfg c54e38e
Add system wide configuration
andrewfg b4cadc0
rename config scope and key name
andrewfg 2898509
fixes based on reviewer suggestions
andrewfg b33185a
revert prior
andrewfg d8f3a92
fix itests and bndrun
andrewfg 7588041
resolve bndrun on other modules
andrewfg e9c54d7
allow useTags to be string or bool, and logging tweaks
andrewfg 38fe5f4
remove osgi test; initialize tags on start up
andrewfg 75953e8
work in progress
andrewfg 1511abf
tweaks to logging
andrewfg 9fa2e5e
unit tests work in progress
andrewfg fcded82
ready for final review
andrewfg 3f9c32e
fix integration test
andrewfg 218c565
fix bndrun merge conflict
andrewfg b444477
fix bndrun (trailing backslashes)
andrewfg cabdb2f
adopt reviewer suggestion
andrewfg 6931c25
Apply suggestion from @Copilot
andrewfg 737b01d
Update itests/org.openhab.core.model.item.tests/itest.bndrun
andrewfg fcacea2
per link useTags can opt out of global useTags
andrewfg ada3952
fix bndrun (again)
andrewfg 8c6b7ee
log exceptions
andrewfg 1f5443c
Merge remote-tracking branch 'upstream/main' into apply-tags-from-ite…
andrewfg 5238cb9
fix bndrun again again
andrewfg 680a238
Merge branch 'main' into apply-tags-from-items-file
andrewfg b7f017d
update bndrun again again again
andrewfg 04c0983
Merge branch 'apply-tags-from-items-file' of https://github.com/andre…
andrewfg d2bf657
Merge branch 'openhab:main' into apply-tags-from-items-file
andrewfg 01eee72
fix bndrun again again again again
andrewfg 79b8b2e
Update bundles/org.openhab.core.thing/src/main/java/org/openhab/core/…
andrewfg 6ae5dbb
Update bundles/org.openhab.core.thing/src/main/java/org/openhab/core/…
andrewfg 0296e3b
add comments
andrewfg a7b1c11
Merge branch 'main' into apply-tags-from-items-file
andrewfg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
283 changes: 273 additions & 10 deletions
283
...openhab.core.thing/src/main/java/org/openhab/core/thing/link/ItemChannelLinkRegistry.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
...thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkTaggingOSGiTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| * Copyright (c) 2010-2025 Contributors to the openHAB project | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0 | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.openhab.core.thing.link; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openhab.core.items.Item; | ||
| import org.openhab.core.items.ItemRegistry; | ||
| import org.openhab.core.model.ItemsStandaloneSetup; | ||
| import org.openhab.core.model.core.ModelRepository; | ||
| import org.openhab.core.model.thing.ThingStandaloneSetup; | ||
| import org.openhab.core.test.java.JavaOSGiTest; | ||
| import org.openhab.core.thing.Channel; | ||
| import org.openhab.core.thing.ChannelUID; | ||
| import org.openhab.core.thing.Thing; | ||
| import org.openhab.core.thing.ThingRegistry; | ||
| import org.openhab.core.thing.ThingTypeUID; | ||
| import org.openhab.core.thing.ThingUID; | ||
| import org.openhab.core.thing.binding.builder.ChannelBuilder; | ||
| import org.openhab.core.thing.binding.builder.ThingBuilder; | ||
|
|
||
| /** | ||
| * Tests for {@link ItemChannelLinkRegistry} tagging. | ||
| * | ||
| * @author Andrew Fiddian-Green - Initial contribution | ||
| */ | ||
| @NonNullByDefault | ||
| public class ItemChannelLinkTaggingOSGiTest extends JavaOSGiTest { | ||
|
|
||
| private static final String ITEMS_MODEL_ID = "test.items"; | ||
| private static final String ITEMS_MODEL = """ | ||
| String Item_01 {channel="hue:device:dummy:color" } | ||
| String Item_02 {channel="hue:device:dummy:color" [useTags=false] } | ||
| String Item_03 {channel="hue:device:dummy:color" [useTags="false"] } | ||
| String Item_04 "Control, Color" {channel="hue:device:dummy:color" [useTags=true] } | ||
| String Item_05 "Control, Color" {channel="hue:device:dummy:color" [useTags="true"] } | ||
| String Item_06 "Control Color, Custom" ["Custom"] {channel="hue:device:dummy:color" [useTags=true] } | ||
| String Item_07 "'Control', Power, Custom" ["Power", "Custom"] {channel="hue:device:dummy:color" } | ||
| String Item_08 "'Control', Power, Custom" ["Power", "Custom"] {channel="hue:device:dummy:color" [useTags=true] } | ||
| String Item_09 "Switch, Custom" ["Switch", "Custom"] {channel="hue:device:dummy:color" } | ||
| String Item_10 "Switch, Custom" ["Switch", "Custom"] {channel="hue:device:dummy:color" [useTags=true] } | ||
| String Item_11 "Switch, Power, Custom" ["Switch", "Power", "Custom"] {channel="hue:device:dummy:color" } | ||
| String Item_12 "Switch, Power, Custom" ["Switch", "Power", "Custom"] {channel="hue:device:dummy:color" [useTags=true] } | ||
| String Item_13 "Alarm, LowBattery" {channel="hue:device:dummy:battery-low" [useTags=true] } | ||
| String Item_14 "Control, Color" {channel="hue:device:dummy:color" [useTags=true], channel="hue:device:dummy:battery-low" [useTags=true] } | ||
| String Item_15 "Alarm, LowBattery" {channel="hue:device:dummy:color" [useTags=false], channel="hue:device:dummy:battery-low" [useTags=true] } | ||
| """; | ||
|
|
||
| private @NonNullByDefault({}) ItemRegistry itemRegistry; | ||
| private @NonNullByDefault({}) ThingRegistry thingRegistry; | ||
| private @NonNullByDefault({}) ModelRepository modelRepository; | ||
| private @NonNullByDefault({}) ItemChannelLinkRegistry itemChannelLinkRegistry; | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| registerVolatileStorageService(); | ||
|
|
||
| ItemsStandaloneSetup.doSetup(); | ||
| ThingStandaloneSetup.doSetup(); | ||
|
|
||
| itemRegistry = getService(ItemRegistry.class); | ||
| assertNotNull(itemRegistry); | ||
|
|
||
| thingRegistry = getService(ThingRegistry.class); | ||
| assertNotNull(thingRegistry); | ||
|
|
||
| itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class); | ||
| assertNotNull(itemChannelLinkRegistry); | ||
|
|
||
| modelRepository = getService(ModelRepository.class); | ||
| assertNotNull(modelRepository); | ||
| } | ||
|
|
||
| @Test | ||
| public void assertTagsAreCorrect() { | ||
| ThingTypeUID thingTypeUID = new ThingTypeUID("hue", "device"); | ||
| ThingUID thingUID = new ThingUID(thingTypeUID, "dummy"); | ||
|
|
||
| Channel colorChannel = ChannelBuilder.create(new ChannelUID(thingUID, "color"), "Color") | ||
| .withDefaultTags(Set.of("Control", "Color")).build(); | ||
| Channel batteryChannel = ChannelBuilder.create(new ChannelUID(thingUID, "battery-low"), "Switch") | ||
| .withDefaultTags(Set.of("Alarm", "LowBattery")).build(); | ||
|
|
||
| Thing thing = ThingBuilder.create(thingTypeUID, thingUID) // | ||
| .withChannels(List.of(colorChannel, batteryChannel)).build(); | ||
|
|
||
| thingRegistry.add(thing); | ||
| assertEquals(1, thingRegistry.getAll().size()); | ||
|
|
||
| modelRepository.addOrRefreshModel(ITEMS_MODEL_ID, new ByteArrayInputStream(ITEMS_MODEL.getBytes())); | ||
| assertEquals(15, itemRegistry.getAll().size()); | ||
| assertEquals(17, itemChannelLinkRegistry.getAll().size()); | ||
|
|
||
| Item item; | ||
|
|
||
| item = itemRegistry.get("Item_01"); | ||
| assertNotNull(item); | ||
| assertTrue(item.getTags().isEmpty()); | ||
|
|
||
| item = itemRegistry.get("Item_02"); | ||
| assertNotNull(item); | ||
| assertTrue(item.getTags().isEmpty()); | ||
|
|
||
| item = itemRegistry.get("Item_03"); | ||
| assertNotNull(item); | ||
| assertTrue(item.getTags().isEmpty()); | ||
|
|
||
| item = itemRegistry.get("Item_04"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Control", "Color"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_05"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Control", "Color"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_06"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Control", "Color", "Custom"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_07"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Power", "Custom"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_08"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Power", "Custom"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_09"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Switch", "Custom"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_10"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Switch", "Custom"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_11"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Switch", "Power", "Custom"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_12"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Switch", "Power", "Custom"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_13"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Alarm", "LowBattery"), item.getTags()); | ||
|
|
||
| item = itemRegistry.get("Item_14"); | ||
| assertNotNull(item); | ||
| assertTrue(item.getTags().equals(Set.of("Control", "Color")) // | ||
| || item.getTags().equals(Set.of("Alarm", "LowBattery"))); | ||
|
|
||
| item = itemRegistry.get("Item_15"); | ||
| assertNotNull(item); | ||
| assertEquals(Set.of("Alarm", "LowBattery"), item.getTags()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.