Skip to content

Commit

Permalink
[innogysmarthome] Added guard against null value (openhab#6920)
Browse files Browse the repository at this point in the history
Fixes openhab#6918

Signed-off-by: Hilbrand Bouwkamp <[email protected]>
Signed-off-by: Daan Meijer <[email protected]>
  • Loading branch information
Hilbrand authored and DaanMeijer committed Sep 1, 2020
1 parent 87397b1 commit 7d66ffa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public void handleNewMessageReceivedEvent(final MessageEvent event)
logger.trace("Message: {}", gson.toJson(message));
logger.trace("Messagetype: {}", message.getType());
}
if (Message.TYPE_DEVICE_LOW_BATTERY.equals(message.getType())) {
if (Message.TYPE_DEVICE_LOW_BATTERY.equals(message.getType()) && message.getDeviceLinkList() != null) {
for (final String link : message.getDeviceLinkList()) {
deviceStructMan.refreshDevice(Link.getId(link));
final Device device = deviceStructMan.getDeviceById(Link.getId(link));
Expand Down Expand Up @@ -688,11 +688,17 @@ public void handleMessageDeletedEvent(final Event event) throws ApiException, IO

logger.debug("handleMessageDeletedEvent with messageId '{}'", messageId);
Device device = deviceStructMan.getDeviceWithMessageId(messageId);

if (device != null) {
deviceStructMan.refreshDevice(device.getId());
device = deviceStructMan.getDeviceById(device.getId());
for (final DeviceStatusListener deviceStatusListener : deviceStatusListeners) {
deviceStatusListener.onDeviceStateChanged(device);
String id = device.getId();
deviceStructMan.refreshDevice(id);
device = deviceStructMan.getDeviceById(id);
if (device != null) {
for (final DeviceStatusListener deviceStatusListener : deviceStatusListeners) {
deviceStatusListener.onDeviceStateChanged(device);
}
} else {
logger.debug("No device with id {} found after refresh.", id);
}
} else {
logger.debug("No device found with message id {}.", messageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void addDeviceToStructure(Device device) {
* @param id
* @return the {@link Device} or null, if it does not exist
*/
public Device getDeviceById(String id) {
public @Nullable Device getDeviceById(String id) {
logger.debug("getDeviceById {}:{}", id, getDeviceMap().containsKey(id));
return getDeviceMap().get(id);
}
Expand All @@ -177,7 +177,7 @@ public Device getDeviceById(String id) {
* @param capabilityId
* @return {@link Device} or null
*/
public Device getDeviceByCapabilityId(String capabilityId) {
public @Nullable Device getDeviceByCapabilityId(String capabilityId) {
return capabilityIdToDeviceMap.get(capabilityId);
}

Expand Down

0 comments on commit 7d66ffa

Please sign in to comment.