From ae81f398cb16e00e978f20e594b8838a0ff7c591 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Wed, 8 Jan 2025 20:03:21 +0100 Subject: [PATCH] fix offline when image not available (#18066) Signed-off-by: Mark Herwege --- .../speedtest/internal/SpeedtestHandler.java | 18 ++++++++++++------ .../internal/dto/ResultContainer.java | 11 +++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/SpeedtestHandler.java b/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/SpeedtestHandler.java index b7d1cd3faa8..f2e1c107f9f 100644 --- a/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/SpeedtestHandler.java +++ b/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/SpeedtestHandler.java @@ -365,13 +365,19 @@ public class SpeedtestHandler extends BaseThingHandler { isp = tmpCont.getIsp(); interfaceInternalIp = tmpCont.getInterface().getInternalIp(); interfaceExternalIp = tmpCont.getInterface().getExternalIp(); - resultUrl = tmpCont.getResult().getUrl(); - String url = String.valueOf(resultUrl) + ".png"; - logger.debug("Downloading result image from: {}", url); - RawType image = HttpUtil.downloadImage(url); - if (image != null) { - resultImage = image; + if (tmpCont.getResult().isPersisted()) { + resultUrl = tmpCont.getResult().getUrl(); + String url = String.valueOf(resultUrl) + ".png"; + logger.debug("Downloading result image from: {}", url); + RawType image = HttpUtil.downloadImage(url); + if (image != null) { + resultImage = image; + } else { + resultImage = UnDefType.NULL; + } } else { + logger.debug("Result image not persisted"); + resultUrl = ""; resultImage = UnDefType.NULL; } diff --git a/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/dto/ResultContainer.java b/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/dto/ResultContainer.java index a0471f7f287..25bff06f205 100644 --- a/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/dto/ResultContainer.java +++ b/bundles/org.openhab.binding.speedtest/src/main/java/org/openhab/binding/speedtest/internal/dto/ResultContainer.java @@ -263,6 +263,9 @@ public class ResultContainer { @SerializedName("url") @Expose private String url; + @SerializedName("persisted") + @Expose + private boolean persisted; public String getId() { return id; @@ -279,6 +282,14 @@ public class ResultContainer { public void setUrl(String url) { this.url = url; } + + public boolean isPersisted() { + return persisted; + } + + public void setPersisted(boolean persisted) { + this.persisted = persisted; + } } public class Server {