Skip to content

Commit

Permalink
[tradfri] Fix NPE if gateway is unreachable (openhab#9629)
Browse files Browse the repository at this point in the history
Fixes openhab#9628

Signed-off-by: Stefan Triller <[email protected]>
  • Loading branch information
t2000 authored and thinkingstone committed Nov 7, 2021
1 parent 269cabe commit 8517b8f
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,21 @@ public synchronized void initialize() {
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);
Expand Down

0 comments on commit 8517b8f

Please sign in to comment.