]> git.basschouten.com Git - openhab-addons.git/commitdiff
[neato] Fix npe in discovery service. (#9561) (#9564)
authorJeff Lauterbach <jjlauterbach@gmail.com>
Tue, 12 Jan 2021 21:14:38 +0000 (15:14 -0600)
committerGitHub <noreply@github.com>
Tue, 12 Jan 2021 21:14:38 +0000 (22:14 +0100)
Signed-off-by: Jeff Lauterbach <jjlauterbach@gmail.com>
bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/discovery/NeatoAccountDiscoveryService.java

index ce925a89a85af306839c6f1c118b9ef2a2bef3ca..20241b4b2093e16d2b51b8a89041ae1f62f6a14a 100644 (file)
@@ -42,14 +42,15 @@ public class NeatoAccountDiscoveryService extends AbstractDiscoveryService {
 
     private static final int TIMEOUT = 15;
 
-    private NeatoAccountHandler handler;
-    private ThingUID bridgeUID;
+    private final NeatoAccountHandler handler;
+    private final ThingUID bridgeUID;
 
     private ScheduledFuture<?> scanTask;
 
     public NeatoAccountDiscoveryService(NeatoAccountHandler handler) {
         super(NeatoHandlerFactory.DISCOVERABLE_THING_TYPE_UIDS, TIMEOUT);
         this.handler = handler;
+        this.bridgeUID = handler.getThing().getUID();
     }
 
     private void findRobots() {
@@ -70,7 +71,7 @@ public class NeatoAccountDiscoveryService extends AbstractDiscoveryService {
         if (this.scanTask != null) {
             scanTask.cancel(true);
         }
-        this.scanTask = scheduler.schedule(() -> findRobots(), 0, TimeUnit.SECONDS);
+        this.scanTask = scheduler.schedule(this::findRobots, 0, TimeUnit.SECONDS);
     }
 
     @Override
@@ -88,17 +89,16 @@ public class NeatoAccountDiscoveryService extends AbstractDiscoveryService {
             return;
         }
 
-        logger.debug("addThing(): Adding new Neato unit {} to the inbox", robot.getName());
+        logger.debug("addThing(): Adding new Neato unit ({}) to the inbox", robot.getName());
 
         Map<String, Object> 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());
         properties.put(Thing.PROPERTY_MODEL_ID, robot.getModel());
         properties.put(NeatoBindingConstants.PROPERTY_NAME, robot.getName());
 
-        thingDiscovered(
-                DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID).withProperties(properties).build());
+        thingDiscovered(DiscoveryResultBuilder.create(thingUID).withLabel(robot.getName()).withBridge(bridgeUID)
+                .withProperties(properties).build());
     }
 }