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;
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);
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 {
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 {
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);
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;
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;
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;
}
@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);
}
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: {}:{}",