]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tradfri] Fix NPE if gateway is unreachable (#9629)
authort2000 <t2000@users.noreply.github.com>
Fri, 1 Jan 2021 20:45:55 +0000 (21:45 +0100)
committerGitHub <noreply@github.com>
Fri, 1 Jan 2021 20:45:55 +0000 (21:45 +0100)
Fixes #9628

Signed-off-by: Stefan Triller <github@stefantriller.de>
bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriThingHandler.java

index 540f4bb8ddae21e43987dbb7f3a09a3bae0def3e..8596fb53fa37845a8a4ecc76c82272602adc04dc 100644 (file)
@@ -66,20 +66,21 @@ public abstract class TradfriThingHandler extends BaseThingHandler implements Co
         this.id = getConfigAs(TradfriDeviceConfig.class).id;
         TradfriGatewayHandler handler = (TradfriGatewayHandler) tradfriGateway.getHandler();
 
-        String uriString = handler.getGatewayURI() + "/" + id;
-        try {
-            URI uri = new URI(uriString);
-            coapClient = new TradfriCoapClient(uri);
-            coapClient.setEndpoint(handler.getEndpoint());
-        } catch (URISyntaxException e) {
-            logger.debug("Illegal device URI `{}`: {}", uriString, e.getMessage());
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
-            return;
-        }
         active = true;
         updateStatus(ThingStatus.UNKNOWN);
         switch (tradfriGateway.getStatus()) {
             case ONLINE:
+                String uriString = handler.getGatewayURI() + "/" + id;
+                try {
+                    URI uri = new URI(uriString);
+                    coapClient = new TradfriCoapClient(uri);
+                    coapClient.setEndpoint(handler.getEndpoint());
+                } catch (URISyntaxException e) {
+                    logger.debug("Illegal device URI `{}`: {}", uriString, e.getMessage());
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
+                    return;
+                }
+
                 scheduler.schedule(() -> {
                     observeRelation = coapClient.startObserve(this);
                 }, 3, TimeUnit.SECONDS);