mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[tradfri] fix null pointer exception when sending command to a device that is offline (#12347)
* [tradfri] fix null pointer exception when sending command to thing that is offline * [tradfri] changed coapClient from @NinNullByDefault({}) to @Nullable Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
This commit is contained in:
parent
38c896edc5
commit
9fd87f52ef
@ -15,6 +15,7 @@ package org.openhab.binding.tradfri.internal.handler;
|
||||
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.tradfri.internal.TradfriCoapClient;
|
||||
import org.openhab.binding.tradfri.internal.model.TradfriBlindData;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
@ -86,8 +87,13 @@ public class TradfriBlindHandler extends TradfriThingHandler {
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (active) {
|
||||
if (command instanceof RefreshType) {
|
||||
TradfriCoapClient coapClient = this.coapClient;
|
||||
if (coapClient != null) {
|
||||
logger.debug("Refreshing channel {}", channelUID);
|
||||
coapClient.asyncGet(this);
|
||||
} else {
|
||||
logger.debug("coapClient is null!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.tradfri.internal.TradfriCoapClient;
|
||||
import org.openhab.binding.tradfri.internal.model.TradfriControllerData;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
@ -80,8 +81,13 @@ public class TradfriControllerHandler extends TradfriThingHandler {
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (active) {
|
||||
if (command instanceof RefreshType) {
|
||||
TradfriCoapClient coapClient = this.coapClient;
|
||||
if (coapClient != null) {
|
||||
logger.debug("Refreshing channel {}", channelUID);
|
||||
coapClient.asyncGet(this);
|
||||
} else {
|
||||
logger.debug("coapClient is null!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.tradfri.internal.TradfriCoapClient;
|
||||
import org.openhab.binding.tradfri.internal.model.TradfriLightData;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
import org.openhab.core.library.types.IncreaseDecreaseType;
|
||||
@ -126,8 +127,13 @@ public class TradfriLightHandler extends TradfriThingHandler {
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (active) {
|
||||
if (command instanceof RefreshType) {
|
||||
TradfriCoapClient coapClient = this.coapClient;
|
||||
if (coapClient != null) {
|
||||
logger.debug("Refreshing channel {}", channelUID);
|
||||
coapClient.asyncGet(this);
|
||||
} else {
|
||||
logger.debug("coapClient is null!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ package org.openhab.binding.tradfri.internal.handler;
|
||||
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.CHANNEL_POWER;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.tradfri.internal.TradfriCoapClient;
|
||||
import org.openhab.binding.tradfri.internal.model.TradfriPlugData;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
@ -62,8 +63,13 @@ public class TradfriPlugHandler extends TradfriThingHandler {
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (active) {
|
||||
if (command instanceof RefreshType) {
|
||||
TradfriCoapClient coapClient = this.coapClient;
|
||||
if (coapClient != null) {
|
||||
logger.debug("Refreshing channel {}", channelUID);
|
||||
coapClient.asyncGet(this);
|
||||
} else {
|
||||
logger.debug("coapClient is null!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ package org.openhab.binding.tradfri.internal.handler;
|
||||
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.tradfri.internal.TradfriCoapClient;
|
||||
import org.openhab.binding.tradfri.internal.model.TradfriSensorData;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
@ -71,8 +72,13 @@ public class TradfriSensorHandler extends TradfriThingHandler {
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (active) {
|
||||
if (command instanceof RefreshType) {
|
||||
TradfriCoapClient coapClient = this.coapClient;
|
||||
if (coapClient != null) {
|
||||
logger.debug("Refreshing channel {}", channelUID);
|
||||
coapClient.asyncGet(this);
|
||||
} else {
|
||||
logger.debug("coapClient is null!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public abstract class TradfriThingHandler extends BaseThingHandler implements Co
|
||||
// used to check whether we have already been disposed when receiving data asynchronously
|
||||
protected volatile boolean active;
|
||||
|
||||
protected @NonNullByDefault({}) TradfriCoapClient coapClient;
|
||||
protected @Nullable TradfriCoapClient coapClient;
|
||||
|
||||
private @Nullable CoapObserveRelation observeRelation;
|
||||
|
||||
@ -135,8 +135,13 @@ public abstract class TradfriThingHandler extends BaseThingHandler implements Co
|
||||
}
|
||||
|
||||
protected void set(String payload) {
|
||||
TradfriCoapClient coapClient = this.coapClient;
|
||||
if (coapClient != null) {
|
||||
logger.debug("Sending payload: {}", payload);
|
||||
coapClient.asyncPut(payload, this, scheduler);
|
||||
} else {
|
||||
logger.debug("coapClient is null!");
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateDeviceProperties(TradfriDeviceData state) {
|
||||
|
Loading…
Reference in New Issue
Block a user