]> git.basschouten.com Git - openhab-addons.git/commitdiff
[evcc] Fix `IllegalArgumentException` for specific vehicle Id's (#17380)
authorlsiepel <leosiepel@gmail.com>
Mon, 9 Sep 2024 16:56:55 +0000 (18:56 +0200)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2024 16:56:55 +0000 (18:56 +0200)
* Handle semicolon in car id

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/EvccAPI.java
bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Loadpoint.java
bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Result.java

index f658f23869b99e0b24e3dfd0e3f1762e030c00dc..afacdfe0be6464165bab01ecf6ab38d143e9fd14 100644 (file)
@@ -75,6 +75,7 @@ public class EvccAPI {
      */
     public Result getResult() throws EvccApiException {
         final String response = httpRequest(this.host + EVCC_REST_API + "state", "GET");
+        logger.trace("API Response >> {}", response);
         try {
             Status status = gson.fromJson(response, Status.class);
             if (status == null) {
index 3792e43ce5b1e5fef0cd5cb494ceac5ef1b35a52..6b9a6f79d89d3f683794653762180d01110e73e6 100644 (file)
@@ -271,7 +271,7 @@ public class Loadpoint {
      * @return vehicle's title/name
      */
     public String getVehicleName() {
-        return vehicleName;
+        return vehicleName != null ? vehicleName.replace(":", "-") : vehicleName;
     }
 
     /**
index 598ee3f7028888eeae984f67c57c0186f57ebfbf..4da0060bd81336ea0f810b784b210811a1d528a5 100644 (file)
@@ -12,7 +12,9 @@
  */
 package org.openhab.binding.evcc.internal.api.dto;
 
+import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import com.google.gson.annotations.SerializedName;
 
@@ -219,7 +221,12 @@ public class Result {
     }
 
     public Map<String, Vehicle> getVehicles() {
-        return vehicles;
+        Map<String, Vehicle> correctedMap = new HashMap<>();
+        for (Entry<String, Vehicle> entry : vehicles.entrySet()) {
+            // The key from the vehicles map is used as uid, so it should not contain semicolons.
+            correctedMap.put(entry.getKey().replace(":", "-"), entry.getValue());
+        }
+        return correctedMap;
     }
 
     /**