From dfa4dbaf4789500a8484d052bed6bdbe2030baf1 Mon Sep 17 00:00:00 2001 From: Johan Vos Date: Sun, 7 Jan 2024 10:55:07 +0100 Subject: [PATCH 1/3] Use default values for some configproperties, as they are required for testing Fixes #2 --- src/main/java/homecontrol/impl/slack/SlackService.java | 4 ++-- src/main/java/homecontrol/impl/sma/SMACharger.java | 2 +- src/main/java/homecontrol/impl/sma/SMAInverter.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/homecontrol/impl/slack/SlackService.java b/src/main/java/homecontrol/impl/slack/SlackService.java index fb0cb7d..fc9f2bf 100644 --- a/src/main/java/homecontrol/impl/slack/SlackService.java +++ b/src/main/java/homecontrol/impl/slack/SlackService.java @@ -18,9 +18,9 @@ @ApplicationScoped public class SlackService implements NotificationService { - @ConfigProperty(name = "EVCHARGING_SLACK_URL") + @ConfigProperty(name = "EVCHARGING_SLACK_URL", defaultValue="NONE") String slackUrl; - @ConfigProperty(name = "EVCHARGING_SLACK_CHANNEL") + @ConfigProperty(name = "EVCHARGING_SLACK_CHANNEL", defaultValue="NONE") String channel; @Inject diff --git a/src/main/java/homecontrol/impl/sma/SMACharger.java b/src/main/java/homecontrol/impl/sma/SMACharger.java index cfc2583..973ea94 100644 --- a/src/main/java/homecontrol/impl/sma/SMACharger.java +++ b/src/main/java/homecontrol/impl/sma/SMACharger.java @@ -19,7 +19,7 @@ @ApplicationScoped public class SMACharger implements Charger { - @ConfigProperty(name = "EVCHARGING_CHARGER_IP") + @ConfigProperty(name = "EVCHARGING_CHARGER_IP", defaultValue="NONE") String chargerIp; @ConfigProperty(name = "EVCHARGING_CHARGER_USERNAME") String chargerUserName; diff --git a/src/main/java/homecontrol/impl/sma/SMAInverter.java b/src/main/java/homecontrol/impl/sma/SMAInverter.java index 823ad7e..c802015 100644 --- a/src/main/java/homecontrol/impl/sma/SMAInverter.java +++ b/src/main/java/homecontrol/impl/sma/SMAInverter.java @@ -27,9 +27,9 @@ @ApplicationScoped public class SMAInverter implements Inverter { public static final Logger LOGGER = Logger.getLogger(SMAInverter.class.getName()); - @ConfigProperty(name = "EVCHARGING_INVERTER_IP") + @ConfigProperty(name = "EVCHARGING_INVERTER_IP", defaultValue="NONE") String inverterIp; - @ConfigProperty(name = "EVCHARGING_INVERTER_PASSWORD") + @ConfigProperty(name = "EVCHARGING_INVERTER_PASSWORD", defaultValue="NONE") String inverterPassword; String sid; From 191432e72b66db04809fa252a534918afb81ba26 Mon Sep 17 00:00:00 2001 From: Johan Vos Date: Sun, 7 Jan 2024 11:19:29 +0100 Subject: [PATCH 2/3] Conditionally avoid trying to get gas info. Don't crash when NONE config properties are used. --- src/main/java/homecontrol/impl/hwep1/HWEP1Client.java | 10 +++++++++- src/main/java/homecontrol/impl/sma/SMACharger.java | 5 +++++ src/main/java/homecontrol/impl/sma/SMAInverter.java | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java b/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java index bbeaec8..2cb4505 100644 --- a/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java +++ b/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java @@ -26,6 +26,14 @@ public class HWEP1Client { @ConfigProperty(name = "EVCHARGING_HWEP1_IP") String ip; + + @ConfigProperty(name = "HAS_GAS", defaultValue = "true") + String hasGas; + + + boolean hasGas() { + return Boolean.valueOf(hasGas); + } @CacheResult(cacheName = "hwep1-data") JsonObject getJsonData() throws IOException { @@ -93,7 +101,7 @@ Telegram parseTelegram(String body) { if (gas != null && gas.size() > 1) { telegram.setTotal_gas_m3(new BigDecimal(parseValue(gas.get(1)))); } - telegram.setTotal_gas_m3(new BigDecimal(parseValue(map.get("0-1:24.2.3").get(1)))); + if (hasGas()) telegram.setTotal_gas_m3(new BigDecimal(parseValue(map.get("0-1:24.2.3").get(1)))); telegram.setActive_power_average_w(new BigDecimal(parseValue(map.get("1-0:1.4.0").get(0))).multiply(new BigDecimal(1000)).intValue()); telegram.setActive_power_import_w(new BigDecimal(parseValue(map.get("1-0:1.7.0").get(0))).multiply(new BigDecimal(1000)).intValue()); telegram.setActive_power_export_w(new BigDecimal(parseValue(map.get("1-0:2.7.0").get(0))).multiply(new BigDecimal(1000)).intValue()); diff --git a/src/main/java/homecontrol/impl/sma/SMACharger.java b/src/main/java/homecontrol/impl/sma/SMACharger.java index 973ea94..dd1f6b0 100644 --- a/src/main/java/homecontrol/impl/sma/SMACharger.java +++ b/src/main/java/homecontrol/impl/sma/SMACharger.java @@ -53,6 +53,7 @@ public State getCurrentState(StateRefresh stateRefresh) { @Asynchronous @Retry(maxRetries = 3, delay = 2, delayUnit = ChronoUnit.SECONDS) public Uni getActivePower() { + if (isDisabled()) return Uni.createFrom().item(0); int activePower = (int) getLivePowerMeterReading(); return Uni.createFrom().item(activePower); } @@ -64,6 +65,7 @@ public int getChargingMeterReading() { } public State getStateInternal() { + if (isDisabled()) return State.NotConnected; try { if (token == null) { token = authenticate(); @@ -204,4 +206,7 @@ private String authenticate() { } } + boolean isDisabled() { + return "NONE".equals(chargerIp); + } } diff --git a/src/main/java/homecontrol/impl/sma/SMAInverter.java b/src/main/java/homecontrol/impl/sma/SMAInverter.java index c802015..77be9df 100644 --- a/src/main/java/homecontrol/impl/sma/SMAInverter.java +++ b/src/main/java/homecontrol/impl/sma/SMAInverter.java @@ -38,6 +38,7 @@ public class SMAInverter implements Inverter { @Retry(maxRetries = 3, delay = 2, delayUnit = ChronoUnit.SECONDS) @Asynchronous public Uni getCurrentYield() { + if (isDisabled()) return Uni.createFrom().item(0); return Uni.createFrom().item(getLiveSMAPowerDataInternal()); } @@ -184,4 +185,8 @@ private void logout() { } } } + + boolean isDisabled() { + return "NONE".equals(inverterIp); + } } From f2508cbe091523ae1c1f81e2563edc1e8ce6c49d Mon Sep 17 00:00:00 2001 From: Johan Vos Date: Sun, 7 Jan 2024 11:27:13 +0100 Subject: [PATCH 3/3] Remove tabs --- src/main/java/homecontrol/impl/hwep1/HWEP1Client.java | 3 +-- src/main/java/homecontrol/impl/sma/SMAInverter.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java b/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java index 2cb4505..169ba43 100644 --- a/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java +++ b/src/main/java/homecontrol/impl/hwep1/HWEP1Client.java @@ -26,10 +26,9 @@ public class HWEP1Client { @ConfigProperty(name = "EVCHARGING_HWEP1_IP") String ip; - + @ConfigProperty(name = "HAS_GAS", defaultValue = "true") String hasGas; - boolean hasGas() { return Boolean.valueOf(hasGas); diff --git a/src/main/java/homecontrol/impl/sma/SMAInverter.java b/src/main/java/homecontrol/impl/sma/SMAInverter.java index 77be9df..8d52f40 100644 --- a/src/main/java/homecontrol/impl/sma/SMAInverter.java +++ b/src/main/java/homecontrol/impl/sma/SMAInverter.java @@ -185,7 +185,7 @@ private void logout() { } } } - + boolean isDisabled() { return "NONE".equals(inverterIp); }