]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lgwebos] Fix representation property (#17588)
authorlsiepel <leosiepel@gmail.com>
Sat, 19 Oct 2024 15:08:13 +0000 (17:08 +0200)
committerGitHub <noreply@github.com>
Sat, 19 Oct 2024 15:08:13 +0000 (17:08 +0200)
* Fix representation property
* Null annotations and compiler fixes
* Fix lowercase

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/WakeOnLanUtility.java
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSHandler.java
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVKeyboardInput.java
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVSocket.java
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceCommand.java
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceSubscription.java

index 78a16cb3ac745d5421abfe6203168a71c88ddb2b..61efe3b34f29b6bb9357525ab4bf31233faac6ee 100644 (file)
@@ -20,6 +20,7 @@ import java.net.InterfaceAddress;
 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;
@@ -46,11 +47,11 @@ public class WakeOnLanUtility {
 
     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")) {
index 65ae982f1efa5f27756aed54166e0dde3ef6011a..43946294acc75b40fabbb18454580ab7847e41ed 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Collections;
 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;
@@ -357,7 +358,8 @@ public class LGWebOSHandler extends BaseThingHandler
         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);
         }
     }
@@ -405,6 +407,7 @@ public class LGWebOSHandler extends BaseThingHandler
     }
 
     public List<String> reportChannels() {
-        return ((TVControlChannel) channelHandlers.get(CHANNEL_CHANNEL)).reportChannels(getThing().getUID());
+        return ((TVControlChannel) Objects.requireNonNull(channelHandlers.get(CHANNEL_CHANNEL)))
+                .reportChannels(getThing().getUID());
     }
 }
index caa5cbefc3f1525c65ccdcbf05d4ec7a4343e7ea..3310e1ecd14d79a49e6dccbe6c9404a4ade40718 100644 (file)
@@ -35,6 +35,7 @@ package org.openhab.binding.lgwebos.internal.handler;
 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;
@@ -48,6 +49,8 @@ import com.google.gson.JsonObject;
  * @author Hyun Kook Khang - Connect SDK initial contribution
  * @author Sebastian Prehn - Adoption for openHAB
  */
+
+@NonNullByDefault
 public class LGWebOSTVKeyboardInput {
 
     private LGWebOSTVSocket service;
index 00b829aeff28498310d573a6301f97d39bdf0f3c..a285f833f62a9119d69d4efe90c709d5cad22348 100644 (file)
@@ -418,6 +418,10 @@ public class LGWebOSTVSocket {
     @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;
@@ -494,6 +498,7 @@ public class LGWebOSTVSocket {
                 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();
index 51088c9dd6e96d0589c5d9662166223f1f95e994..34f4eb1c222f535e9dbe09a50afa82e8a431cf82 100644 (file)
@@ -36,6 +36,7 @@ package org.openhab.binding.lgwebos.internal.handler.command;
 
 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;
 
@@ -48,6 +49,7 @@ import com.google.gson.JsonObject;
  * @author Hyun Kook Khang - Connect SDK initial contribution
  * @author Sebastian Prehn - Adoption for openHAB
  */
+@NonNullByDefault
 public class ServiceCommand<T> {
 
     protected enum Type {
@@ -56,13 +58,13 @@ public class ServiceCommand<T> {
     }
 
     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;
@@ -71,7 +73,7 @@ public class ServiceCommand<T> {
         this.type = Type.request;
     }
 
-    public JsonElement getPayload() {
+    public @Nullable JsonElement getPayload() {
         return payload;
     }
 
@@ -83,8 +85,10 @@ public class ServiceCommand<T> {
         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) {
index 6487f9285100bfef2b4ff03f8e02e5ceba748639..30f92c83e16eadcb9de1e99c5301a4708a93b90d 100644 (file)
@@ -35,6 +35,7 @@ package org.openhab.binding.lgwebos.internal.handler.command;
 
 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;
 
@@ -47,9 +48,10 @@ import com.google.gson.JsonObject;
  * @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;