From 851a85df1e8b2859146a8c31a8b428ceaba84c72 Mon Sep 17 00:00:00 2001 From: Sagar Bandi Venu Date: Tue, 1 Aug 2023 16:39:30 +0200 Subject: [PATCH] Review changes --- .../io/openems/edge/core/meta/MetaImpl.java | 1 - .../bnd.bnd | 6 +--- .../timeofusetariff/entsoe/TouEntsoeImpl.java | 32 ++++++++++--------- .../test}/.gitignore | 0 4 files changed, 18 insertions(+), 21 deletions(-) rename {io.openems.edge.controller.ess.timeofusetariff/bin_test => io.openems.edge.timeofusetariff.entsoe/test}/.gitignore (100%) diff --git a/io.openems.edge.core/src/io/openems/edge/core/meta/MetaImpl.java b/io.openems.edge.core/src/io/openems/edge/core/meta/MetaImpl.java index 85c4dc3ec51..1c62a29d894 100644 --- a/io.openems.edge.core/src/io/openems/edge/core/meta/MetaImpl.java +++ b/io.openems.edge.core/src/io/openems/edge/core/meta/MetaImpl.java @@ -40,7 +40,6 @@ private void activate(ComponentContext context, Config config) { super.activate(context, SINGLETON_COMPONENT_ID, Meta.SINGLETON_SERVICE_PID, true); this.applyConfig(config); - if (OpenemsComponent.validateSingleton(this.cm, Meta.SINGLETON_SERVICE_PID, SINGLETON_COMPONENT_ID)) { return; } diff --git a/io.openems.edge.timeofusetariff.entsoe/bnd.bnd b/io.openems.edge.timeofusetariff.entsoe/bnd.bnd index 68b6fbaf51c..5f93b54c0d0 100644 --- a/io.openems.edge.timeofusetariff.entsoe/bnd.bnd +++ b/io.openems.edge.timeofusetariff.entsoe/bnd.bnd @@ -6,14 +6,10 @@ Bundle-Version: 1.0.0.${tstamp} -buildpath: \ ${buildpath},\ com.squareup.okio,\ + io.openems.common,\ io.openems.edge.common,\ io.openems.edge.timeofusetariff.api,\ io.openems.wrapper.okhttp,\ - io.openems.common,\ -testpath: \ - com.squareup.okio,\ - io.openems.wrapper.kotlinx-coroutines-core-jvm,\ - io.openems.wrapper.okhttp,\ - org.jetbrains.kotlin.osgi-bundle,\ ${testpath} diff --git a/io.openems.edge.timeofusetariff.entsoe/src/io/openems/edge/timeofusetariff/entsoe/TouEntsoeImpl.java b/io.openems.edge.timeofusetariff.entsoe/src/io/openems/edge/timeofusetariff/entsoe/TouEntsoeImpl.java index bc36066a26e..51fdf37a5c7 100644 --- a/io.openems.edge.timeofusetariff.entsoe/src/io/openems/edge/timeofusetariff/entsoe/TouEntsoeImpl.java +++ b/io.openems.edge.timeofusetariff.entsoe/src/io/openems/edge/timeofusetariff/entsoe/TouEntsoeImpl.java @@ -48,18 +48,20 @@ ) public class TouEntsoeImpl extends AbstractOpenemsComponent implements TouEntsoe, OpenemsComponent, TimeOfUseTariff { + private static final int EUR_EXHANGE_RATE = 1; + private static final int API_EXECUTE_HOUR = 14; + private final Logger log = LoggerFactory.getLogger(TouEntsoeImpl.class); private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); private final AtomicReference> prices = new AtomicReference<>( ImmutableSortedMap.of()); + @Reference + private CurrencyProvider currencyProvider; + private Config config = null; private Currency currency; private ZonedDateTime updateTimeStamp = null; - private static final int EUR_EXHANGE_RATE = 1; - - @Reference - private CurrencyProvider currencyProvider; public TouEntsoeImpl() { super(// @@ -76,8 +78,8 @@ private void activate(ComponentContext context, Config config) { return; } this.config = config; - Consumer updateCurrency = t -> { - this.currency = t; + Consumer updateCurrency = currency -> { + this.currency = currency; this.executor.schedule(this.task, 0, TimeUnit.SECONDS); }; @@ -109,23 +111,23 @@ public Currency getCurrent() { /** * Subscribes to the Currency channel to trigger on update. * - * @param consumer The callback {@link Consumer}. + * @param updateCurrency The callback {@link Consumer}. */ - public void subscribe(Consumer consumer) { + public void subscribe(Consumer updateCurrency) { - Consumer> c = t -> { - consumer.accept(t.asEnum()); + Consumer> subscription = currency -> { + updateCurrency.accept(currency.asEnum()); }; - this.subscriptions.add(c); - this.meta.getCurrencyChannel().onSetNextValue(c); + this.subscriptions.add(subscription); + this.meta.getCurrencyChannel().onSetNextValue(subscription); } /** * Unsubscribes from all the Subscriptions. */ public void unsubscribeAll() { - this.subscriptions.forEach(t -> { - this.meta.getCurrencyChannel().removeOnSetNextValueCallback(t); + this.subscriptions.forEach(subscription -> { + this.meta.getCurrencyChannel().removeOnSetNextValueCallback(subscription); }); } } @@ -169,7 +171,7 @@ public void unsubscribeAll() { * Schedule next price update at 2 o clock every day. */ var now = ZonedDateTime.now(); - var nextRun = now.withHour(14).truncatedTo(ChronoUnit.HOURS); + var nextRun = now.withHour(API_EXECUTE_HOUR).truncatedTo(ChronoUnit.HOURS); if (unableToUpdatePrices) { // If the prices are not updated, try again in next minute. nextRun = now.plusMinutes(1).truncatedTo(ChronoUnit.MINUTES); diff --git a/io.openems.edge.controller.ess.timeofusetariff/bin_test/.gitignore b/io.openems.edge.timeofusetariff.entsoe/test/.gitignore similarity index 100% rename from io.openems.edge.controller.ess.timeofusetariff/bin_test/.gitignore rename to io.openems.edge.timeofusetariff.entsoe/test/.gitignore