[evcc] Adjust to evcc 0.125.0 API changes (#16660)

* avoid deprecated parameters evcc rest API parameters 'batteryConfigured' and 'pvConfigured'

Signed-off-by: Michael Weger <weger.michael@gmx.net>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
MikeTheTux 2024-04-20 15:00:59 +02:00 committed by Ciprian Pascu
parent 627cc9d590
commit 173e124278
5 changed files with 147 additions and 29 deletions

View File

@ -1,7 +1,7 @@
# evcc Binding # evcc Binding
This binding integrates [evcc - electric vehicle charging control](https://evcc.io), a project that provides a control center for electric vehicle charging. This binding integrates [evcc](https://evcc.io), an extensible **E**lectric **V**ehicle **C**harge **C**ontroller and home energy management system.
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. 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).
You can easily install and upgrade evcc on openHABian using `sudo openhabian-config`. You can easily install and upgrade evcc on openHABian using `sudo openhabian-config`.

View File

@ -27,7 +27,9 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.evcc.internal.api.EvccAPI; import org.openhab.binding.evcc.internal.api.EvccAPI;
import org.openhab.binding.evcc.internal.api.EvccApiException; import org.openhab.binding.evcc.internal.api.EvccApiException;
import org.openhab.binding.evcc.internal.api.dto.Battery;
import org.openhab.binding.evcc.internal.api.dto.Loadpoint; import org.openhab.binding.evcc.internal.api.dto.Loadpoint;
import org.openhab.binding.evcc.internal.api.dto.PV;
import org.openhab.binding.evcc.internal.api.dto.Plan; import org.openhab.binding.evcc.internal.api.dto.Plan;
import org.openhab.binding.evcc.internal.api.dto.Result; import org.openhab.binding.evcc.internal.api.dto.Result;
import org.openhab.binding.evcc.internal.api.dto.Vehicle; import org.openhab.binding.evcc.internal.api.dto.Vehicle;
@ -216,7 +218,6 @@ public class EvccHandler extends BaseThingHandler {
return; return;
} }
} }
} else if (groupId.startsWith(CHANNEL_GROUP_ID_VEHICLE) || groupId.startsWith(CHANNEL_GROUP_ID_HEATING) } else if (groupId.startsWith(CHANNEL_GROUP_ID_VEHICLE) || groupId.startsWith(CHANNEL_GROUP_ID_HEATING)
|| (groupId.startsWith(CHANNEL_GROUP_ID_LOADPOINT) || (groupId.startsWith(CHANNEL_GROUP_ID_LOADPOINT)
&& groupId.endsWith(CHANNEL_GROUP_ID_CURRENT))) { && groupId.endsWith(CHANNEL_GROUP_ID_CURRENT))) {
@ -412,9 +413,11 @@ public class EvccHandler extends BaseThingHandler {
Map<String, Vehicle> vehicles = result.getVehicles(); Map<String, Vehicle> vehicles = result.getVehicles();
logger.debug("Found {} vehicles on site {}.", vehicles.size(), sitename); logger.debug("Found {} vehicles on site {}.", vehicles.size(), sitename);
updateStatus(ThingStatus.ONLINE); updateStatus(ThingStatus.ONLINE);
batteryConfigured = result.getBatteryConfigured(); Battery[] batteries = result.getBattery();
gridConfigured = result.getGridConfigured(); batteryConfigured = ((batteries != null) && (batteries.length > 0));
pvConfigured = result.getPvConfigured(); gridConfigured = (result.getGridPower() != null);
PV[] pvs = result.getPV();
pvConfigured = ((pvs != null) && (pvs.length > 0));
createChannelsGeneral(); createChannelsGeneral();
updateChannelsGeneral(); updateChannelsGeneral();
for (int i = 0; i < numberOfLoadpoints; i++) { for (int i = 0; i < numberOfLoadpoints; i++) {
@ -704,7 +707,7 @@ public class EvccHandler extends BaseThingHandler {
} }
boolean gridConfigured = this.gridConfigured; boolean gridConfigured = this.gridConfigured;
if (gridConfigured) { if (gridConfigured) {
float gridPower = result.getGridPower(); float gridPower = ((result.getGridPower() == null) ? 0.0f : result.getGridPower());
channel = new ChannelUID(uid, CHANNEL_GROUP_ID_GENERAL, CHANNEL_GRID_POWER); channel = new ChannelUID(uid, CHANNEL_GROUP_ID_GENERAL, CHANNEL_GRID_POWER);
updateState(channel, new QuantityType<>(gridPower, Units.WATT)); updateState(channel, new QuantityType<>(gridPower, Units.WATT));
} }

View File

@ -0,0 +1,69 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.evcc.internal.api.dto;
import com.google.gson.annotations.SerializedName;
/**
* This class represents a battery object of the status response (/api/state).
* This DTO was written for evcc version 0.123.1
*
* @author MikeTheTux - Initial contribution
*/
public class Battery {
// Data types from https://github.com/evcc-io/evcc/blob/master/api/api.go
// and from https://docs.evcc.io/docs/reference/configuration/messaging/#msg
@SerializedName("power")
private float power;
@SerializedName("energy")
private float energy;
@SerializedName("soc")
private float soc;
@SerializedName("capacity")
private float capacity;
@SerializedName("controllable")
private boolean controllable;
/**
* @return battery's capacity
*/
public float getCapacity() {
return capacity;
}
/**
* @return battery's power
*/
public float getPower() {
return power;
}
/**
* @return battery's state of charge
*/
public float getSoC() {
return soc;
}
/**
* @return battery discharge controlable
*/
public boolean getControllable() {
return controllable;
}
}

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.evcc.internal.api.dto;
import com.google.gson.annotations.SerializedName;
/**
* This class represents a PV object of the status response (/api/state).
* This DTO was written for evcc version 0.123.1
*
* @author MikeTheTux - Initial contribution
*/
public class PV {
// Data types from https://github.com/evcc-io/evcc/blob/master/api/api.go
// and from https://docs.evcc.io/docs/reference/configuration/messaging/#msg
@SerializedName("power")
private float power;
/**
* @return PV power
*/
public float getPower() {
return power;
}
}

View File

@ -32,8 +32,8 @@ public class Result {
@SerializedName("batteryCapacity") @SerializedName("batteryCapacity")
private float batteryCapacity; private float batteryCapacity;
@SerializedName("batteryConfigured") @SerializedName("battery")
private boolean batteryConfigured; private Battery[] battery;
@SerializedName("batteryPower") @SerializedName("batteryPower")
private float batteryPower; private float batteryPower;
@ -47,11 +47,14 @@ public class Result {
@SerializedName("batteryMode") @SerializedName("batteryMode")
private String batteryMode; private String batteryMode;
@SerializedName("gridConfigured") @SerializedName("gridCurrents")
private boolean gridConfigured; private float[] gridCurrents;
@SerializedName("gridEnergy")
private float gridEnergy;
@SerializedName("gridPower") @SerializedName("gridPower")
private float gridPower; private Float gridPower;
@SerializedName("homePower") @SerializedName("homePower")
private float homePower; private float homePower;
@ -71,8 +74,8 @@ public class Result {
@SerializedName("residualPower") @SerializedName("residualPower")
private float residualPower; private float residualPower;
@SerializedName("pvConfigured") @SerializedName("pv")
private boolean pvConfigured; private PV[] pv;
@SerializedName("pvPower") @SerializedName("pvPower")
private float pvPower; private float pvPower;
@ -89,6 +92,13 @@ public class Result {
@SerializedName("availableVersion") @SerializedName("availableVersion")
private String availableVersion; private String availableVersion;
/**
* @return all configured batteries
*/
public Battery[] getBattery() {
return battery;
}
/** /**
* @return battery's capacity * @return battery's capacity
*/ */
@ -96,13 +106,6 @@ public class Result {
return batteryCapacity; return batteryCapacity;
} }
/**
* @return whether battery is configured
*/
public boolean getBatteryConfigured() {
return batteryConfigured;
}
/** /**
* @return battery's power * @return battery's power
*/ */
@ -160,16 +163,23 @@ public class Result {
} }
/** /**
* @return whether grid is configured * @return grid's currents
*/ */
public boolean getGridConfigured() { public float[] getGridCurrents() {
return gridConfigured; return gridCurrents;
} }
/** /**
* @return grid's power * @return grid's energy
*/ */
public float getGridPower() { public float getGridEnergy() {
return gridEnergy;
}
/**
* @return grid's power or {@code null} if not available
*/
public Float getGridPower() {
return gridPower; return gridPower;
} }
@ -188,10 +198,10 @@ public class Result {
} }
/** /**
* @return whether pv is configured * @return all configured PVs
*/ */
public boolean getPvConfigured() { public PV[] getPV() {
return pvConfigured; return pv;
} }
/** /**