[tesla] Removed dependency on org.apache.commons (#9815)

* Removed dependency on org.apache.commons

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2021-01-16 12:35:31 +01:00 committed by GitHub
parent c426d6de79
commit de3cacc603
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 13 deletions

View File

@ -40,7 +40,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.tesla.internal.TeslaBindingConstants;
import org.openhab.binding.tesla.internal.discovery.TeslaVehicleDiscoveryService;
import org.openhab.binding.tesla.internal.protocol.TokenRequest;
@ -223,7 +222,7 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
for (Vehicle vehicle : vehicleArray) {
String responseString = invokeAndParse(vehicle.id, VEHICLE_CONFIG, null, dataRequestTarget);
if (StringUtils.isBlank(responseString)) {
if (responseString == null || responseString.isBlank()) {
continue;
}
VehicleConfig vehicleConfig = gson.fromJson(responseString, VehicleConfig.class);
@ -274,8 +273,8 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
if (hasExpired) {
String username = (String) getConfig().get(CONFIG_USERNAME);
String refreshToken = (String) getConfig().get(CONFIG_REFRESHTOKEN);
if (refreshToken == null || StringUtils.isEmpty(refreshToken)) {
if (!StringUtils.isEmpty(username)) {
if (refreshToken == null || refreshToken.isEmpty()) {
if (username != null && !username.isEmpty()) {
String password = (String) getConfig().get(CONFIG_PASSWORD);
return authenticate(username, password);
} else {
@ -310,13 +309,13 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
updateConfiguration(configuration);
}
if (!StringUtils.isEmpty(tokenResponse.access_token)) {
if (tokenResponse.access_token != null && !tokenResponse.access_token.isEmpty()) {
this.logonToken = tokenResponse;
logger.trace("Access Token is {}", logonToken.access_token);
}
return new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
} else if (response.getStatus() == 401) {
if (!StringUtils.isEmpty(username)) {
if (username != null && !username.isEmpty()) {
String password = (String) getConfig().get(CONFIG_PASSWORD);
return authenticate(username, password);
} else {
@ -350,8 +349,7 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
if (response.getStatus() == 200 && response.hasEntity()) {
String responsePayLoad = response.readEntity(String.class);
TokenResponse tokenResponse = gson.fromJson(responsePayLoad.trim(), TokenResponse.class);
if (StringUtils.isNotEmpty(tokenResponse.access_token)) {
if (tokenResponse.token_type != null && !tokenResponse.access_token.isEmpty()) {
this.logonToken = tokenResponse;
Configuration cfg = editConfiguration();
cfg.put(TeslaBindingConstants.CONFIG_REFRESHTOKEN, logonToken.refresh_token);

View File

@ -21,6 +21,7 @@ import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -28,6 +29,7 @@ import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import javax.measure.quantity.Temperature;
import javax.ws.rs.ProcessingException;
@ -37,8 +39,6 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.tesla.internal.TeslaBindingConstants;
import org.openhab.binding.tesla.internal.TeslaBindingConstants.EventKeys;
@ -474,12 +474,12 @@ public class TeslaVehicleHandler extends BaseThingHandler {
}
@Override
protected void updateStatus(@NonNull ThingStatus status) {
protected void updateStatus(ThingStatus status) {
super.updateStatus(status);
}
@Override
protected void updateStatus(@NonNull ThingStatus status, @NonNull ThingStatusDetail statusDetail) {
protected void updateStatus(ThingStatus status, ThingStatusDetail statusDetail) {
super.updateStatus(status, statusDetail);
}
@ -991,7 +991,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
eventClient = clientBuilder.build()
.register(new Authenticator((String) getConfig().get(CONFIG_USERNAME), vehicle.tokens[0]));
eventTarget = eventClient.target(URI_EVENT).path(vehicle.vehicle_id + "/").queryParam("values",
StringUtils.join(EventKeys.values(), ',', 1, EventKeys.values().length));
Arrays.asList(EventKeys.values()).stream().skip(1).map(Enum::toString)
.collect(Collectors.joining(",")));
eventResponse = eventTarget.request(MediaType.TEXT_PLAIN_TYPE).get();
logger.debug("Event Stream: Establishing the event stream: Response: {}:{}",