Skip to content

Commit

Permalink
[evcc] Fix IllegalArgumentException for specific vehicle Id's (#17380)
Browse files Browse the repository at this point in the history
* Handle semicolon in car id

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
  • Loading branch information
lsiepel authored Sep 9, 2024
1 parent 110fd9b commit 16a6853
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private String httpRequest(String url, String method) throws EvccApiException {
*/
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public float getVehicleSoC() {
* @return vehicle's title/name
*/
public String getVehicleName() {
return vehicleName;
return vehicleName != null ? vehicleName.replace(":", "-") : vehicleName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -219,7 +221,12 @@ public String getSiteTitle() {
}

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;
}

/**
Expand Down

0 comments on commit 16a6853

Please sign in to comment.