[tradfri] Fix NPE if gateway is unreachable (#9629)

Fixes #9628

Signed-off-by: Stefan Triller <github@stefantriller.de>
This commit is contained in:
t2000 2021-01-01 21:45:55 +01:00 committed by GitHub
parent d3ae64140f
commit 572da80fd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,6 +66,10 @@ public abstract class TradfriThingHandler extends BaseThingHandler implements Co
this.id = getConfigAs(TradfriDeviceConfig.class).id; this.id = getConfigAs(TradfriDeviceConfig.class).id;
TradfriGatewayHandler handler = (TradfriGatewayHandler) tradfriGateway.getHandler(); TradfriGatewayHandler handler = (TradfriGatewayHandler) tradfriGateway.getHandler();
active = true;
updateStatus(ThingStatus.UNKNOWN);
switch (tradfriGateway.getStatus()) {
case ONLINE:
String uriString = handler.getGatewayURI() + "/" + id; String uriString = handler.getGatewayURI() + "/" + id;
try { try {
URI uri = new URI(uriString); URI uri = new URI(uriString);
@ -76,10 +80,7 @@ public abstract class TradfriThingHandler extends BaseThingHandler implements Co
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
return; return;
} }
active = true;
updateStatus(ThingStatus.UNKNOWN);
switch (tradfriGateway.getStatus()) {
case ONLINE:
scheduler.schedule(() -> { scheduler.schedule(() -> {
observeRelation = coapClient.startObserve(this); observeRelation = coapClient.startObserve(this);
}, 3, TimeUnit.SECONDS); }, 3, TimeUnit.SECONDS);