From 06e30201e9d71bd451240d41da80ee1978356ae2 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 5 Nov 2020 20:46:52 +0100 Subject: [PATCH] [miio] avoid Invalid URI host: null error (#8867) for 2.5 (#8898) * [miio] avoid Invalid URI host: null error (#8867) * [miio] avoid Invalid URI host: null error Signed-off-by: Marcel Verpaalen --- .../miio/internal/cloud/CloudConnector.java | 20 +++++++++++++------ .../miio/internal/cloud/MiCloudConnector.java | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/CloudConnector.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/CloudConnector.java index 57b86f11160..28e7c709d52 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/CloudConnector.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/CloudConnector.java @@ -137,14 +137,22 @@ public class CloudConnector { mapCountry = country.trim().toLowerCase(); mapUrl = cl.getMapUrl(mapId, mapCountry); } - @Nullable - RawType mapData = HttpUtil.downloadData(mapUrl, null, false, -1); - if (mapData != null) { - return mapData; - } else { - logger.debug("Could not download '{}'", mapUrl); + if (mapUrl.isEmpty()) { + logger.debug("Cannot download map data: Returned map URL is empty"); return null; } + try { + RawType mapData = HttpUtil.downloadData(mapUrl, null, false, -1); + if (mapData != null) { + return mapData; + } else { + logger.debug("Could not download '{}'", mapUrl); + return null; + } + } catch (IllegalArgumentException e) { + logger.debug("Error downloading map: {}", e.getMessage()); + } + return null; } public void setCredentials(@Nullable String username, @Nullable String password, @Nullable String country) { diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/MiCloudConnector.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/MiCloudConnector.java index 0e446b6a73c..085542f11ae 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/MiCloudConnector.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/cloud/MiCloudConnector.java @@ -160,7 +160,8 @@ public class MiCloudConnector { if (response.getAsJsonObject().has("result") && response.getAsJsonObject().get("result").isJsonObject()) { JsonObject jo = response.getAsJsonObject().get("result").getAsJsonObject(); if (jo.has("url")) { - return jo.get("url").getAsString(); + String mapUrl = jo.get("url").getAsString(); + return mapUrl != null ? mapUrl : ""; } else { errorMsg = "Could not get url"; }