Skip to content

Commit

Permalink
avoid deprecated parameters evcc rest API parameters 'batteryConfigur…
Browse files Browse the repository at this point in the history
…ed' and 'pvConfigured'
  • Loading branch information
MikeTheTux committed Apr 17, 2024
1 parent 31c3356 commit 04494dd
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 16 deletions.
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();
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++) {
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 Down Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 04494dd

Please sign in to comment.