[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
1 changed files with 11 additions and 10 deletions

View 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);