From dd8eb4701e1a7d152d77ebab6b2024d4b6c8f128 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Fri, 30 Dec 2022 02:23:45 -0600 Subject: [PATCH] [bondhome] Fix fatal Null Pointer errors (#14103) * Fix fatal Null Pointer errors Signed-off-by: Michael Lobstein --- .../binding/bondhome/internal/api/BondDeviceType.java | 1 + .../openhab/binding/bondhome/internal/api/BondHttpApi.java | 6 ++++-- .../bondhome/internal/discovery/BondDiscoveryService.java | 2 +- .../src/main/resources/OH-INF/i18n/bondhome.properties | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondDeviceType.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondDeviceType.java index e22517437c..e8003e8332 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondDeviceType.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondDeviceType.java @@ -35,6 +35,7 @@ public enum BondDeviceType { FIREPLACE(THING_TYPE_BOND_FIREPLACE), @SerializedName("GX") GENERIC_DEVICE(THING_TYPE_BOND_GENERIC); + // TODO: add Light ("LT") type private ThingTypeUID deviceTypeUid; diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java index c9fd6cd22e..7338d2c321 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java @@ -120,7 +120,9 @@ public class BondHttpApi { String json = request("/v2/devices/" + deviceId); logger.trace("BondHome device info : {}", json); try { - return Objects.requireNonNull(gson.fromJson(json, BondDevice.class)); + BondDevice device = Objects.requireNonNull(gson.fromJson(json, BondDevice.class)); + device.actions.removeIf(Objects::isNull); + return device; } catch (JsonParseException e) { logger.debug("Could not parse device {}'s JSON '{}'", deviceId, json, e); throw new BondException("@text/offline.comm-error.unparseable-response"); @@ -250,7 +252,7 @@ public class BondHttpApi { logger.debug("Repeated Bond API calls to {} failed.", uri); bridgeHandler.setBridgeOffline(ThingStatusDetail.COMMUNICATION_ERROR, "@text/offline.comm-error.api-call-failed"); - throw new BondException("@text/offline.conf-error.api-call-failed", true); + throw new BondException("@text/offline.comm-error.api-call-failed", true); } } } while (true); diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java index 46d6dd0546..b839898a0d 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java @@ -96,7 +96,7 @@ public class BondDiscoveryService extends AbstractDiscoveryService implements Th for (final String deviceId : deviceList) { BondDevice thisDevice = api.getDevice(deviceId); String deviceName; - if ((deviceName = thisDevice.name) != null) { + if (thisDevice.type != null && (deviceName = thisDevice.name) != null) { final ThingUID deviceUid = new ThingUID(thisDevice.type.getThingTypeUID(), bridgeUid, deviceId); final DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(deviceUid) .withBridge(bridgeUid).withLabel(thisDevice.name) diff --git a/bundles/org.openhab.binding.bondhome/src/main/resources/OH-INF/i18n/bondhome.properties b/bundles/org.openhab.binding.bondhome/src/main/resources/OH-INF/i18n/bondhome.properties index b102047a2c..3c0e779f91 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/resources/OH-INF/i18n/bondhome.properties +++ b/bundles/org.openhab.binding.bondhome/src/main/resources/OH-INF/i18n/bondhome.properties @@ -82,7 +82,7 @@ channel-type.bondhome.timerChannelType.description = Starts a timer for s second # thing status descriptions -offline.comm-error.api-call-failed = Bond API call to {} failed: {} +offline.comm-error.api-call-failed = Bond API call failed. offline.comm-error.device-not-found = No Bond device found with the given device id. offline.comm-error.no-api = Bond Bridge API not available. offline.comm-error.no-response = No response received! -- 2.47.3