[evcc] Fix IllegalArgumentException for specific vehicle Id's (#17380)

* Handle semicolon in car id

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2024-09-09 18:56:55 +02:00 committed by Leo Siepel
parent 5d3c6c93d7
commit bec9863d4a
3 changed files with 10 additions and 2 deletions

View File

@ -75,6 +75,7 @@ public class EvccAPI {
*/ */
public Result getResult() throws EvccApiException { public Result getResult() throws EvccApiException {
final String response = httpRequest(this.host + EVCC_REST_API + "state", "GET"); final String response = httpRequest(this.host + EVCC_REST_API + "state", "GET");
logger.trace("API Response >> {}", response);
try { try {
Status status = gson.fromJson(response, Status.class); Status status = gson.fromJson(response, Status.class);
if (status == null) { if (status == null) {

View File

@ -271,7 +271,7 @@ public class Loadpoint {
* @return vehicle's title/name * @return vehicle's title/name
*/ */
public String getVehicleName() { public String getVehicleName() {
return vehicleName; return vehicleName != null ? vehicleName.replace(":", "-") : vehicleName;
} }
/** /**

View File

@ -12,7 +12,9 @@
*/ */
package org.openhab.binding.evcc.internal.api.dto; package org.openhab.binding.evcc.internal.api.dto;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -219,7 +221,12 @@ public class Result {
} }
public Map<String, Vehicle> getVehicles() { 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;
} }
/** /**