Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tradfri] fix null pointer exception when sending command to a device that is offline #12347

Merged
merged 2 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -86,8 +87,13 @@ private void triggerStop() {
public void handleCommand(ChannelUID channelUID, Command command) {
if (active) {
if (command instanceof RefreshType) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
TradfriCoapClient coapClient = this.coapClient;
if (coapClient != null) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
} else {
logger.debug("coapClient is null!");
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand Down Expand Up @@ -80,8 +81,13 @@ public void onUpdate(JsonElement data) {
public void handleCommand(ChannelUID channelUID, Command command) {
if (active) {
if (command instanceof RefreshType) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
TradfriCoapClient coapClient = this.coapClient;
if (coapClient != null) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
} else {
logger.debug("coapClient is null!");
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand Down Expand Up @@ -126,8 +127,13 @@ private void setColor(HSBType hsb) {
public void handleCommand(ChannelUID channelUID, Command command) {
if (active) {
if (command instanceof RefreshType) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
TradfriCoapClient coapClient = this.coapClient;
if (coapClient != null) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
} else {
logger.debug("coapClient is null!");
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -62,8 +63,13 @@ private void setState(OnOffType onOff) {
public void handleCommand(ChannelUID channelUID, Command command) {
if (active) {
if (command instanceof RefreshType) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
TradfriCoapClient coapClient = this.coapClient;
if (coapClient != null) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
} else {
logger.debug("coapClient is null!");
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -71,8 +72,13 @@ public void onUpdate(JsonElement data) {
public void handleCommand(ChannelUID channelUID, Command command) {
if (active) {
if (command instanceof RefreshType) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
TradfriCoapClient coapClient = this.coapClient;
if (coapClient != null) {
logger.debug("Refreshing channel {}", channelUID);
coapClient.asyncGet(this);
} else {
logger.debug("coapClient is null!");
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -135,8 +135,13 @@ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
}

protected void set(String payload) {
logger.debug("Sending payload: {}", payload);
coapClient.asyncPut(payload, this, scheduler);
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) {
Expand Down