import java.net.NetworkInterface;
import java.time.Duration;
import java.util.Enumeration;
+import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
private static final String COMMAND;
static {
- String os = System.getProperty("os.name").toLowerCase();
+ String os = Objects.requireNonNullElse(System.getProperty("os.name"), "").toLowerCase();
LOGGER.debug("os: {}", os);
- if ((os.contains("win"))) {
+ if (os.contains("win")) {
COMMAND = "arp -a %s";
- } else if ((os.contains("mac"))) {
+ } else if (os.contains("mac")) {
COMMAND = "arp %s";
} else { // linux
if (checkIfLinuxCommandExists("arp")) {
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
if (job == null || job.isCancelled()) {
logger.debug("Schedule channel subscription job");
channelSubscriptionJob = scheduler.schedule(
- () -> channelHandlers.get(CHANNEL_CHANNEL).refreshSubscription(CHANNEL_CHANNEL, this),
+ () -> Objects.requireNonNull(channelHandlers.get(CHANNEL_CHANNEL))
+ .refreshSubscription(CHANNEL_CHANNEL, this),
CHANNEL_SUBSCRIPTION_DELAY_SECONDS, TimeUnit.SECONDS);
}
}
}
public List<String> reportChannels() {
- return ((TVControlChannel) channelHandlers.get(CHANNEL_CHANNEL)).reportChannels(getThing().getUID());
+ return ((TVControlChannel) Objects.requireNonNull(channelHandlers.get(CHANNEL_CHANNEL)))
+ .reportChannels(getThing().getUID());
}
}
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.lgwebos.internal.handler.command.ServiceCommand;
import org.openhab.binding.lgwebos.internal.handler.command.ServiceSubscription;
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
* @author Hyun Kook Khang - Connect SDK initial contribution
* @author Sebastian Prehn - Adoption for openHAB
*/
+
+@NonNullByDefault
public class LGWebOSTVKeyboardInput {
private LGWebOSTVSocket service;
@OnWebSocketMessage
public void onMessage(String message) {
Response response = GSON.fromJson(message, Response.class);
+ if (response == null) {
+ logger.warn("Received an unexpected null response. Ignoring the response");
+ return;
+ }
JsonElement payload = response.getPayload();
JsonObject jsonPayload = payload == null ? null : payload.getAsJsonObject();
String messageToLog = (jsonPayload != null && jsonPayload.has("client-key")) ? "***" : message;
map.put(PROPERTY_DEVICE_OS, jsonPayload.get("deviceOS").getAsString());
map.put(PROPERTY_DEVICE_OS_VERSION, jsonPayload.get("deviceOSVersion").getAsString());
map.put(PROPERTY_DEVICE_OS_RELEASE_VERSION, jsonPayload.get("deviceOSReleaseVersion").getAsString());
+ map.put(PROPERTY_DEVICE_ID, jsonPayload.get("deviceUUID").getAsString());
map.put(PROPERTY_LAST_CONNECTED, Instant.now().toString());
config.storeProperties(map);
sendRegister();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
* @author Hyun Kook Khang - Connect SDK initial contribution
* @author Sebastian Prehn - Adoption for openHAB
*/
+@NonNullByDefault
public class ServiceCommand<T> {
protected enum Type {
}
protected Type type;
- protected JsonObject payload;
+ protected @Nullable JsonObject payload;
protected String target;
protected Function<JsonObject, @Nullable T> converter;
ResponseListener<T> responseListener;
- public ServiceCommand(String targetURL, JsonObject payload, Function<JsonObject, @Nullable T> converter,
+ public ServiceCommand(String targetURL, @Nullable JsonObject payload, Function<JsonObject, @Nullable T> converter,
ResponseListener<T> listener) {
this.target = targetURL;
this.payload = payload;
this.type = Type.request;
}
- public JsonElement getPayload() {
+ public @Nullable JsonElement getPayload() {
return payload;
}
return target;
}
- public void processResponse(JsonObject response) {
- this.getResponseListener().onSuccess(this.converter.apply(response));
+ public void processResponse(@Nullable JsonObject response) {
+ if (response != null) {
+ this.getResponseListener().onSuccess(this.converter.apply(response));
+ }
}
public void processError(String error) {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
* @author Hyun Kook Khang - Connect SDK initial contribution
* @author Sebastian Prehn - Adoption for openHAB
*/
+@NonNullByDefault
public class ServiceSubscription<T> extends ServiceCommand<T> {
- public ServiceSubscription(String uri, JsonObject payload, Function<JsonObject, @Nullable T> converter,
+ public ServiceSubscription(String uri, @Nullable JsonObject payload, Function<JsonObject, @Nullable T> converter,
ResponseListener<T> listener) {
super(uri, payload, converter, listener);
type = Type.subscribe;