Skip to content

Commit 6ec28a8

Browse files
authored
[lgwebos] Fix representation property (openhab#17588)
* Fix representation property * Null annotations and compiler fixes * Fix lowercase Signed-off-by: Leo Siepel <[email protected]>
1 parent 455330e commit 6ec28a8

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/WakeOnLanUtility.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.net.NetworkInterface;
2121
import java.time.Duration;
2222
import java.util.Enumeration;
23+
import java.util.Objects;
2324
import java.util.regex.Matcher;
2425
import java.util.regex.Pattern;
2526
import java.util.stream.Stream;
@@ -46,11 +47,11 @@ public class WakeOnLanUtility {
4647

4748
private static final String COMMAND;
4849
static {
49-
String os = System.getProperty("os.name").toLowerCase();
50+
String os = Objects.requireNonNullElse(System.getProperty("os.name"), "").toLowerCase();
5051
LOGGER.debug("os: {}", os);
51-
if ((os.contains("win"))) {
52+
if (os.contains("win")) {
5253
COMMAND = "arp -a %s";
53-
} else if ((os.contains("mac"))) {
54+
} else if (os.contains("mac")) {
5455
COMMAND = "arp %s";
5556
} else { // linux
5657
if (checkIfLinuxCommandExists("arp")) {

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSHandler.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.List;
2323
import java.util.Map;
24+
import java.util.Objects;
2425
import java.util.Set;
2526
import java.util.concurrent.ScheduledFuture;
2627
import java.util.concurrent.TimeUnit;
@@ -357,7 +358,8 @@ private void scheduleChannelSubscriptionJob() {
357358
if (job == null || job.isCancelled()) {
358359
logger.debug("Schedule channel subscription job");
359360
channelSubscriptionJob = scheduler.schedule(
360-
() -> channelHandlers.get(CHANNEL_CHANNEL).refreshSubscription(CHANNEL_CHANNEL, this),
361+
() -> Objects.requireNonNull(channelHandlers.get(CHANNEL_CHANNEL))
362+
.refreshSubscription(CHANNEL_CHANNEL, this),
361363
CHANNEL_SUBSCRIPTION_DELAY_SECONDS, TimeUnit.SECONDS);
362364
}
363365
}
@@ -405,6 +407,7 @@ public List<String> reportApplications() {
405407
}
406408

407409
public List<String> reportChannels() {
408-
return ((TVControlChannel) channelHandlers.get(CHANNEL_CHANNEL)).reportChannels(getThing().getUID());
410+
return ((TVControlChannel) Objects.requireNonNull(channelHandlers.get(CHANNEL_CHANNEL)))
411+
.reportChannels(getThing().getUID());
409412
}
410413
}

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVKeyboardInput.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.ArrayList;
3636
import java.util.List;
3737

38+
import org.eclipse.jdt.annotation.NonNullByDefault;
3839
import org.openhab.binding.lgwebos.internal.handler.command.ServiceCommand;
3940
import org.openhab.binding.lgwebos.internal.handler.command.ServiceSubscription;
4041
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
@@ -48,6 +49,8 @@
4849
* @author Hyun Kook Khang - Connect SDK initial contribution
4950
* @author Sebastian Prehn - Adoption for openHAB
5051
*/
52+
53+
@NonNullByDefault
5154
public class LGWebOSTVKeyboardInput {
5255

5356
private LGWebOSTVSocket service;

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/LGWebOSTVSocket.java

+5
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ private JsonObject maskKeyInJson(JsonObject json) {
418418
@OnWebSocketMessage
419419
public void onMessage(String message) {
420420
Response response = GSON.fromJson(message, Response.class);
421+
if (response == null) {
422+
logger.warn("Received an unexpected null response. Ignoring the response");
423+
return;
424+
}
421425
JsonElement payload = response.getPayload();
422426
JsonObject jsonPayload = payload == null ? null : payload.getAsJsonObject();
423427
String messageToLog = (jsonPayload != null && jsonPayload.has("client-key")) ? "***" : message;
@@ -494,6 +498,7 @@ public void onMessage(String message) {
494498
map.put(PROPERTY_DEVICE_OS, jsonPayload.get("deviceOS").getAsString());
495499
map.put(PROPERTY_DEVICE_OS_VERSION, jsonPayload.get("deviceOSVersion").getAsString());
496500
map.put(PROPERTY_DEVICE_OS_RELEASE_VERSION, jsonPayload.get("deviceOSReleaseVersion").getAsString());
501+
map.put(PROPERTY_DEVICE_ID, jsonPayload.get("deviceUUID").getAsString());
497502
map.put(PROPERTY_LAST_CONNECTED, Instant.now().toString());
498503
config.storeProperties(map);
499504
sendRegister();

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceCommand.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import java.util.function.Function;
3838

39+
import org.eclipse.jdt.annotation.NonNullByDefault;
3940
import org.eclipse.jdt.annotation.Nullable;
4041
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
4142

@@ -48,6 +49,7 @@
4849
* @author Hyun Kook Khang - Connect SDK initial contribution
4950
* @author Sebastian Prehn - Adoption for openHAB
5051
*/
52+
@NonNullByDefault
5153
public class ServiceCommand<T> {
5254

5355
protected enum Type {
@@ -56,13 +58,13 @@ protected enum Type {
5658
}
5759

5860
protected Type type;
59-
protected JsonObject payload;
61+
protected @Nullable JsonObject payload;
6062
protected String target;
6163
protected Function<JsonObject, @Nullable T> converter;
6264

6365
ResponseListener<T> responseListener;
6466

65-
public ServiceCommand(String targetURL, JsonObject payload, Function<JsonObject, @Nullable T> converter,
67+
public ServiceCommand(String targetURL, @Nullable JsonObject payload, Function<JsonObject, @Nullable T> converter,
6668
ResponseListener<T> listener) {
6769
this.target = targetURL;
6870
this.payload = payload;
@@ -71,7 +73,7 @@ public ServiceCommand(String targetURL, JsonObject payload, Function<JsonObject,
7173
this.type = Type.request;
7274
}
7375

74-
public JsonElement getPayload() {
76+
public @Nullable JsonElement getPayload() {
7577
return payload;
7678
}
7779

@@ -83,8 +85,10 @@ public String getTarget() {
8385
return target;
8486
}
8587

86-
public void processResponse(JsonObject response) {
87-
this.getResponseListener().onSuccess(this.converter.apply(response));
88+
public void processResponse(@Nullable JsonObject response) {
89+
if (response != null) {
90+
this.getResponseListener().onSuccess(this.converter.apply(response));
91+
}
8892
}
8993

9094
public void processError(String error) {

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/handler/command/ServiceSubscription.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import java.util.function.Function;
3737

38+
import org.eclipse.jdt.annotation.NonNullByDefault;
3839
import org.eclipse.jdt.annotation.Nullable;
3940
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
4041

@@ -47,9 +48,10 @@
4748
* @author Hyun Kook Khang - Connect SDK initial contribution
4849
* @author Sebastian Prehn - Adoption for openHAB
4950
*/
51+
@NonNullByDefault
5052
public class ServiceSubscription<T> extends ServiceCommand<T> {
5153

52-
public ServiceSubscription(String uri, JsonObject payload, Function<JsonObject, @Nullable T> converter,
54+
public ServiceSubscription(String uri, @Nullable JsonObject payload, Function<JsonObject, @Nullable T> converter,
5355
ResponseListener<T> listener) {
5456
super(uri, payload, converter, listener);
5557
type = Type.subscribe;

0 commit comments

Comments
 (0)