Skip to content

Commit bec9863

Browse files
committed
[evcc] Fix IllegalArgumentException for specific vehicle Id's (openhab#17380)
* Handle semicolon in car id Signed-off-by: Leo Siepel <[email protected]>
1 parent 5d3c6c9 commit bec9863

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/EvccAPI.java

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private String httpRequest(String url, String method) throws EvccApiException {
7575
*/
7676
public Result getResult() throws EvccApiException {
7777
final String response = httpRequest(this.host + EVCC_REST_API + "state", "GET");
78+
logger.trace("API Response >> {}", response);
7879
try {
7980
Status status = gson.fromJson(response, Status.class);
8081
if (status == null) {

bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Loadpoint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public float getVehicleSoC() {
271271
* @return vehicle's title/name
272272
*/
273273
public String getVehicleName() {
274-
return vehicleName;
274+
return vehicleName != null ? vehicleName.replace(":", "-") : vehicleName;
275275
}
276276

277277
/**

bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Result.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
*/
1313
package org.openhab.binding.evcc.internal.api.dto;
1414

15+
import java.util.HashMap;
1516
import java.util.Map;
17+
import java.util.Map.Entry;
1618

1719
import com.google.gson.annotations.SerializedName;
1820

@@ -219,7 +221,12 @@ public String getSiteTitle() {
219221
}
220222

221223
public Map<String, Vehicle> getVehicles() {
222-
return vehicles;
224+
Map<String, Vehicle> correctedMap = new HashMap<>();
225+
for (Entry<String, Vehicle> entry : vehicles.entrySet()) {
226+
// The key from the vehicles map is used as uid, so it should not contain semicolons.
227+
correctedMap.put(entry.getKey().replace(":", "-"), entry.getValue());
228+
}
229+
return correctedMap;
223230
}
224231

225232
/**

0 commit comments

Comments
 (0)