From 6c7354b49e19554531d29c102be348c54f70e4ce Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sun, 26 Feb 2023 10:24:46 +0100 Subject: [PATCH] [innogysmarthome] Remove org.apache.commons (#14407) Signed-off-by: lsiepel --- .../client/entity/action/ShutterAction.java | 2 +- .../internal/handler/InnogyBridgeHandler.java | 4 +- .../internal/manager/FullDeviceManager.java | 5 --- .../internal/util/ExceptionUtils.java | 39 +++++++++++++++++++ .../handler/InnogyBridgeHandlerTest.java | 11 ++++++ 5 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/util/ExceptionUtils.java diff --git a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/client/entity/action/ShutterAction.java b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/client/entity/action/ShutterAction.java index 62c24320ae3a7..351db4db727f8 100644 --- a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/client/entity/action/ShutterAction.java +++ b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/client/entity/action/ShutterAction.java @@ -15,7 +15,7 @@ /** * Special {@link Action} needed to control shutters. * - * @author Marco Mans + * @author Marco Mans - Initial contribution */ public class ShutterAction extends Action { diff --git a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java index 528bfb8831caa..c82b8ae7ffc0c 100644 --- a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java +++ b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java @@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; @@ -58,6 +57,7 @@ import org.openhab.binding.innogysmarthome.internal.listener.EventListener; import org.openhab.binding.innogysmarthome.internal.manager.DeviceStructureManager; import org.openhab.binding.innogysmarthome.internal.manager.FullDeviceManager; +import org.openhab.binding.innogysmarthome.internal.util.ExceptionUtils; import org.openhab.core.auth.client.oauth2.AccessTokenRefreshListener; import org.openhab.core.auth.client.oauth2.AccessTokenResponse; import org.openhab.core.auth.client.oauth2.OAuthClientService; @@ -954,7 +954,7 @@ private boolean handleClientException(final Exception e) { isReinitialize = false; Thread.currentThread().interrupt(); } else if (e instanceof ExecutionException) { - logger.debug("ExecutionException: {}", ExceptionUtils.getRootCauseMessage(e)); + logger.debug("ExecutionException: {}", ExceptionUtils.getRootThrowable(e).getMessage()); updateStatus(ThingStatus.OFFLINE); } else { logger.debug("Unknown exception", e); diff --git a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/FullDeviceManager.java b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/FullDeviceManager.java index 4628c311cc6d6..a50e428257ede 100644 --- a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/FullDeviceManager.java +++ b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/FullDeviceManager.java @@ -56,7 +56,6 @@ public FullDeviceManager(InnogyClient client) { * states. Calling this may take a while... */ public List getFullDevices() throws IOException, ApiException, AuthenticationException { - final Map locationMap = createLocationMap(client); final Map capabilityMap = createCapabilityMap(client); final Map deviceStateMap = createDeviceStateMap(client); @@ -91,7 +90,6 @@ public Device getFullDeviceById(final String deviceId) throws IOException, ApiEx private void initializeDevice(Device device, @Nullable DeviceState deviceState, Map locationMap, Map capabilityMap, List messageList) { - device.setDeviceState(deviceState); if (isBatteryPowered(device)) { @@ -135,7 +133,6 @@ private static Map createCapabilityStateMap(InnogyClien private static Map createCapabilityMap(InnogyClient client) throws IOException, ApiException, AuthenticationException { - final Map capabilityStateMap = createCapabilityStateMap(client); final List capabilityList = client.getCapabilities(); @@ -144,7 +141,6 @@ private static Map createCapabilityMap(InnogyClient client) private static Map createCapabilityMap(String deviceId, InnogyClient client) throws IOException, ApiException, AuthenticationException { - final Map capabilityStateMap = createCapabilityStateMap(client); final List capabilityList = client.getCapabilitiesForDevice(deviceId); @@ -167,7 +163,6 @@ private static Map initializeCapabilities(Map createDeviceCapabilityMap(Device device, Map capabilityMap) { - final HashMap deviceCapabilityMap = new HashMap<>(); for (final String capabilityValue : device.getCapabilities()) { final Capability capability = capabilityMap.get(Link.getId(capabilityValue)); diff --git a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/util/ExceptionUtils.java b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/util/ExceptionUtils.java new file mode 100644 index 0000000000000..6761f5b02959f --- /dev/null +++ b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/util/ExceptionUtils.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2010-2023 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.binding.innogysmarthome.internal.util; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link ExceptionUtils} class defines static Exception related methods + * + * @author Leo Siepel - Initial contribution + */ +@NonNullByDefault +public class ExceptionUtils { + + public static Throwable getRootThrowable(Throwable throwable) { + List list = new ArrayList<>(); + while (!list.contains(throwable)) { + list.add(throwable); + Throwable throwableLocal = throwable.getCause(); + if (throwableLocal != null) { + throwable = throwableLocal; + } + } + return throwable; + } +} diff --git a/bundles/org.openhab.binding.innogysmarthome/src/test/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandlerTest.java b/bundles/org.openhab.binding.innogysmarthome/src/test/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandlerTest.java index a07030a04110d..83847ae0da14f 100644 --- a/bundles/org.openhab.binding.innogysmarthome/src/test/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandlerTest.java +++ b/bundles/org.openhab.binding.innogysmarthome/src/test/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandlerTest.java @@ -36,6 +36,11 @@ import org.openhab.core.config.core.Configuration; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ThingUID; +import org.openhab.core.thing.binding.BaseThingHandler; +import org.slf4j.LoggerFactory; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; /** * @author Sven Strohschein - Initial contribution @@ -50,6 +55,12 @@ public class InnogyBridgeHandlerTest { @BeforeEach public void before() throws Exception { + final Logger loggerBridge = (Logger) LoggerFactory.getLogger(InnogyBridgeHandler.class); + loggerBridge.setLevel(Level.OFF); + + final Logger logerBaseHandler = (Logger) LoggerFactory.getLogger(BaseThingHandler.class); + logerBaseHandler.setLevel(Level.OFF); + bridgeMock = mock(Bridge.class); when(bridgeMock.getUID()).thenReturn(new ThingUID("innogysmarthome", "bridge"));