From 04494dd79133c0eb39324a23fb948d36cf3ca58a Mon Sep 17 00:00:00 2001 From: Michael Weger Date: Wed, 17 Apr 2024 19:43:08 +0200 Subject: [PATCH] avoid deprecated parameters evcc rest API parameters 'batteryConfigured' and 'pvConfigured' --- .../binding/evcc/internal/EvccHandler.java | 9 ++- .../evcc/internal/api/dto/Battery.java | 69 +++++++++++++++++++ .../binding/evcc/internal/api/dto/PV.java | 36 ++++++++++ .../binding/evcc/internal/api/dto/Result.java | 26 +++---- 4 files changed, 124 insertions(+), 16 deletions(-) create mode 100644 bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Battery.java create mode 100644 bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/PV.java diff --git a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java index 3e6131d2a3ae4..b704ceb957c31 100644 --- a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java +++ b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java @@ -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; @@ -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))) { @@ -412,9 +413,11 @@ private void refresh() { Map vehicles = result.getVehicles(); logger.debug("Found {} vehicles on site {}.", vehicles.size(), sitename); updateStatus(ThingStatus.ONLINE); - batteryConfigured = result.getBatteryConfigured(); + Battery[] battery = result.getBattery(); + batteryConfigured = ((battery != null) && (battery.length > 0)); gridConfigured = result.getGridConfigured(); - pvConfigured = result.getPvConfigured(); + PV[] pv = result.getPV(); + pvConfigured = ((pv != null) && (pv.length > 0)); createChannelsGeneral(); updateChannelsGeneral(); for (int i = 0; i < numberOfLoadpoints; i++) { diff --git a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Battery.java b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Battery.java new file mode 100644 index 0000000000000..9d21b612c42cd --- /dev/null +++ b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Battery.java @@ -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; + } +} diff --git a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/PV.java b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/PV.java new file mode 100644 index 0000000000000..0261c35db73d3 --- /dev/null +++ b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/PV.java @@ -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; + } +} diff --git a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Result.java b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Result.java index 0e3f367bc473a..159b278644c81 100644 --- a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Result.java +++ b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/api/dto/Result.java @@ -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; @@ -71,8 +71,8 @@ public class Result { @SerializedName("residualPower") private float residualPower; - @SerializedName("pvConfigured") - private boolean pvConfigured; + @SerializedName("pv") + private PV[] pv; @SerializedName("pvPower") private float pvPower; @@ -90,17 +90,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; } /** @@ -188,10 +188,10 @@ public Loadpoint[] getLoadpoints() { } /** - * @return whether pv is configured + * @return all configured PVs */ - public boolean getPvConfigured() { - return pvConfigured; + public PV[] getPV() { + return pv; } /**