From 7600f3339a3eaefb40db21d8411bf29e0505bef3 Mon Sep 17 00:00:00 2001 From: Mark Hilbush Date: Sat, 16 Mar 2024 08:46:55 -0400 Subject: [PATCH] [orbitbhyve] Handle null location attribute in devices json (#16525) * Handle null location in devices json --------- Signed-off-by: Mark Hilbush Signed-off-by: Ciprian Pascu --- .../internal/handler/OrbitBhyveBridgeHandler.java | 7 +++++++ .../orbitbhyve/internal/model/OrbitBhyveDevice.java | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java index 1ff85838965..26ae2389d43 100644 --- a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java +++ b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java @@ -64,6 +64,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; /** * The {@link OrbitBhyveBridgeHandler} is responsible for handling commands, which are @@ -210,6 +211,9 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Get devices returned response status: " + response.getStatus()); } + } catch (JsonSyntaxException e) { + logger.debug("Exception parsing devices json: {}", e.getMessage(), e); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error parsing devices json"); } catch (TimeoutException | ExecutionException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during getting devices"); } catch (InterruptedException e) { @@ -237,6 +241,9 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Returned status: " + response.getStatus()); } + } catch (JsonSyntaxException e) { + logger.debug("Exception parsing device json: {}", e.getMessage(), e); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error parsing device json"); } catch (TimeoutException | ExecutionException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during getting device info: " + deviceId); diff --git a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/model/OrbitBhyveDevice.java b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/model/OrbitBhyveDevice.java index 43acf3f9558..5fb2a8a50bc 100644 --- a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/model/OrbitBhyveDevice.java +++ b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/model/OrbitBhyveDevice.java @@ -16,7 +16,9 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; @@ -52,7 +54,8 @@ public class OrbitBhyveDevice { @SerializedName("last_connected_at") String lastConnectedAt = ""; - JsonObject location = new JsonObject(); + @Nullable + JsonElement location = null; @SerializedName("suggested_start_time") String suggestedStartTime = "";