Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[evcc] Adjust to evcc 0.125.0 API changes #16660

Merged
merged 8 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.evcc/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# evcc Binding

This binding integrates [evcc - electric vehicle charging control](https://evcc.io), a project that provides a control center for electric vehicle charging.
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 compatbile to evcc starting with [version 0.123.1](https://github.com/evcc-io/evcc/releases/tag/0.123.1) or newer. Starting with [evcc version 0.125.0](https://github.com/evcc-io/evcc/releases/tag/0.125.0) this version of the binding is mandatory as some of the evcc rest-API parameters got discontinued. This binding was tested with [version 0.125.0](https://github.com/evcc-io/evcc/releases/tag/0.125.0).
florian-h05 marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.evcc.internal.api.EvccAPI;
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.PV;
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.Vehicle;
Expand Down Expand Up @@ -216,7 +218,6 @@ public void handleCommand(ChannelUID channelUID, Command command) {
return;
}
}

} else if (groupId.startsWith(CHANNEL_GROUP_ID_VEHICLE) || groupId.startsWith(CHANNEL_GROUP_ID_HEATING)
|| (groupId.startsWith(CHANNEL_GROUP_ID_LOADPOINT)
&& groupId.endsWith(CHANNEL_GROUP_ID_CURRENT))) {
Expand Down Expand Up @@ -412,9 +413,11 @@ private void refresh() {
Map<String, Vehicle> vehicles = result.getVehicles();
logger.debug("Found {} vehicles on site {}.", vehicles.size(), sitename);
updateStatus(ThingStatus.ONLINE);
batteryConfigured = result.getBatteryConfigured();
gridConfigured = result.getGridConfigured();
pvConfigured = result.getPvConfigured();
Battery[] batteries = result.getBattery();
batteryConfigured = ((batteries != null) && (batteries.length > 0));
gridConfigured = (result.getGridPower() != null);
PV[] pvs = result.getPV();
pvConfigured = ((pvs != null) && (pvs.length > 0));
createChannelsGeneral();
updateChannelsGeneral();
for (int i = 0; i < numberOfLoadpoints; i++) {
Expand Down Expand Up @@ -704,7 +707,7 @@ private void updateChannelsGeneral() {
}
boolean gridConfigured = this.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);
updateState(channel, new QuantityType<>(gridPower, Units.WATT));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class Result {
@SerializedName("batteryCapacity")
private float batteryCapacity;

@SerializedName("batteryConfigured")
private boolean batteryConfigured;
@SerializedName("battery")
private Battery[] battery;

@SerializedName("batteryPower")
private float batteryPower;
Expand All @@ -47,11 +47,14 @@ public class Result {
@SerializedName("batteryMode")
private String batteryMode;

@SerializedName("gridConfigured")
private boolean gridConfigured;
@SerializedName("gridCurrents")
private float[] gridCurrents;

@SerializedName("gridEnergy")
private float gridEnergy;

@SerializedName("gridPower")
private float gridPower;
private Float gridPower;

@SerializedName("homePower")
private float homePower;
Expand All @@ -71,8 +74,8 @@ public class Result {
@SerializedName("residualPower")
private float residualPower;

@SerializedName("pvConfigured")
private boolean pvConfigured;
@SerializedName("pv")
private PV[] pv;

@SerializedName("pvPower")
private float pvPower;
Expand All @@ -90,17 +93,17 @@ public class Result {
private String availableVersion;

/**
* @return battery's capacity
* @return all configured batteries
*/
public float getBatteryCapacity() {
return batteryCapacity;
public Battery[] getBattery() {
return battery;
}

/**
* @return whether battery is configured
* @return battery's capacity
*/
public boolean getBatteryConfigured() {
return batteryConfigured;
public float getBatteryCapacity() {
return batteryCapacity;
}

/**
Expand Down Expand Up @@ -160,16 +163,23 @@ public String getBatteryMode() {
}

/**
* @return whether grid is configured
* @return grid's currents
*/
public float[] getGridCurrents() {
return gridCurrents;
}

/**
* @return grid's energy
*/
public boolean getGridConfigured() {
return gridConfigured;
public float getGridEnergy() {
return gridEnergy;
}

/**
* @return grid's power
* {@return grid's power} {@code null} if not available
florian-h05 marked this conversation as resolved.
Show resolved Hide resolved
*/
public float getGridPower() {
public Float getGridPower() {
florian-h05 marked this conversation as resolved.
Show resolved Hide resolved
return gridPower;
}

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

/**
* @return whether pv is configured
* @return all configured PVs
*/
public boolean getPvConfigured() {
return pvConfigured;
public PV[] getPV() {
return pv;
}

/**
Expand Down