Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
blafoo committed Jan 13, 2024
1 parent ff7335f commit 529a997
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/main/java/de/blafoo/bkw/views/bkw/BkwFeignView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.blafoo.growatt.feign.GrowattFeignClient;
import de.blafoo.growatt.feign.GrowattFeignCookieJar;

@SuppressWarnings("serial")
@PageTitle("BKW (Feign)")
@Route(value = "bkwfeign", layout = MainLayout.class)
public class BkwFeignView extends BkwView {
Expand All @@ -40,7 +41,7 @@ protected String login() {

@Override
protected TotalDataResponse getTotalData(@NonNull String plantId) {
return growatt.getTotalData(new EnergyRequest(plantId, null));
return growatt.getTotalData(new EnergyRequest(plantId));
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/blafoo/bkw/views/bkw/BkwGrowattView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.blafoo.growatt.entity.LoginRequest;
import de.blafoo.growatt.entity.TotalDataResponse;

@SuppressWarnings("serial")
@PageTitle("BKW (Growatt)")
@Route(value = "bkwgrowatt", layout = MainLayout.class)
@RouteAlias(value = "", layout = MainLayout.class)
Expand All @@ -37,7 +38,7 @@ protected String login() {

@Override
protected TotalDataResponse getTotalData(@NonNull String plantId) {
return growatt.getTotalData(new EnergyRequest(plantId, null));
return growatt.getTotalData(new EnergyRequest(plantId));
}

@Override
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/de/blafoo/bkw/views/bkw/BkwView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.lang.NonNull;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.board.Board;
import com.vaadin.flow.component.charts.Chart;
import com.vaadin.flow.component.charts.model.ChartType;
Expand All @@ -27,6 +28,9 @@
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.AfterNavigationEvent;
import com.vaadin.flow.router.AfterNavigationObserver;
import com.vaadin.flow.router.PreserveOnRefresh;
import com.vaadin.flow.theme.lumo.LumoUtility.BoxSizing;
import com.vaadin.flow.theme.lumo.LumoUtility.FontSize;
import com.vaadin.flow.theme.lumo.LumoUtility.FontWeight;
Expand All @@ -37,20 +41,26 @@
import de.blafoo.growatt.entity.TotalDataResponse;
import jakarta.annotation.PostConstruct;

abstract class BkwView extends Main {
@SuppressWarnings("serial")
@PreserveOnRefresh
abstract class BkwView extends Main implements AfterNavigationObserver {

protected String account;

protected String password;

private String plantId;

private TotalDataResponse totalData;

private Select<String> yearSelect;

private String month;

private Chart yearChart;

private Chart monthChart;

public BkwView(String account, String password) {
if ( StringUtils.isBlank(account) || StringUtils.isBlank(password) )
throw new IllegalArgumentException("account and password must not be empty - add them to the application.properites");
Expand All @@ -63,18 +73,24 @@ public BkwView(String account, String password) {
protected void init() {
addClassName("bkw-view");

String plantId = login();
var totalData = getTotalData(plantId);
plantId = login();
totalData = getTotalData(plantId);

yearSelect = new Select<>();
var gridYear = Integer.valueOf(totalData.getObj().getGridDate().split("-")[0]);
yearSelect.setItems(IntStream.range(gridYear, LocalDate.now().getYear()+1).mapToObj(String::valueOf).toList());
yearSelect.setValue(String.valueOf(LocalDate.now().getYear()));
yearSelect.addValueChangeListener(e -> UI.getCurrent().navigate(this.getClass()));
}

@Override
public void afterNavigation(AfterNavigationEvent event) {
this.removeAll();

double eTotal = totalData.getObj().getETotal();
Board board = new Board();
board.addRow(
createHighlight("Yearly production", totalData.getObj().getETotal(), null),
createHighlight("Total production", totalData.getObj().getETotal(), null),
createHighlight("Monthly production", totalData.getObj().getEMonth(), null),
createHighlight("Daily production", totalData.getObj().getEToday(), eTotal / Double.valueOf(totalData.getObj().getRunDay())),
createHighlight("Current production", totalData.getObj().getPac(), null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class GrowattFeignCookieJar {

Map<String, String> cookies = new HashMap<>();
private Map<String, String> cookies = new HashMap<>();

public String getCookie(String cookie, String defaultValue) {
return cookies.getOrDefault(cookie, defaultValue);
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/application.yml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server.port=${PORT:8080}
logging.level.org.atmosphere = warn
logging.level.de.blafoo = DEBUG
spring.mustache.check-template-location = false

# Launch the default browser when starting the application in development mode
vaadin.launch-browser=true
# To improve the performance during development.
# For more information https://vaadin.com/docs/flow/spring/tutorial-spring-configuration.html#special-configuration-parameters
vaadin.whitelisted-packages = com.vaadin,org.vaadin,dev.hilla,de.blafoo.bkw
spring.jpa.defer-datasource-initialization = true

growatt.account =
growatt.password =

spring.cloud.openfeign.client.config.growatt-client.loggerLevel = BASIC

0 comments on commit 529a997

Please sign in to comment.