Skip to content

Commit bf2d728

Browse files
committed
Major Growatt API change
1 parent 77d6be0 commit bf2d728

File tree

4 files changed

+54
-32
lines changed

4 files changed

+54
-32
lines changed

src/main/java/de/blafoo/bkw/views/bkw/BkwFeignView.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import com.vaadin.flow.router.Route;
55
import de.blafoo.bkw.views.MainLayout;
66
import de.blafoo.growatt.controller.GrowattWebClient;
7-
import de.blafoo.growatt.entity.TotalDataResponse;
7+
import de.blafoo.growatt.entity.DevicesResponse;
8+
import de.blafoo.growatt.entity.YearResponse;
89
import de.blafoo.growatt.feign.GrowattFeignClient;
910
import de.blafoo.growatt.feign.GrowattFeignCookieJar;
1011
import de.blafoo.growatt.md5.MD5;
@@ -34,9 +35,9 @@ public BkwFeignView(@Autowired GrowattFeignClient growatt, @Autowired GrowattFei
3435
}
3536

3637
private String createBody(@NonNull String plantId, @Nullable String date, @Nullable Integer year, @Nullable String params) {
37-
var map = GrowattWebClient.createBody(plantId, date, year, params);
38+
var payload = GrowattWebClient.createBody(plantId, date, year, params);
3839
return UriComponentsBuilder.newInstance()
39-
.queryParams(map)
40+
.queryParams(payload)
4041
.build()
4142
.encode()
4243
.getQuery();
@@ -47,12 +48,18 @@ protected String login() {
4748
growatt.login("account=%s&passwordCrc=%s".formatted(account, MD5.md5(password)));
4849
return cookieJar.getCookie("onePlantId", null);
4950
}
50-
51+
5152
@Override
52-
protected TotalDataResponse getTotalData(@NonNull String plantId) {
53-
return growatt.getTotalData(createBody(plantId, null, null, ""));
53+
protected DevicesResponse getDevicesByPlantList(@NonNull String plantId) {
54+
return growatt.getDevicesByPlantList("currPage=%s&plantId=%s".formatted("1", plantId));
5455
}
55-
56+
57+
@Override
58+
protected YearResponse getEnergyTotalChart(@NonNull String plantId, int lastYear) {
59+
return growatt.getEnergyTotalChart(createBody(plantId, null, lastYear, "energy,autoEnergy"));
60+
}
61+
62+
5663
@Override
5764
protected List<Double> getYearlyProduction(@NonNull String plantId, int year) {
5865
return growatt.getEnergyYearChart(createBody(plantId, null, year, "")).getObj().getFirst().getDatas().getEnergy();

src/main/java/de/blafoo/bkw/views/bkw/BkwGrowattView.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import com.vaadin.flow.router.RouteAlias;
66
import de.blafoo.bkw.views.MainLayout;
77
import de.blafoo.growatt.controller.GrowattWebClient;
8-
import de.blafoo.growatt.entity.TotalDataResponse;
8+
import de.blafoo.growatt.entity.DevicesResponse;
9+
import de.blafoo.growatt.entity.YearResponse;
910
import org.springframework.beans.factory.annotation.Autowired;
1011
import org.springframework.beans.factory.annotation.Value;
1112
import org.springframework.lang.NonNull;
@@ -31,13 +32,18 @@ protected String login() {
3132
growatt.login(account, password);
3233
return growatt.getPlantId();
3334
}
34-
35+
3536
@Override
36-
protected TotalDataResponse getTotalData(@NonNull String plantId) {
37-
return growatt.getTotalData(plantId);
37+
protected DevicesResponse getDevicesByPlantList(@NonNull String plantId) {
38+
return growatt.getDevicesByPlantList(plantId);
3839
}
39-
40-
@Override
40+
41+
@Override
42+
protected YearResponse getEnergyTotalChart(@NonNull String plantId, int year) {
43+
return growatt.getEnergyTotalChart(plantId, year);
44+
}
45+
46+
@Override
4147
protected List<Double> getYearlyProduction(@NonNull String plantId, int year) {
4248
return growatt.getEnergyYearChart(plantId, year).getObj().getFirst().getDatas().getEnergy();
4349
}

src/main/java/de/blafoo/bkw/views/bkw/BkwView.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import com.vaadin.flow.router.AfterNavigationObserver;
2323
import com.vaadin.flow.router.PreserveOnRefresh;
2424
import com.vaadin.flow.theme.lumo.LumoUtility.*;
25-
import de.blafoo.growatt.entity.TotalDataResponse;
25+
import de.blafoo.growatt.entity.DevicesResponse;
26+
import de.blafoo.growatt.entity.YearResponse;
2627
import jakarta.annotation.PostConstruct;
2728
import org.apache.commons.lang3.StringUtils;
2829
import org.springframework.lang.NonNull;
@@ -43,7 +44,7 @@ abstract class BkwView extends Main implements AfterNavigationObserver {
4344

4445
private String plantId;
4546

46-
private TotalDataResponse totalData;
47+
private DevicesResponse totalData;
4748

4849
private Select<Integer> yearSelect;
4950

@@ -64,28 +65,31 @@ public BkwView(String account, String password) {
6465
@PostConstruct
6566
protected void init() {
6667
addClassName("bkw-view");
68+
int thisYear = LocalDate.now().getYear();
6769

6870
plantId = login();
69-
totalData = getTotalData(plantId);
71+
72+
totalData = getDevicesByPlantList(plantId);
73+
YearResponse years = getEnergyTotalChart(plantId, thisYear);
74+
long yearsWithProduction = years.getObj().getFirst().getDatas().getEnergy().stream().filter(energy -> energy > 0).count();
7075

71-
int gridYear = Integer.parseInt(totalData.getObj().getGridDate().split("-")[0]);
7276
yearSelect = new Select<>();
73-
yearSelect.setItems(IntStream.range(gridYear, LocalDate.now().getYear()+1).boxed().toList());
74-
yearSelect.setValue(LocalDate.now().getYear());
77+
yearSelect.setItems(IntStream.range(thisYear-(int)yearsWithProduction+1, thisYear+1).boxed().toList());
78+
yearSelect.setValue(thisYear);
7579
yearSelect.addValueChangeListener(e -> UI.getCurrent().navigate(this.getClass()));
7680
}
7781

7882
@Override
7983
public void afterNavigation(AfterNavigationEvent event) {
8084
this.removeAll();
8185

82-
double eTotal = totalData.getObj().getETotal();
86+
double eTotal = totalData.getObj().getDatas().getFirst().getETotal();
8387
Board board = new Board();
8488
board.addRow(
85-
createHighlight("Total production", totalData.getObj().getETotal(), null),
86-
createHighlight("Monthly production", totalData.getObj().getEMonth(), null),
87-
createHighlight("Daily production", totalData.getObj().getEToday(), eTotal / Double.valueOf(totalData.getObj().getRunDay())),
88-
createHighlight("Current production", totalData.getObj().getPac(), null)
89+
createHighlight("Total production", totalData.getObj().getDatas().getFirst().getETotal(), null),
90+
createHighlight("Monthly production", totalData.getObj().getDatas().getFirst().getEMonth(), null),
91+
createHighlight("Daily production", totalData.getObj().getDatas().getFirst().getEToday(), null),
92+
createHighlight("Current production", totalData.getObj().getDatas().getFirst().getPac(), null)
8993
);
9094
board.addRow(createYearlyOverview(plantId));
9195
board.addRow(createMonthlyOverview(plantId), createDailyOverview(plantId));
@@ -262,9 +266,11 @@ private HorizontalLayout createHeader(String title, String subtitle) {
262266
}
263267

264268
protected abstract String login();
265-
266-
protected abstract TotalDataResponse getTotalData(@NonNull String plantId);
267-
269+
270+
protected abstract DevicesResponse getDevicesByPlantList(@NonNull String plantId);
271+
272+
protected abstract YearResponse getEnergyTotalChart(@NonNull String plantId, int year);
273+
268274
protected abstract List<Double> getYearlyProduction(@NonNull String plantId, int year);
269275

270276
protected abstract List<Double> getMonthlyProduction(@NonNull String plantId, LocalDate date);

src/main/java/de/blafoo/growatt/feign/GrowattFeignClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package de.blafoo.growatt.feign;
22

33
import de.blafoo.growatt.entity.DayResponse;
4+
import de.blafoo.growatt.entity.DevicesResponse;
45
import de.blafoo.growatt.entity.MonthResponse;
5-
import de.blafoo.growatt.entity.TotalDataResponse;
66
import de.blafoo.growatt.entity.YearResponse;
77
import org.springframework.cloud.openfeign.FeignClient;
88
import org.springframework.http.MediaType;
@@ -14,10 +14,13 @@ public interface GrowattFeignClient {
1414

1515
@PostMapping(value = "/login", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
1616
String login(@RequestBody String userPassword);
17-
18-
@PostMapping(value = "/indexbC/getTotalData", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
19-
TotalDataResponse getTotalData(@RequestBody String request);
20-
17+
18+
@PostMapping(value = "/panel/getDevicesByPlantList", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
19+
DevicesResponse getDevicesByPlantList(@RequestBody String request);
20+
21+
@PostMapping(value = "/energy/compare/getDevicesTotalChart", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
22+
YearResponse getEnergyTotalChart(@RequestBody String request);
23+
2124
@PostMapping(value = "/energy/compare/getDevicesYearChart", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
2225
YearResponse getEnergyYearChart(@RequestBody String request);
2326

0 commit comments

Comments
 (0)