Skip to content

Commit 0de0566

Browse files
author
Daniel Kötting
committed
Fix missing grid readings after evcc breaking change in 0.133.0
Fixes openhab#18148 Signed-off-by: Daniel Kötting <[email protected]>
1 parent dfea7a1 commit 0de0566

File tree

3 files changed

+68
-22
lines changed

3 files changed

+68
-22
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private void refresh() {
420420
updateStatus(ThingStatus.ONLINE);
421421
Battery[] batteries = result.getBattery();
422422
batteryConfigured = ((batteries != null) && (batteries.length > 0));
423-
gridConfigured = (result.getGridPower() != null);
423+
gridConfigured = result.getGridConfigured();
424424
PV[] pvs = result.getPV();
425425
pvConfigured = ((pvs != null) && (pvs.length > 0));
426426
createChannelsGeneral();
@@ -712,7 +712,7 @@ private void updateChannelsGeneral() {
712712
}
713713
boolean gridConfigured = this.gridConfigured;
714714
if (gridConfigured) {
715-
float gridPower = ((result.getGridPower() == null) ? 0.0f : result.getGridPower());
715+
float gridPower = ((result.getGrid().getPower() == null) ? 0.0f : result.getGrid().getPower());
716716
channel = new ChannelUID(uid, CHANNEL_GROUP_ID_GENERAL, CHANNEL_GRID_POWER);
717717
updateState(channel, new QuantityType<>(gridPower, Units.WATT));
718718
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2010-2025 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 the grid response (/api/state).
19+
* This DTO was written for evcc version 0.133.0
20+
*
21+
* @author Daniel Kötting - Initial contribution
22+
*/
23+
public class Grid {
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("currents")
28+
private float[] currents;
29+
30+
@SerializedName("energy")
31+
private float energy;
32+
33+
@SerializedName("power")
34+
private Float power;
35+
36+
/**
37+
* @return grid's currents
38+
*/
39+
public float[] getCurrents() {
40+
return currents;
41+
}
42+
43+
/**
44+
* @return grid's energy
45+
*/
46+
public float getEnergy() {
47+
return energy;
48+
}
49+
50+
/**
51+
* @return grid's power or {@code null} if not available
52+
*/
53+
public Float getPower() {
54+
return power;
55+
}
56+
}

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

+10-20
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,11 @@ public class Result {
4949
@SerializedName("batteryMode")
5050
private String batteryMode;
5151

52-
@SerializedName("gridCurrents")
53-
private float[] gridCurrents;
52+
@SerializedName("grid")
53+
private Grid grid;
5454

55-
@SerializedName("gridEnergy")
56-
private float gridEnergy;
57-
58-
@SerializedName("gridPower")
59-
private Float gridPower;
55+
@SerializedName("gridConfigured")
56+
private boolean gridConfigured;
6057

6158
@SerializedName("homePower")
6259
private float homePower;
@@ -165,24 +162,17 @@ public String getBatteryMode() {
165162
}
166163

167164
/**
168-
* @return grid's currents
169-
*/
170-
public float[] getGridCurrents() {
171-
return gridCurrents;
172-
}
173-
174-
/**
175-
* @return grid's energy
165+
* @return all grid related values
176166
*/
177-
public float getGridEnergy() {
178-
return gridEnergy;
167+
public Grid getGrid() {
168+
return grid;
179169
}
180170

181171
/**
182-
* @return grid's power or {@code null} if not available
172+
* @return is grid configured
183173
*/
184-
public Float getGridPower() {
185-
return gridPower;
174+
public boolean getGridConfigured() {
175+
return gridConfigured;
186176
}
187177

188178
/**

0 commit comments

Comments
 (0)