mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[ecobee] Remove org.apache.commons (#14403)
Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
parent
19db9ee726
commit
1c35ebcd4e
@ -26,7 +26,6 @@ import java.util.Properties;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
@ -46,6 +45,7 @@ import org.openhab.binding.ecobee.internal.dto.thermostat.summary.RunningDTODese
|
|||||||
import org.openhab.binding.ecobee.internal.dto.thermostat.summary.SummaryResponseDTO;
|
import org.openhab.binding.ecobee.internal.dto.thermostat.summary.SummaryResponseDTO;
|
||||||
import org.openhab.binding.ecobee.internal.function.FunctionRequest;
|
import org.openhab.binding.ecobee.internal.function.FunctionRequest;
|
||||||
import org.openhab.binding.ecobee.internal.handler.EcobeeAccountBridgeHandler;
|
import org.openhab.binding.ecobee.internal.handler.EcobeeAccountBridgeHandler;
|
||||||
|
import org.openhab.binding.ecobee.internal.util.ExceptionUtils;
|
||||||
import org.openhab.core.auth.client.oauth2.AccessTokenRefreshListener;
|
import org.openhab.core.auth.client.oauth2.AccessTokenRefreshListener;
|
||||||
import org.openhab.core.auth.client.oauth2.AccessTokenResponse;
|
import org.openhab.core.auth.client.oauth2.AccessTokenResponse;
|
||||||
import org.openhab.core.auth.client.oauth2.OAuthClientService;
|
import org.openhab.core.auth.client.oauth2.OAuthClientService;
|
||||||
@ -315,7 +315,7 @@ public class EcobeeApi implements AccessTokenRefreshListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void logIOException(Exception e) {
|
private void logIOException(Exception e) {
|
||||||
Throwable rootCause = ExceptionUtils.getRootCause(e);
|
Throwable rootCause = ExceptionUtils.getRootThrowable(e);
|
||||||
if (rootCause instanceof TimeoutException || rootCause instanceof EOFException) {
|
if (rootCause instanceof TimeoutException || rootCause instanceof EOFException) {
|
||||||
// These are "normal" errors and should be logged as DEBUG
|
// These are "normal" errors and should be logged as DEBUG
|
||||||
logger.debug("API: Call to Ecobee API failed with exception: {}: {}", rootCause.getClass().getSimpleName(),
|
logger.debug("API: Call to Ecobee API failed with exception: {}: {}", rootCause.getClass().getSimpleName(),
|
||||||
|
@ -18,7 +18,6 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
@ -29,6 +28,7 @@ import org.eclipse.jetty.http.HttpStatus;
|
|||||||
import org.openhab.binding.ecobee.internal.dto.oauth.AuthorizeResponseDTO;
|
import org.openhab.binding.ecobee.internal.dto.oauth.AuthorizeResponseDTO;
|
||||||
import org.openhab.binding.ecobee.internal.dto.oauth.TokenResponseDTO;
|
import org.openhab.binding.ecobee.internal.dto.oauth.TokenResponseDTO;
|
||||||
import org.openhab.binding.ecobee.internal.handler.EcobeeAccountBridgeHandler;
|
import org.openhab.binding.ecobee.internal.handler.EcobeeAccountBridgeHandler;
|
||||||
|
import org.openhab.binding.ecobee.internal.util.ExceptionUtils;
|
||||||
import org.openhab.core.auth.client.oauth2.AccessTokenResponse;
|
import org.openhab.core.auth.client.oauth2.AccessTokenResponse;
|
||||||
import org.openhab.core.auth.client.oauth2.OAuthClientService;
|
import org.openhab.core.auth.client.oauth2.OAuthClientService;
|
||||||
import org.openhab.core.auth.client.oauth2.OAuthException;
|
import org.openhab.core.auth.client.oauth2.OAuthException;
|
||||||
@ -254,7 +254,7 @@ public class EcobeeAuth {
|
|||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
logger.debug("TimeoutException: Call to Ecobee API timed out");
|
logger.debug("TimeoutException: Call to Ecobee API timed out");
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
if (ExceptionUtils.getRootCause(e) instanceof HttpResponseException) {
|
if (ExceptionUtils.getRootThrowable(e) instanceof HttpResponseException) {
|
||||||
logger.info("Awaiting entry of PIN in Ecobee portal. Expires in {} minutes",
|
logger.info("Awaiting entry of PIN in Ecobee portal. Expires in {} minutes",
|
||||||
getMinutesUntilPinExpiration());
|
getMinutesUntilPinExpiration());
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,11 +17,11 @@ import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.WordUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.binding.ecobee.internal.config.EcobeeSensorConfiguration;
|
import org.openhab.binding.ecobee.internal.config.EcobeeSensorConfiguration;
|
||||||
import org.openhab.binding.ecobee.internal.dto.thermostat.RemoteSensorCapabilityDTO;
|
import org.openhab.binding.ecobee.internal.dto.thermostat.RemoteSensorCapabilityDTO;
|
||||||
import org.openhab.binding.ecobee.internal.dto.thermostat.RemoteSensorDTO;
|
import org.openhab.binding.ecobee.internal.dto.thermostat.RemoteSensorDTO;
|
||||||
|
import org.openhab.binding.ecobee.internal.util.StringUtils;
|
||||||
import org.openhab.core.library.unit.Units;
|
import org.openhab.core.library.unit.Units;
|
||||||
import org.openhab.core.thing.Channel;
|
import org.openhab.core.thing.Channel;
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
@ -126,7 +126,7 @@ public class EcobeeSensorThingHandler extends BaseThingHandler {
|
|||||||
ThingBuilder thingBuilder;
|
ThingBuilder thingBuilder;
|
||||||
thingBuilder = editThing();
|
thingBuilder = editThing();
|
||||||
channel = ChannelBuilder.create(uid, getAcceptedItemType(capability.type))
|
channel = ChannelBuilder.create(uid, getAcceptedItemType(capability.type))
|
||||||
.withLabel("Sensor " + WordUtils.capitalize(capability.type))
|
.withLabel("Sensor " + StringUtils.capitalizeWords(capability.type))
|
||||||
.withType(getChannelTypeUID(capability.type)).build();
|
.withType(getChannelTypeUID(capability.type)).build();
|
||||||
thingBuilder.withChannel(channel);
|
thingBuilder.withChannel(channel);
|
||||||
updateThing(thingBuilder.build());
|
updateThing(thingBuilder.build());
|
||||||
|
@ -25,7 +25,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
|
|
||||||
import javax.measure.Unit;
|
import javax.measure.Unit;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.WordUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.ecobee.internal.action.EcobeeActions;
|
import org.openhab.binding.ecobee.internal.action.EcobeeActions;
|
||||||
@ -50,6 +49,7 @@ import org.openhab.binding.ecobee.internal.dto.thermostat.WeatherDTO;
|
|||||||
import org.openhab.binding.ecobee.internal.dto.thermostat.WeatherForecastDTO;
|
import org.openhab.binding.ecobee.internal.dto.thermostat.WeatherForecastDTO;
|
||||||
import org.openhab.binding.ecobee.internal.function.AbstractFunction;
|
import org.openhab.binding.ecobee.internal.function.AbstractFunction;
|
||||||
import org.openhab.binding.ecobee.internal.function.FunctionRequest;
|
import org.openhab.binding.ecobee.internal.function.FunctionRequest;
|
||||||
|
import org.openhab.binding.ecobee.internal.util.StringUtils;
|
||||||
import org.openhab.core.i18n.TimeZoneProvider;
|
import org.openhab.core.i18n.TimeZoneProvider;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
import org.openhab.core.library.types.DecimalType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
@ -179,7 +179,7 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler {
|
|||||||
for (Channel channel : thing.getChannelsOfGroup(group)) {
|
for (Channel channel : thing.getChannelsOfGroup(group)) {
|
||||||
if (isLinked(channel.getUID())) {
|
if (isLinked(channel.getUID())) {
|
||||||
try {
|
try {
|
||||||
Field field = selection.getClass().getField("include" + WordUtils.capitalize(group));
|
Field field = selection.getClass().getField("include" + StringUtils.capitalizeWords(group));
|
||||||
logger.trace("ThermostatBridge: Thermostat thing '{}' including object '{}' in selection",
|
logger.trace("ThermostatBridge: Thermostat thing '{}' including object '{}' in selection",
|
||||||
thing.getUID(), field.getName());
|
thing.getUID(), field.getName());
|
||||||
field.set(selection, Boolean.TRUE);
|
field.set(selection, Boolean.TRUE);
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* 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.ecobee.internal.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link ExceptionUtils} class defines static Exception related methods
|
||||||
|
*
|
||||||
|
* @author Leo Siepel - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class ExceptionUtils {
|
||||||
|
|
||||||
|
public static @Nullable Throwable getRootThrowable(@Nullable Throwable throwable) {
|
||||||
|
List<Throwable> list = new ArrayList<>();
|
||||||
|
while (throwable != null && !list.contains(throwable)) {
|
||||||
|
list.add(throwable);
|
||||||
|
throwable = throwable.getCause();
|
||||||
|
}
|
||||||
|
return throwable;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* 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.ecobee.internal.util;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link StringUtils} class defines static string related methods
|
||||||
|
*
|
||||||
|
* @author Leo Siepel - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class StringUtils {
|
||||||
|
|
||||||
|
public static String capitalizeWords(@Nullable String input) {
|
||||||
|
String output = "";
|
||||||
|
if (input != null) {
|
||||||
|
String[] splitted = input.split("\\s+");
|
||||||
|
String[] processed = new String[splitted.length];
|
||||||
|
for (int wordIndex = 0; wordIndex < splitted.length; wordIndex++) {
|
||||||
|
if (splitted[wordIndex].length() > 1) {
|
||||||
|
processed[wordIndex] = splitted[wordIndex].substring(0, 1).toUpperCase()
|
||||||
|
+ splitted[wordIndex].substring(1);
|
||||||
|
} else {
|
||||||
|
processed[wordIndex] = splitted[wordIndex].toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output = String.join(" ", processed);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user