diff --git a/io.openems.edge.core/src/io/openems/edge/app/timeofusetariff/AwattarHourly.java b/io.openems.edge.core/src/io/openems/edge/app/timeofusetariff/AwattarHourly.java index 016d3af4bb4..2f1a51bfb78 100644 --- a/io.openems.edge.core/src/io/openems/edge/app/timeofusetariff/AwattarHourly.java +++ b/io.openems.edge.core/src/io/openems/edge/app/timeofusetariff/AwattarHourly.java @@ -1,5 +1,8 @@ package io.openems.edge.app.timeofusetariff; +import static io.openems.edge.app.common.props.CommonProps.alias; +import static io.openems.edge.app.common.props.CommonProps.defaultDef; + import java.util.Map; import java.util.function.Function; @@ -17,7 +20,8 @@ import io.openems.common.session.Language; import io.openems.common.types.EdgeConfig; import io.openems.common.utils.JsonUtils; -import io.openems.edge.app.common.props.CommonProps; +import io.openems.edge.app.enums.OptionsFactory; +import io.openems.edge.app.enums.TranslatableEnum; import io.openems.edge.app.timeofusetariff.AwattarHourly.Property; import io.openems.edge.common.component.ComponentManager; import io.openems.edge.core.appmanager.AbstractOpenemsApp; @@ -31,9 +35,11 @@ import io.openems.edge.core.appmanager.OpenemsApp; import io.openems.edge.core.appmanager.OpenemsAppCardinality; import io.openems.edge.core.appmanager.OpenemsAppCategory; +import io.openems.edge.core.appmanager.TranslationUtil; import io.openems.edge.core.appmanager.Type; import io.openems.edge.core.appmanager.Type.Parameter.BundleParameter; import io.openems.edge.core.appmanager.dependency.Tasks; +import io.openems.edge.core.appmanager.formly.JsonFormlyUtil; /** * Describes a App for AwattarHourly. @@ -47,7 +53,8 @@ "properties":{ "CTRL_ESS_TIME_OF_USE_TARIFF_ID": "ctrlEssTimeOfUseTariff0", "TIME_OF_USE_TARIFF_PROVIDER_ID": "timeOfUseTariff0", - "CONTROL_MODE": {@link ControlMode} + "CONTROL_MODE": {@link ControlMode}, + "ZONE": {@link Zone}, }, "appDescriptor": { "websiteUrl": {@link AppDescriptor#getWebsiteUrl()} @@ -65,7 +72,16 @@ public static enum Property implements Type def // + .setTranslatedLabelWithAppPrefix(".zone.label") // + .setTranslatedDescriptionWithAppPrefix(".zone.description") // + .setRequired(true)// + .setDefaultValue(Zone.GERMANY)// + .setField(JsonFormlyUtil::buildSelectFromNameable, (app, property, l, parameter, field) -> { + field.setOptions(Zone.optionsFactory(), l); + }))); private final AppDef def; @@ -100,6 +116,7 @@ protected ThrowingTriFunction, L return (t, p, l) -> { final var timeOfUseTariffProviderId = this.getId(t, p, Property.TIME_OF_USE_TARIFF_PROVIDER_ID); final var ctrlEssTimeOfUseTariffId = this.getId(t, p, Property.CTRL_ESS_TIME_OF_USE_TARIFF_ID); + final var zone = this.getEnum(p, Zone.class, Property.ZONE); final var alias = this.getString(p, l, Property.ALIAS); @@ -110,6 +127,7 @@ protected ThrowingTriFunction, L .build()), // new EdgeConfig.Component(timeOfUseTariffProviderId, this.getName(l), "TimeOfUseTariff.Awattar", JsonUtils.buildJsonObject() // + .addProperty("zone", zone) // .build())// ); @@ -148,4 +166,33 @@ protected AwattarHourly getApp() { return this; } + public enum Zone implements TranslatableEnum { + GERMANY("germany"), // + AUSTRIA("austria"), // + ; + + private static final String TRANSLATION_PREFIX = "App.TimeOfUseTariff.Awattar.zone.option."; + + private final String translationKey; + + private Zone(String translationKey) { + this.translationKey = TRANSLATION_PREFIX + translationKey; + } + + @Override + public final String getTranslation(Language l) { + final var bundle = AbstractOpenemsApp.getTranslationBundle(l); + return TranslationUtil.getTranslation(bundle, this.translationKey); + } + + /** + * Creates a {@link OptionsFactory} of this enum. + * + * @return the {@link OptionsFactory} + */ + public static final OptionsFactory optionsFactory() { + return OptionsFactory.of(values()); + } + } + } diff --git a/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_de.properties b/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_de.properties index 09e8af311b2..97b7726bcb4 100644 --- a/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_de.properties +++ b/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_de.properties @@ -326,6 +326,10 @@ App.PvInverter.SolarEdge.Name.short = SolarEdge # Time of use Tariff App.TimeOfUseTariff.Awattar.Name = Dynamischer Stromtarif (Awattar HOURLY) App.TimeOfUseTariff.Awattar.Name.short = Awattar HOURLY +App.TimeOfUseTariff.Awattar.zone.label = Zone +App.TimeOfUseTariff.Awattar.zone.description = z.B. Deutschland, Österreich +App.TimeOfUseTariff.Awattar.zone.option.austria = Österreich +App.TimeOfUseTariff.Awattar.zone.option.germany = Deutschland App.TimeOfUseTariff.ENTSO-E.Name = Dynamischer Stromtarif (ENTSO-E) App.TimeOfUseTariff.ENTSO-E.Name.short = ENTSO-E App.TimeOfUseTariff.ENTSO-E.biddingZone.label = Gebotszone diff --git a/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_en.properties b/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_en.properties index 44708741e41..656a0da0635 100644 --- a/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_en.properties +++ b/io.openems.edge.core/src/io/openems/edge/core/appmanager/translation_en.properties @@ -326,6 +326,10 @@ App.PvInverter.SolarEdge.Name.short = SolarEdge # Time of use Tarif App.TimeOfUseTariff.Awattar.Name = Time-of-Use Tariff (Awattar HOURLY) App.TimeOfUseTariff.Awattar.Name.short = Awattar HOURLY +App.TimeOfUseTariff.Awattar.zone.label = Zone +App.TimeOfUseTariff.Awattar.zone.description = e.g. Germany, Austria +App.TimeOfUseTariff.Awattar.zone.option.austria = Austria +App.TimeOfUseTariff.Awattar.zone.option.germany = Germany App.TimeOfUseTariff.ENTSO-E.Name = Time-of-Use Tariff (ENTSO-E) App.TimeOfUseTariff.ENTSO-E.Name.short = ENTSO-E App.TimeOfUseTariff.ENTSO-E.biddingZone.label = Bidding Zone diff --git a/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/Config.java b/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/Config.java index 0b0810cf355..a526f91f0a4 100644 --- a/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/Config.java +++ b/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/Config.java @@ -17,5 +17,8 @@ @AttributeDefinition(name = "Is enabled?", description = "Is this Component enabled?") boolean enabled() default true; + @AttributeDefinition(name = "Zone", description = "Zone corresponding to the customer's location") + Zone zone() default Zone.GERMANY; + String webconsole_configurationFactory_nameHint() default "Time-Of-Use Tariff Awattar [{id}]"; } diff --git a/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImpl.java b/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImpl.java index f6487d74223..906f0c35450 100644 --- a/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImpl.java +++ b/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImpl.java @@ -48,8 +48,6 @@ public class TimeOfUseTariffAwattarImpl extends AbstractOpenemsComponent implements TimeOfUseTariff, OpenemsComponent, TimeOfUseTariffAwattar { - private static final String AWATTAR_API_URL = "https://api.awattar.de/v1/marketdata"; - private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); private final AtomicReference> prices = new AtomicReference<>( ImmutableSortedMap.of()); @@ -60,6 +58,7 @@ public class TimeOfUseTariffAwattarImpl extends AbstractOpenemsComponent @Reference private ComponentManager componentManager; + private Config config = null; private ZonedDateTime updateTimeStamp = null; public TimeOfUseTariffAwattarImpl() { @@ -77,6 +76,7 @@ private void activate(ComponentContext context, Config config) { return; } + this.config = config; this.executor.schedule(this.task, 0, TimeUnit.SECONDS); } @@ -93,8 +93,9 @@ protected void deactivate() { * Update Map of prices */ var client = new OkHttpClient(); + final var url = this.config.zone().toUrl(); var request = new Request.Builder() // - .url(AWATTAR_API_URL) // + .url(url) // // aWATTar currently does not anymore require an Apikey. // .header("Authorization", Credentials.basic(apikey, "")) // .build(); @@ -165,7 +166,7 @@ public static ImmutableSortedMap parsePrices(String jsonDa var startTimeStamp = ZonedDateTime // .ofInstant(Instant.ofEpochMilli(startTimestampLong), ZoneId.systemDefault()) .truncatedTo(ChronoUnit.HOURS); - + // Adding the values in the Map. result.put(startTimeStamp, marketPrice); result.put(startTimeStamp.plusMinutes(15), marketPrice); diff --git a/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/Zone.java b/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/Zone.java new file mode 100644 index 00000000000..83b7aee1ed5 --- /dev/null +++ b/io.openems.edge.timeofusetariff.awattar/src/io/openems/edge/timeofusetariff/awattar/Zone.java @@ -0,0 +1,29 @@ +package io.openems.edge.timeofusetariff.awattar; + +/** + * Represents different energy market zones. + */ +public enum Zone { + + /** + * The energy market zone for Germany. + */ + GERMANY, // + + /** + * The energy market zone for Austria. + */ + AUSTRIA; + + /** + * Returns the API URL specific to the {@link Zone}. + * + * @return The {@link Zone} specific API URL. + */ + public String toUrl() { + return switch (this) { + case GERMANY -> "https://api.awattar.de/v1/marketdata"; + case AUSTRIA -> "https://api.awattar.at/v1/marketdata"; + }; + } +} diff --git a/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/MyConfig.java b/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/MyConfig.java index 5295e2ed29f..2696e4c150e 100644 --- a/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/MyConfig.java +++ b/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/MyConfig.java @@ -7,7 +7,7 @@ public class MyConfig extends AbstractComponentConfig implements Config { public static class Builder { private String id; - private int zipcode; + private Zone zone; private Builder() { } @@ -17,6 +17,11 @@ public Builder setId(String id) { return this; } + public Builder setZone(Zone zone) { + this.zone = zone; + return this; + } + public MyConfig build() { return new MyConfig(this); } @@ -38,4 +43,9 @@ private MyConfig(Builder builder) { this.builder = builder; } + @Override + public Zone zone() { + return this.builder.zone; + } + } \ No newline at end of file diff --git a/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImplTest.java b/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImplTest.java index 43cb18a941d..6b819d8abd4 100644 --- a/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImplTest.java +++ b/io.openems.edge.timeofusetariff.awattar/test/io/openems/edge/timeofusetariff/awattar/TimeOfUseTariffAwattarImplTest.java @@ -22,11 +22,9 @@ public void test() throws Exception { new ComponentTest(awattar) // .activate(MyConfig.create() // .setId(CTRL_ID) // + .setZone(Zone.GERMANY) // .build()) // ; - - // Thread.sleep(5000); - // System.out.println(sut.getPrices()); } @Test