From 20f4e5deb3d31f92ac9c695d5b5206ad8c33c00f Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Sat, 16 Nov 2019 15:54:11 +0100 Subject: [PATCH] Removed use of 'bundleContext' from 'BaseThingHandler' as it is deprecated (#6395) Signed-off-by: Christoph Weitkamp --- .../openhab/binding/exec/internal/handler/ExecHandler.java | 5 +++++ .../globalcache/internal/handler/GlobalCacheHandler.java | 5 +++++ .../modbus/internal/handler/ModbusDataThingHandler.java | 5 +++++ .../binding/modbus/internal/ModbusDataHandlerTest.java | 3 --- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java b/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java index dc60555be27e5..918ac4c350cd1 100644 --- a/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java +++ b/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java @@ -42,6 +42,8 @@ import org.eclipse.smarthome.core.transform.TransformationService; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.RefreshType; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,6 +58,8 @@ public class ExecHandler extends BaseThingHandler { private Logger logger = LoggerFactory.getLogger(ExecHandler.class); + private final BundleContext bundleContext; + // List of Configurations constants public static final String INTERVAL = "interval"; public static final String TIME_OUT = "timeout"; @@ -73,6 +77,7 @@ public class ExecHandler extends BaseThingHandler { public ExecHandler(Thing thing) { super(thing); + this.bundleContext = FrameworkUtil.getBundle(ExecHandler.class).getBundleContext(); } @Override diff --git a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java index 14e8456678823..a88c4e49dc3ce 100644 --- a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java +++ b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java @@ -61,6 +61,8 @@ import org.openhab.binding.globalcache.internal.command.CommandSetstate; import org.openhab.binding.globalcache.internal.command.RequestMessage; import org.openhab.binding.globalcache.internal.command.ResponseMessage; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,6 +75,8 @@ public class GlobalCacheHandler extends BaseThingHandler { private Logger logger = LoggerFactory.getLogger(GlobalCacheHandler.class); + private final BundleContext bundleContext; + private static final String GLOBALCACHE_THREAD_POOL = "globalCacheHandler"; private InetAddress ifAddress; @@ -97,6 +101,7 @@ public GlobalCacheHandler(@NonNull Thing gcDevice, String ipv4Address) { commandProcessor = new CommandProcessor(); scheduledFuture = null; this.ipv4Address = ipv4Address; + this.bundleContext = FrameworkUtil.getBundle(GlobalCacheHandler.class).getBundleContext(); } @Override diff --git a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java index e5b06518b27ef..a1a8dfd45c310 100644 --- a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java +++ b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusDataThingHandler.java @@ -80,6 +80,8 @@ import org.openhab.io.transport.modbus.PollTask; import org.openhab.io.transport.modbus.endpoint.ModbusSlaveEndpoint; import org.openhab.io.transport.modbus.json.WriteRequestJsonUtilities; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,6 +101,8 @@ public class ModbusDataThingHandler extends BaseThingHandler implements ModbusRe private final Logger logger = LoggerFactory.getLogger(ModbusDataThingHandler.class); + private final BundleContext bundleContext; + private static final Duration MIN_STATUS_INFO_UPDATE_INTERVAL = Duration.ofSeconds(1); private static final Map>> CHANNEL_ID_TO_ACCEPTED_TYPES = new HashMap<>(); @@ -153,6 +157,7 @@ public class ModbusDataThingHandler extends BaseThingHandler implements ModbusRe public ModbusDataThingHandler(Thing thing) { super(thing); + this.bundleContext = FrameworkUtil.getBundle(ModbusDataThingHandler.class).getBundleContext(); } @Override diff --git a/bundles/org.openhab.binding.modbus/src/test/java/org/openhab/binding/modbus/internal/ModbusDataHandlerTest.java b/bundles/org.openhab.binding.modbus/src/test/java/org/openhab/binding/modbus/internal/ModbusDataHandlerTest.java index 29ce98ba10875..a63ac56ed796b 100644 --- a/bundles/org.openhab.binding.modbus/src/test/java/org/openhab/binding/modbus/internal/ModbusDataHandlerTest.java +++ b/bundles/org.openhab.binding.modbus/src/test/java/org/openhab/binding/modbus/internal/ModbusDataHandlerTest.java @@ -420,9 +420,6 @@ private ModbusDataThingHandler createDataHandler(String id, Bridge bridge, hookLinkRegistry(dataThingHandler); dataThing.setHandler(dataThingHandler); dataThingHandler.setCallback(thingCallback); - if (context != null) { - dataThingHandler.setBundleContext(context); - } dataThingHandler.initialize(); return dataThingHandler; }