Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
venu-sagar committed Aug 1, 2023
1 parent 69cc094 commit 851a85d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions io.openems.edge.timeofusetariff.entsoe/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImmutableSortedMap<ZonedDateTime, Float>> 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(//
Expand All @@ -76,8 +78,8 @@ private void activate(ComponentContext context, Config config) {
return;
}
this.config = config;
Consumer<Currency> updateCurrency = t -> {
this.currency = t;
Consumer<Currency> updateCurrency = currency -> {
this.currency = currency;
this.executor.schedule(this.task, 0, TimeUnit.SECONDS);
};

Expand Down Expand Up @@ -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<Currency> consumer) {
public void subscribe(Consumer<Currency> updateCurrency) {

Consumer<Value<Integer>> c = t -> {
consumer.accept(t.asEnum());
Consumer<Value<Integer>> 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);
});
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 851a85d

Please sign in to comment.