Skip to content

Commit 82fce11

Browse files
MikeTheTuxflorian-h05
authored andcommitted
[evcc] Adjust to evcc 0.125.0 API changes (openhab#16660)
* avoid deprecated parameters evcc rest API parameters 'batteryConfigured' and 'pvConfigured' Signed-off-by: Michael Weger <[email protected]> (cherry picked from commit 6db28f5)
1 parent ade8d7d commit 82fce11

File tree

5 files changed

+146
-28
lines changed

5 files changed

+146
-28
lines changed

bundles/org.openhab.binding.evcc/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# evcc Binding
22

3-
This binding integrates [evcc - electric vehicle charging control](https://evcc.io), a project that provides a control center for electric vehicle charging.
4-
The binding requires evcc [version 0.123.1](https://github.com/evcc-io/evcc/releases/tag/0.123.1) or newer and is tested with this version.
3+
This binding integrates [evcc](https://evcc.io), an extensible **E**lectric **V**ehicle **C**harge **C**ontroller and home energy management system.
4+
The binding is compatible to evcc [version 0.123.1](https://github.com/evcc-io/evcc/releases/tag/0.123.1) or newer and was tested with [version 0.125.0](https://github.com/evcc-io/evcc/releases/tag/0.125.0).
55

66
You can easily install and upgrade evcc on openHABian using `sudo openhabian-config`.
77

bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import org.eclipse.jdt.annotation.Nullable;
2828
import org.openhab.binding.evcc.internal.api.EvccAPI;
2929
import org.openhab.binding.evcc.internal.api.EvccApiException;
30+
import org.openhab.binding.evcc.internal.api.dto.Battery;
3031
import org.openhab.binding.evcc.internal.api.dto.Loadpoint;
32+
import org.openhab.binding.evcc.internal.api.dto.PV;
3133
import org.openhab.binding.evcc.internal.api.dto.Plan;
3234
import org.openhab.binding.evcc.internal.api.dto.Result;
3335
import org.openhab.binding.evcc.internal.api.dto.Vehicle;
@@ -216,7 +218,6 @@ public void handleCommand(ChannelUID channelUID, Command command) {
216218
return;
217219
}
218220
}
219-
220221
} else if (groupId.startsWith(CHANNEL_GROUP_ID_VEHICLE) || groupId.startsWith(CHANNEL_GROUP_ID_HEATING)
221222
|| (groupId.startsWith(CHANNEL_GROUP_ID_LOADPOINT)
222223
&& groupId.endsWith(CHANNEL_GROUP_ID_CURRENT))) {
@@ -412,9 +413,11 @@ private void refresh() {
412413
Map<String, Vehicle> vehicles = result.getVehicles();
413414
logger.debug("Found {} vehicles on site {}.", vehicles.size(), sitename);
414415
updateStatus(ThingStatus.ONLINE);
415-
batteryConfigured = result.getBatteryConfigured();
416-
gridConfigured = result.getGridConfigured();
417-
pvConfigured = result.getPvConfigured();
416+
Battery[] batteries = result.getBattery();
417+
batteryConfigured = ((batteries != null) && (batteries.length > 0));
418+
gridConfigured = (result.getGridPower() != null);
419+
PV[] pvs = result.getPV();
420+
pvConfigured = ((pvs != null) && (pvs.length > 0));
418421
createChannelsGeneral();
419422
updateChannelsGeneral();
420423
for (int i = 0; i < numberOfLoadpoints; i++) {
@@ -704,7 +707,7 @@ private void updateChannelsGeneral() {
704707
}
705708
boolean gridConfigured = this.gridConfigured;
706709
if (gridConfigured) {
707-
float gridPower = result.getGridPower();
710+
float gridPower = ((result.getGridPower() == null) ? 0.0f : result.getGridPower());
708711
channel = new ChannelUID(uid, CHANNEL_GROUP_ID_GENERAL, CHANNEL_GRID_POWER);
709712
updateState(channel, new QuantityType<>(gridPower, Units.WATT));
710713
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.evcc.internal.api.dto;
14+
15+
import com.google.gson.annotations.SerializedName;
16+
17+
/**
18+
* This class represents a battery object of the status response (/api/state).
19+
* This DTO was written for evcc version 0.123.1
20+
*
21+
* @author MikeTheTux - Initial contribution
22+
*/
23+
public class Battery {
24+
// Data types from https://github.com/evcc-io/evcc/blob/master/api/api.go
25+
// and from https://docs.evcc.io/docs/reference/configuration/messaging/#msg
26+
27+
@SerializedName("power")
28+
private float power;
29+
30+
@SerializedName("energy")
31+
private float energy;
32+
33+
@SerializedName("soc")
34+
private float soc;
35+
36+
@SerializedName("capacity")
37+
private float capacity;
38+
39+
@SerializedName("controllable")
40+
private boolean controllable;
41+
42+
/**
43+
* @return battery's capacity
44+
*/
45+
public float getCapacity() {
46+
return capacity;
47+
}
48+
49+
/**
50+
* @return battery's power
51+
*/
52+
public float getPower() {
53+
return power;
54+
}
55+
56+
/**
57+
* @return battery's state of charge
58+
*/
59+
public float getSoC() {
60+
return soc;
61+
}
62+
63+
/**
64+
* @return battery discharge controlable
65+
*/
66+
public boolean getControllable() {
67+
return controllable;
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.evcc.internal.api.dto;
14+
15+
import com.google.gson.annotations.SerializedName;
16+
17+
/**
18+
* This class represents a PV object of the status response (/api/state).
19+
* This DTO was written for evcc version 0.123.1
20+
*
21+
* @author MikeTheTux - Initial contribution
22+
*/
23+
public class PV {
24+
// Data types from https://github.com/evcc-io/evcc/blob/master/api/api.go
25+
// and from https://docs.evcc.io/docs/reference/configuration/messaging/#msg
26+
27+
@SerializedName("power")
28+
private float power;
29+
30+
/**
31+
* @return PV power
32+
*/
33+
public float getPower() {
34+
return power;
35+
}
36+
}

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

+31-21
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public class Result {
3232
@SerializedName("batteryCapacity")
3333
private float batteryCapacity;
3434

35-
@SerializedName("batteryConfigured")
36-
private boolean batteryConfigured;
35+
@SerializedName("battery")
36+
private Battery[] battery;
3737

3838
@SerializedName("batteryPower")
3939
private float batteryPower;
@@ -47,11 +47,14 @@ public class Result {
4747
@SerializedName("batteryMode")
4848
private String batteryMode;
4949

50-
@SerializedName("gridConfigured")
51-
private boolean gridConfigured;
50+
@SerializedName("gridCurrents")
51+
private float[] gridCurrents;
52+
53+
@SerializedName("gridEnergy")
54+
private float gridEnergy;
5255

5356
@SerializedName("gridPower")
54-
private float gridPower;
57+
private Float gridPower;
5558

5659
@SerializedName("homePower")
5760
private float homePower;
@@ -71,8 +74,8 @@ public class Result {
7174
@SerializedName("residualPower")
7275
private float residualPower;
7376

74-
@SerializedName("pvConfigured")
75-
private boolean pvConfigured;
77+
@SerializedName("pv")
78+
private PV[] pv;
7679

7780
@SerializedName("pvPower")
7881
private float pvPower;
@@ -90,17 +93,17 @@ public class Result {
9093
private String availableVersion;
9194

9295
/**
93-
* @return battery's capacity
96+
* @return all configured batteries
9497
*/
95-
public float getBatteryCapacity() {
96-
return batteryCapacity;
98+
public Battery[] getBattery() {
99+
return battery;
97100
}
98101

99102
/**
100-
* @return whether battery is configured
103+
* @return battery's capacity
101104
*/
102-
public boolean getBatteryConfigured() {
103-
return batteryConfigured;
105+
public float getBatteryCapacity() {
106+
return batteryCapacity;
104107
}
105108

106109
/**
@@ -160,16 +163,23 @@ public String getBatteryMode() {
160163
}
161164

162165
/**
163-
* @return whether grid is configured
166+
* @return grid's currents
167+
*/
168+
public float[] getGridCurrents() {
169+
return gridCurrents;
170+
}
171+
172+
/**
173+
* @return grid's energy
164174
*/
165-
public boolean getGridConfigured() {
166-
return gridConfigured;
175+
public float getGridEnergy() {
176+
return gridEnergy;
167177
}
168178

169179
/**
170-
* @return grid's power
180+
* @return grid's power or {@code null} if not available
171181
*/
172-
public float getGridPower() {
182+
public Float getGridPower() {
173183
return gridPower;
174184
}
175185

@@ -188,10 +198,10 @@ public Loadpoint[] getLoadpoints() {
188198
}
189199

190200
/**
191-
* @return whether pv is configured
201+
* @return all configured PVs
192202
*/
193-
public boolean getPvConfigured() {
194-
return pvConfigured;
203+
public PV[] getPV() {
204+
return pv;
195205
}
196206

197207
/**

0 commit comments

Comments
 (0)