2222import com .vaadin .flow .router .AfterNavigationObserver ;
2323import com .vaadin .flow .router .PreserveOnRefresh ;
2424import 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 ;
2627import jakarta .annotation .PostConstruct ;
2728import org .apache .commons .lang3 .StringUtils ;
2829import 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 );
0 commit comments