diff --git a/bundles/org.opensmarthouse.core.io.rest.item/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java b/bundles/org.opensmarthouse.core.io.rest.item/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java
index 7e0b38ca17f..714e2c7c7c6 100644
--- a/bundles/org.opensmarthouse.core.io.rest.item/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java
+++ b/bundles/org.opensmarthouse.core.io.rest.item/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java
@@ -40,7 +40,6 @@
import org.openhab.core.thing.link.AbstractLink;
import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.link.ItemChannelLinkRegistry;
-import org.openhab.core.thing.link.ThingLinkManager;
import org.openhab.core.thing.link.dto.ItemChannelLinkDTO;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@@ -72,7 +71,6 @@ public class ItemChannelLinkResource implements RESTResource {
public static final String PATH_LINKS = "links";
private ItemChannelLinkRegistry itemChannelLinkRegistry;
- private ThingLinkManager thingLinkManager;
@Context
UriInfo uriInfo;
@@ -97,15 +95,6 @@ public Response getAll(
return Response.ok(new Stream2JSONInputStream(linkStream)).build();
}
- @GET
- @Path("/auto")
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Tells whether automatic link mode is active or not", response = Boolean.class)
- @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = Boolean.class) })
- public Response isAutomatic() {
- return Response.ok(thingLinkManager.isAutoLinksEnabled()).build();
- }
-
@GET
@Path("/{itemName}/{channelUID}")
@ApiOperation(value = "Retrieves an individual link.")
@@ -180,15 +169,6 @@ public Response unlink(@PathParam("itemName") @ApiParam(value = "itemName") Stri
}
}
- @Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
- protected void setThingLinkManager(ThingLinkManager thingLinkManager) {
- this.thingLinkManager = thingLinkManager;
- }
-
- protected void unsetThingLinkManager(ThingLinkManager thingLinkManager) {
- this.thingLinkManager = null;
- }
-
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
protected void setItemChannelLinkRegistry(ItemChannelLinkRegistry itemChannelLinkRegistry) {
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
@@ -205,7 +185,7 @@ private ItemChannelLinkDTO toBeans(ItemChannelLink link) {
@Override
public boolean isSatisfied() {
- return itemChannelLinkRegistry != null && thingLinkManager != null;
+ return itemChannelLinkRegistry != null;
}
}
diff --git a/bundles/org.opensmarthouse.core.thing/src/main/java/org/openhab/core/thing/link/ThingLinkManager.java b/bundles/org.opensmarthouse.core.thing/src/main/java/org/openhab/core/thing/link/ThingLinkManager.java
deleted file mode 100644
index 97aa2ec4208..00000000000
--- a/bundles/org.opensmarthouse.core.thing/src/main/java/org/openhab/core/thing/link/ThingLinkManager.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/**
- * Copyright (c) 2010-2020 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 java.util.List;
-import java.util.Set;
-import java.util.concurrent.ScheduledExecutorService;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.core.common.ThreadPoolManager;
-import org.openhab.core.common.registry.Provider;
-import org.openhab.core.common.registry.ProviderChangeListener;
-import org.openhab.core.common.registry.RegistryChangeListener;
-import org.openhab.core.events.AbstractTypedEventSubscriber;
-import org.openhab.core.events.EventSubscriber;
-import org.openhab.core.items.Item;
-import org.openhab.core.items.ItemRegistry;
-import org.openhab.core.thing.Channel;
-import org.openhab.core.thing.ChannelUID;
-import org.openhab.core.thing.ManagedThingProvider;
-import org.openhab.core.thing.Thing;
-import org.openhab.core.thing.ThingRegistry;
-import org.openhab.core.thing.ThingStatus;
-import org.openhab.core.thing.binding.ThingHandler;
-import org.openhab.core.thing.events.ThingStatusInfoChangedEvent;
-import org.openhab.core.thing.type.ChannelType;
-import org.openhab.core.thing.type.ChannelTypeRegistry;
-import org.openhab.core.thing.util.ThingHandlerHelper;
-import org.osgi.service.component.ComponentContext;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Modified;
-import org.osgi.service.component.annotations.Reference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The {@link ThingLinkManager} manages links for channels.
- *
- * If a Thing is created, it can automatically create links for its non-advanced channels.
- * Upon a Thing deletion, it removes all links of this Thing.
- *
- * @author Dennis Nobel - Initial contribution
- * @author Markus Rathgeb - Handle item registry's all items changed notification
- * @author Kai Kreuzer - Refactored to make it a service and introduced the auto-linking (as a replacement for the
- * ThingSetupManager)
- * @author Markus Rathgeb - Send link notification if item and link exists and unlink on the first removal
- */
-@Component(immediate = true, configurationPid = ThingLinkManager.CONFIGURATION_PID, service = { ThingLinkManager.class,
- EventSubscriber.class }, property = { "service.config.description.uri:String=system:links",
- "service.config.label:String=Item Linking", "service.config.category:String=system",
- "service.pid:String=org.openhab.core.links" })
-@NonNullByDefault
-public class ThingLinkManager extends AbstractTypedEventSubscriber {
-
- public static final String CONFIGURATION_PID = "org.openhab.links";
-
- public static final String AUTO_LINKS = "autoLinks";
-
- private static final String THREADPOOL_NAME = "thingLinkManager";
-
- private final Logger logger = LoggerFactory.getLogger(ThingLinkManager.class);
-
- private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool(THREADPOOL_NAME);
-
- private final ThingRegistry thingRegistry;
- private final ManagedThingProvider managedThingProvider;
- private final ItemRegistry itemRegistry;
- private final ItemChannelLinkRegistry itemChannelLinkRegistry;
- private final ChannelTypeRegistry channelTypeRegistry;
-
- private boolean autoLinks = true;
-
- @Activate
- public ThingLinkManager(final @Reference ThingRegistry thingRegistry,
- final @Reference ManagedThingProvider managedThingProvider, final @Reference ItemRegistry itemRegistry,
- final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry,
- final @Reference ChannelTypeRegistry channelTypeRegistry) {
- super(ThingStatusInfoChangedEvent.TYPE);
- this.thingRegistry = thingRegistry;
- this.managedThingProvider = managedThingProvider;
- this.itemRegistry = itemRegistry;
- this.itemChannelLinkRegistry = itemChannelLinkRegistry;
- this.channelTypeRegistry = channelTypeRegistry;
- }
-
- @Activate
- public void activate(ComponentContext context) {
- modified(context);
- itemRegistry.addRegistryChangeListener(itemRegistryChangeListener);
- itemChannelLinkRegistry.addRegistryChangeListener(itemChannelLinkRegistryChangeListener);
- managedThingProvider.addProviderChangeListener(managedThingProviderListener);
- }
-
- @Modified
- protected void modified(ComponentContext context) {
- // check whether we want to enable the automatic link creation or not
- if (context != null) {
- Object value = context.getProperties().get(AUTO_LINKS);
- autoLinks = value == null || !value.toString().equals("false");
- }
- }
-
- @Deactivate
- public void deactivate() {
- itemRegistry.removeRegistryChangeListener(itemRegistryChangeListener);
- itemChannelLinkRegistry.removeRegistryChangeListener(itemChannelLinkRegistryChangeListener);
- managedThingProvider.removeProviderChangeListener(managedThingProviderListener);
- }
-
- public boolean isAutoLinksEnabled() {
- return autoLinks;
- }
-
- private final RegistryChangeListener- itemRegistryChangeListener = new RegistryChangeListener
- () {
- @Override
- public void added(Item element) {
- for (final ChannelUID channelUID : itemChannelLinkRegistry.getBoundChannels(element.getName())) {
- final Thing thing = thingRegistry.get(channelUID.getThingUID());
- if (thing != null) {
- final Channel channel = thing.getChannel(channelUID.getId());
- if (channel != null) {
- ThingLinkManager.this.informHandlerAboutLinkedChannel(thing, channel);
- }
- }
- }
- }
-
- @Override
- public void removed(Item element) {
- for (final ChannelUID channelUID : itemChannelLinkRegistry.getBoundChannels(element.getName())) {
- final Thing thing = thingRegistry.get(channelUID.getThingUID());
- if (thing != null) {
- final Channel channel = thing.getChannel(channelUID.getId());
- if (channel != null) {
- ThingLinkManager.this.informHandlerAboutUnlinkedChannel(thing, channel);
- }
- }
- }
- }
-
- @Override
- public void updated(Item oldElement, Item element) {
- if (!oldElement.equals(element)) {
- this.removed(oldElement);
- this.added(element);
- }
- }
-
- };
-
- private final RegistryChangeListener itemChannelLinkRegistryChangeListener = new RegistryChangeListener() {
-
- @Override
- public void added(ItemChannelLink itemChannelLink) {
- if (itemRegistry.get(itemChannelLink.getItemName()) == null) {
- // Don't inform about the link if the item does not exist.
- // The handler will be informed on item creation.
- return;
- }
- ChannelUID channelUID = itemChannelLink.getLinkedUID();
- Thing thing = thingRegistry.get(channelUID.getThingUID());
- if (thing != null) {
- Channel channel = thing.getChannel(channelUID.getId());
- if (channel != null) {
- ThingLinkManager.this.informHandlerAboutLinkedChannel(thing, channel);
- }
- }
- }
-
- @Override
- public void removed(ItemChannelLink itemChannelLink) {
- /*
- * Don't check for item existence here.
- * If an item and its link are removed before the registry change listener methods are called,
- * a check for the item could prevent that the handler is informed about the unlink at all.
- */
- ChannelUID channelUID = itemChannelLink.getLinkedUID();
- Thing thing = thingRegistry.get(channelUID.getThingUID());
- if (thing != null) {
- Channel channel = thing.getChannel(channelUID.getId());
- if (channel != null) {
- ThingLinkManager.this.informHandlerAboutUnlinkedChannel(thing, channel);
- }
- }
- }
-
- @Override
- public void updated(ItemChannelLink oldElement, ItemChannelLink element) {
- if (!oldElement.equals(element)) {
- this.removed(oldElement);
- this.added(element);
- }
- }
-
- };
-
- private final ProviderChangeListener managedThingProviderListener = new ProviderChangeListener() {
-
- @Override
- public void added(Provider provider, Thing thing) {
- List channels = thing.getChannels();
- for (Channel channel : channels) {
- createLinkIfNotAdvanced(channel);
- }
- }
-
- private void createLinkIfNotAdvanced(Channel channel) {
- if (autoLinks) {
- if (channel.getChannelTypeUID() != null) {
- ChannelType type = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
- if (type != null && type.isAdvanced()) {
- return;
- }
- }
- ItemChannelLink link = new ItemChannelLink(deriveItemName(channel.getUID()), channel.getUID());
- itemChannelLinkRegistry.add(link);
- }
- }
-
- @Override
- public void removed(Provider provider, Thing thing) {
- List channels = thing.getChannels();
- for (Channel channel : channels) {
- ItemChannelLink link = new ItemChannelLink(deriveItemName(channel.getUID()), channel.getUID());
- itemChannelLinkRegistry.remove(link.getUID());
- }
- }
-
- @Override
- public void updated(Provider provider, Thing oldThing, Thing newThing) {
- for (Channel channel : oldThing.getChannels()) {
- if (newThing.getChannel(channel.getUID().getId()) == null) {
- // this channel does not exist anymore, so remove outdated links
- ItemChannelLink link = new ItemChannelLink(deriveItemName(channel.getUID()), channel.getUID());
- itemChannelLinkRegistry.remove(link.getUID());
- }
- }
- for (Channel channel : newThing.getChannels()) {
- if (oldThing.getChannel(channel.getUID().getId()) == null) {
- // this channel did not exist before, so add a link
- createLinkIfNotAdvanced(channel);
- }
- }
- }
-
- private String deriveItemName(ChannelUID uid) {
- return uid.getAsString().replaceAll("[^a-zA-Z0-9_]", "_");
- }
-
- };
-
- private void informHandlerAboutLinkedChannel(Thing thing, Channel channel) {
- scheduler.submit(() -> {
- // Don't notify the thing if the thing isn't initialized
- if (ThingHandlerHelper.isHandlerInitialized(thing)) {
- ThingHandler handler = thing.getHandler();
- if (handler != null) {
- try {
- handler.channelLinked(channel.getUID());
- } catch (Exception ex) {
- logger.error("Exception occurred while informing handler: {}", ex.getMessage(), ex);
- }
- } else {
- logger.trace(
- "Can not inform handler about linked channel, because no handler is assigned to the thing {}.",
- thing.getUID());
- }
- }
- });
- }
-
- private void informHandlerAboutUnlinkedChannel(Thing thing, Channel channel) {
- scheduler.submit(() -> {
- // Don't notify the thing if the thing isn't initialized
- if (ThingHandlerHelper.isHandlerInitialized(thing)) {
- ThingHandler handler = thing.getHandler();
- if (handler != null) {
- try {
- handler.channelUnlinked(channel.getUID());
- } catch (Exception ex) {
- logger.error("Exception occurred while informing handler: {}", ex.getMessage(), ex);
- }
- } else {
- logger.trace(
- "Can not inform handler about unlinked channel, because no handler is assigned to the thing {}.",
- thing.getUID());
- }
- }
- });
- }
-
- @Override
- protected void receiveTypedEvent(ThingStatusInfoChangedEvent event) {
- // when a thing handler is successfully initialized (i.e. it goes from INITIALIZING to UNKNOWN, ONLINE or
- // OFFLINE), we need to make sure that channelLinked() is called for all existing links
- if (ThingStatus.INITIALIZING.equals(event.getOldStatusInfo().getStatus())) {
- if (ThingHandlerHelper.isHandlerInitialized(event.getStatusInfo().getStatus())) {
- Thing thing = thingRegistry.get(event.getThingUID());
- if (thing != null) {
- for (Channel channel : thing.getChannels()) {
- Set linkedItemNames = itemChannelLinkRegistry.getLinkedItemNames(channel.getUID());
- if (!linkedItemNames.isEmpty()) {
- informHandlerAboutLinkedChannel(thing, channel);
- }
- }
- }
- }
- }
- }
-
-}
diff --git a/bundles/org.opensmarthouse.core.thing/src/main/resources/OH-INF/config/config.xml b/bundles/org.opensmarthouse.core.thing/src/main/resources/OH-INF/config/config.xml
index 42fa8d1b7a4..feb736c9e0c 100644
--- a/bundles/org.opensmarthouse.core.thing/src/main/resources/OH-INF/config/config.xml
+++ b/bundles/org.opensmarthouse.core.thing/src/main/resources/OH-INF/config/config.xml
@@ -5,18 +5,6 @@
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0
https://openhab.org/schemas/config-description-1.0.0.xsd">
-
-
-
- In simple mode, links and their according items are automatically created for new Things.
- If the simple mode is turned off, the user has the full control about which items channels are linked to. Existing links will remain untouched.
- ]]>
-
- true
-
-
-
diff --git a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingLinkManagerOSGiTest.java b/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingLinkManagerOSGiTest.java
deleted file mode 100644
index a3b814fa210..00000000000
--- a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingLinkManagerOSGiTest.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/**
- * Copyright (c) 2010-2020 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.internal;
-
-import static java.util.Collections.singletonList;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Mockito.*;
-
-import java.math.BigDecimal;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.openhab.core.config.core.Configuration;
-import org.openhab.core.items.ItemRegistry;
-import org.openhab.core.test.java.JavaOSGiTest;
-import org.openhab.core.thing.Channel;
-import org.openhab.core.thing.ChannelUID;
-import org.openhab.core.thing.ManagedThingProvider;
-import org.openhab.core.thing.Thing;
-import org.openhab.core.thing.ThingRegistry;
-import org.openhab.core.thing.ThingStatus;
-import org.openhab.core.thing.ThingTypeUID;
-import org.openhab.core.thing.ThingUID;
-import org.openhab.core.thing.binding.BaseThingHandler;
-import org.openhab.core.thing.binding.BaseThingHandlerFactory;
-import org.openhab.core.thing.binding.ThingHandler;
-import org.openhab.core.thing.binding.ThingHandlerFactory;
-import org.openhab.core.thing.link.ItemChannelLinkRegistry;
-import org.openhab.core.thing.link.ThingLinkManager;
-import org.openhab.core.thing.type.ChannelDefinitionBuilder;
-import org.openhab.core.thing.type.ChannelType;
-import org.openhab.core.thing.type.ChannelTypeBuilder;
-import org.openhab.core.thing.type.ChannelTypeProvider;
-import org.openhab.core.thing.type.ChannelTypeUID;
-import org.openhab.core.thing.type.ThingType;
-import org.openhab.core.thing.type.ThingTypeBuilder;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.StateDescription;
-import org.openhab.core.types.StateOption;
-import org.osgi.service.component.ComponentContext;
-
-/**
- *
- * These tests will check (un-)linking of items and channels managed
- * by {@link ThingLinkManager}.
- *
- * @author Alex Tugarev - Initial contribution
- * @author Dennis Nobel - Added test for bug 459628 (lifecycle problem)
- * @author Thomas Höfer - Thing type constructor modified because of thing properties introduction
- * @author Kai Kreuzer - Adapted to new service implementation
- * @author Wouter Born - Migrate tests from Groovy to Java
- */
-public class ThingLinkManagerOSGiTest extends JavaOSGiTest {
-
- private ThingRegistry thingRegistry;
- private ManagedThingProvider managedThingProvider;
- private ItemRegistry itemRegistry;
- private ItemChannelLinkRegistry itemChannelLinkRegistry;
-
- private final Map context = new ConcurrentHashMap<>();
-
- @Before
- public void setup() {
- context.clear();
-
- registerVolatileStorageService();
- thingRegistry = getService(ThingRegistry.class);
- managedThingProvider = getService(ManagedThingProvider.class);
- itemRegistry = getService(ItemRegistry.class);
- assertNotNull(itemRegistry);
- itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
- assertThat(thingRegistry, is(notNullValue()));
-
- ComponentContext componentContext = mock(ComponentContext.class);
- when(componentContext.getBundleContext()).thenReturn(bundleContext);
-
- TestThingHandlerFactory thingHandlerFactory = new TestThingHandlerFactory();
- thingHandlerFactory.activate(componentContext);
- registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
-
- StateDescription state = new StateDescription(BigDecimal.valueOf(0), BigDecimal.valueOf(100),
- BigDecimal.valueOf(10), "%d Peek", true,
- Collections.singletonList(new StateOption("SOUND", "My great sound.")));
-
- ChannelType channelType = ChannelTypeBuilder.state(new ChannelTypeUID("hue:alarm"), "Alarm Channel", "Number")
- .withStateDescription(state).build();
- List channelTypes = singletonList(channelType);
-
- ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
- when(channelTypeProvider.getChannelTypes(nullable(Locale.class))).thenReturn(channelTypes);
- when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class)))
- .then(new Answer<@Nullable ChannelType>() {
- @Override
- public @Nullable ChannelType answer(InvocationOnMock invocation) throws Throwable {
- ChannelTypeUID uid = (ChannelTypeUID) invocation.getArgument(0);
- return channelTypes.stream().filter(t -> t.getUID().equals(uid)).findFirst().get();
-
- }
- });
- registerService(channelTypeProvider);
-
- ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("hue:lamp"), "label")
- .withChannelDefinitions(singletonList(new ChannelDefinitionBuilder("1", channelType.getUID()).build()))
- .build();
- SimpleThingTypeProvider thingTypeProvider = new SimpleThingTypeProvider(singletonList(thingType));
- registerService(thingTypeProvider);
- }
-
- @After
- public void teardown() {
- ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class);
- if (managedThingProvider != null) {
- managedThingProvider.getAll().forEach(t -> managedThingProvider.remove(t.getUID()));
- }
-
- itemChannelLinkRegistry.getAll().forEach(l -> itemChannelLinkRegistry.remove(l.getUID()));
- }
-
- @Test
- public void assertThatLinksAreRemovedUponThingRemoval() {
- ThingUID thingUID = new ThingUID("hue:lamp:lamp1");
- Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), thingUID, null, "test thing",
- new Configuration());
-
- List channels = thing.getChannels();
- assertThat(channels.size(), is(1));
- Channel channel = channels.get(0);
-
- managedThingProvider.add(thing);
- waitForAssert(() -> assertThat(itemChannelLinkRegistry.getLinkedItems(channel.getUID()).size(), is(1)));
-
- managedThingProvider.remove(thingUID);
- waitForAssert(() -> assertThat(itemChannelLinkRegistry.getLinkedItems(channel.getUID()).size(), is(0)));
- }
-
- @Test
- public void assertThatChannelLinkedAndChannelUnlinkedAtThingHandlerIsCalled() {
- ThingUID thingUID = new ThingUID("hue:lamp:lamp1");
- Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), thingUID, null, "test thing",
- new Configuration());
- if (thing != null) {
- managedThingProvider.add(thing);
- } else {
- throw new AssertionError("thing is null");
- }
-
- ChannelUID channelUID = new ChannelUID(thingUID, "1");
-
- waitForAssert(() -> {
- assertThat(context.remove("linkedChannel"), is(equalTo(channelUID)));
- assertThat(context.remove("unlinkedChannel"), is(nullValue()));
- });
-
- itemChannelLinkRegistry.removeLinksForThing(thingUID);
-
- waitForAssert(() -> assertThat(context.remove("unlinkedChannel"), is(equalTo(channelUID))));
- }
-
- class TestThingHandlerFactory extends BaseThingHandlerFactory {
- @Override
- public void activate(ComponentContext componentContext) {
- super.activate(componentContext);
- }
-
- @Override
- public boolean supportsThingType(ThingTypeUID thingTypeUID) {
- return true;
- }
-
- @Override
- protected ThingHandler createHandler(Thing thing) {
- return new TestThingHandler(thing);
- }
- }
-
- class TestThingHandler extends BaseThingHandler {
- public TestThingHandler(Thing thing) {
- super(thing);
- }
-
- @Override
- public void handleCommand(ChannelUID channelUID, Command command) {
- }
-
- @Override
- public void initialize() {
- updateStatus(ThingStatus.ONLINE);
- }
-
- @Override
- public void channelLinked(ChannelUID channelUID) {
- context.put("linkedChannel", channelUID);
- }
-
- @Override
- public void channelUnlinked(ChannelUID channelUID) {
- context.put("unlinkedChannel", channelUID);
- }
- }
-}
diff --git a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java b/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java
index 353ce82c0d7..e0c15d297a4 100644
--- a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java
+++ b/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java
@@ -18,11 +18,8 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
-import java.io.IOException;
import java.net.URI;
import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Semaphore;
@@ -75,7 +72,6 @@
import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.link.ItemChannelLinkRegistry;
import org.openhab.core.thing.link.ManagedItemChannelLinkProvider;
-import org.openhab.core.thing.link.ThingLinkManager;
import org.openhab.core.thing.type.ChannelDefinitionBuilder;
import org.openhab.core.thing.type.ChannelGroupType;
import org.openhab.core.thing.type.ChannelGroupTypeBuilder;
@@ -89,7 +85,6 @@
import org.openhab.core.thing.type.ThingTypeBuilder;
import org.openhab.core.types.Command;
import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.ComponentContext;
/**
@@ -144,8 +139,6 @@ public void setUp() throws Exception {
)).build();
registerVolatileStorageService();
- configureAutoLinking(false);
-
managedThingProvider = getService(ManagedThingProvider.class);
itemRegistry = getService(ItemRegistry.class);
@@ -194,7 +187,6 @@ public void teardown() throws Exception {
managedThingProvider.remove(it.getUID());
});
storage.remove(THING_UID.getAsString());
- configureAutoLinking(true);
}
@Test
@@ -1054,17 +1046,6 @@ private void registerChannelGroupTypeProvider() throws Exception {
registerService(mockChannelGroupTypeProvider);
}
- private void configureAutoLinking(Boolean on) throws IOException {
- ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class);
- org.osgi.service.cm.Configuration config = configAdmin.getConfiguration(ThingLinkManager.CONFIGURATION_PID);
- Dictionary properties = config.getProperties();
- if (properties == null) {
- properties = new Hashtable<>();
- }
- properties.put(ThingLinkManager.AUTO_LINKS, on.toString());
- config.update(properties);
- }
-
private static class TestThingHandlerFactory extends BaseThingHandlerFactory {
private final ThingTypeUID thingTypeUID;
diff --git a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java b/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java
index f0c5984bc99..549fb08885a 100644
--- a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java
+++ b/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java
@@ -89,7 +89,6 @@
import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.link.ItemChannelLinkRegistry;
import org.openhab.core.thing.link.ManagedItemChannelLinkProvider;
-import org.openhab.core.thing.link.ThingLinkManager;
import org.openhab.core.thing.testutil.i18n.DefaultLocaleSetter;
import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelTypeBuilder;
@@ -127,7 +126,6 @@ public class ThingManagerOSGiTest extends JavaOSGiTest {
private ManagedThingProvider managedThingProvider;
private ReadyService readyService;
private Thing thing;
- private ThingLinkManager thingLinkManager;
@Before
@SuppressWarnings("null")
@@ -142,8 +140,6 @@ public void setUp() {
.thenReturn(ChannelTypeBuilder.state(CHANNEL_TYPE_UID, "label", "Switch").build());
registerService(channelTypeProvider);
- thingLinkManager = getService(ThingLinkManager.class);
- thingLinkManager.deactivate();
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
managedThingProvider = getService(ManagedThingProvider.class);
eventPublisher = getService(EventPublisher.class);
@@ -192,7 +188,6 @@ public void teardown() {
managedThingProvider.getAll().forEach(t -> managedThingProvider.remove(t.getUID()));
ComponentContext componentContext = mock(ComponentContext.class);
when(componentContext.getProperties()).thenReturn(new Hashtable<>());
- thingLinkManager.activate(componentContext);
}
@Test
diff --git a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java b/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java
index 2be7c5c1769..9ff93ab4841 100644
--- a/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java
+++ b/itests/org.opensmarthouse.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java
@@ -48,13 +48,10 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest {
private ManagedItemChannelLinkProvider managedItemChannelLinkProvider;
private ItemChannelLinkRegistry itemChannelLinkRegistry;
private ManagedThingProvider managedThingProvider;
- private ThingLinkManager thingLinkManager;
@Before
public void setup() {
registerVolatileStorageService();
- thingLinkManager = getService(ThingLinkManager.class);
- thingLinkManager.deactivate();
managedThingProvider = getService(ManagedThingProvider.class);
managedThingProvider.add(ThingBuilder.create(THING_TYPE_UID, THING_UID)
.withChannel(ChannelBuilder.create(CHANNEL_UID, "Color").build()).build());
@@ -69,7 +66,6 @@ public void teardown() {
managedThingProvider.getAll().forEach(it -> managedThingProvider.remove(it.getUID()));
ComponentContext componentContext = mock(ComponentContext.class);
when(componentContext.getProperties()).thenReturn(new Hashtable<>());
- thingLinkManager.activate(componentContext);
}
@Test