From a6f6410b5c88cc8157f4528732fd8db304da88d1 Mon Sep 17 00:00:00 2001 From: J-N-K Date: Sun, 1 Nov 2020 21:29:47 +0100 Subject: [PATCH] fix NPE in discovery (#8931) Signed-off-by: Jan N. Klug --- .../org/openhab/binding/neato/internal/classes/Robot.java | 4 ++++ .../internal/discovery/NeatoAccountDiscoveryService.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/classes/Robot.java b/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/classes/Robot.java index 7cc4670bbcc..707fd5dfab0 100644 --- a/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/classes/Robot.java +++ b/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/classes/Robot.java @@ -148,4 +148,8 @@ public class Robot { public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } + + public boolean discoveryInformationPresent() { + return serial != null && secretKey != null && name != null && model != null; + } } diff --git a/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/discovery/NeatoAccountDiscoveryService.java b/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/discovery/NeatoAccountDiscoveryService.java index 70bc6f531c1..050fd8d3c09 100644 --- a/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/discovery/NeatoAccountDiscoveryService.java +++ b/bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/discovery/NeatoAccountDiscoveryService.java @@ -84,9 +84,14 @@ public class NeatoAccountDiscoveryService extends AbstractDiscoveryService { } private void addThing(Robot robot) { + if (robot == null || !robot.discoveryInformationPresent()) { + return; + } + logger.debug("addThing(): Adding new Neato unit {} to the smarthome inbox", robot.getName()); Map properties = new HashMap<>(); + String serial = robot.getSerial(); ThingUID thingUID = new ThingUID(NeatoBindingConstants.THING_TYPE_VACUUMCLEANER, bridgeUID, robot.getSerial()); properties.put(NeatoBindingConstants.CONFIG_SECRET, robot.getSecretKey()); properties.put(NeatoBindingConstants.CONFIG_SERIAL, robot.getSerial());