[energidataservice] Fix @ActionOutput annotations (#17679)

Related to #17636

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
lolodomo 2024-11-11 14:21:12 +01:00 committed by Ciprian Pascu
parent e696cdd079
commit d2cbbeea9d
2 changed files with 62 additions and 30 deletions

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.energidataservice.internal.action;
import static org.openhab.binding.energidataservice.internal.EnergiDataServiceBindingConstants.*;
import static org.openhab.binding.energidataservice.internal.EnergiDataServiceBindingConstants.CURRENCY_DKK;
import java.math.BigDecimal;
import java.time.Duration;
@ -36,8 +36,10 @@ import org.openhab.binding.energidataservice.internal.PriceCalculator;
import org.openhab.binding.energidataservice.internal.PriceComponent;
import org.openhab.binding.energidataservice.internal.exception.MissingPriceException;
import org.openhab.binding.energidataservice.internal.handler.EnergiDataServiceHandler;
import org.openhab.core.automation.Visibility;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.ActionOutputs;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
@ -63,8 +65,8 @@ public class EnergiDataServiceActions implements ThingActions {
private @Nullable EnergiDataServiceHandler handler;
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description")
public @ActionOutput(name = "prices", type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices() {
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description", visibility = Visibility.HIDDEN)
public @ActionOutput(type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices() {
EnergiDataServiceHandler handler = this.handler;
if (handler == null) {
logger.warn("EnergiDataServiceActions ThingHandler is null.");
@ -79,8 +81,8 @@ public class EnergiDataServiceActions implements ThingActions {
.collect(Collectors.toSet()));
}
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description")
public @ActionOutput(name = "prices", type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices(
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description", visibility = Visibility.HIDDEN)
public @ActionOutput(type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices(
@ActionInput(name = "priceComponents", label = "@text/action.get-prices.priceComponents.label", description = "@text/action.get-prices.priceComponents.description") @Nullable String priceComponents) {
if (priceComponents == null) {
logger.warn("Argument 'priceComponents' is null");
@ -100,10 +102,10 @@ public class EnergiDataServiceActions implements ThingActions {
}
@RuleAction(label = "@text/action.calculate-price.label", description = "@text/action.calculate-price.description")
public @ActionOutput(name = "price", type = "java.math.BigDecimal") @Nullable BigDecimal calculatePrice(
@ActionInput(name = "start", type = "java.time.Instant") Instant start,
@ActionInput(name = "end", type = "java.time.Instant") Instant end,
@ActionInput(name = "power", type = "QuantityType<Power>") QuantityType<Power> power) {
public @ActionOutput(label = "@text/action.calculate-price.output.label", type = "java.math.BigDecimal") @Nullable BigDecimal calculatePrice(
@ActionInput(name = "start", label = "@text/action.calculate-price.input.start.label", type = "java.time.Instant") Instant start,
@ActionInput(name = "end", label = "@text/action.calculate-price.input.end.label", type = "java.time.Instant") Instant end,
@ActionInput(name = "power", label = "@text/action.calculate-price.input.power.label", type = "QuantityType<Power>") QuantityType<Power> power) {
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
try {
@ -115,10 +117,12 @@ public class EnergiDataServiceActions implements ThingActions {
}
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "duration", type = "java.time.Duration") Duration duration) {
public @ActionOutputs({
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"), }) Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "duration", label = "@text/action.calculate-cheapest-period.input.duration.label", type = "java.time.Duration") Duration duration) {
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
try {
@ -143,11 +147,15 @@ public class EnergiDataServiceActions implements ThingActions {
}
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "duration", type = "java.time.Duration") Duration duration,
@ActionInput(name = "power", type = "QuantityType<Power>") QuantityType<Power> power) {
public @ActionOutputs({
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
@ActionOutput(name = "LowestPrice", label = "@text/action.calculate-cheapest-period.output.lowest-price.label", type = "java.math.BigDecimal"),
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"),
@ActionOutput(name = "HighestPrice", label = "@text/action.calculate-cheapest-period.output.highest-price.label", type = "java.math.BigDecimal") }) Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "duration", label = "@text/action.calculate-cheapest-period.input.duration.label", type = "java.time.Duration") Duration duration,
@ActionInput(name = "power", label = "@text/action.calculate-cheapest-period.input.power.label", type = "QuantityType<Power>") QuantityType<Power> power) {
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
try {
@ -159,12 +167,16 @@ public class EnergiDataServiceActions implements ThingActions {
}
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "totalDuration", type = "java.time.Duration") Duration totalDuration,
@ActionInput(name = "durationPhases", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
@ActionInput(name = "energyUsedPerPhase", type = "QuantityType<Energy>") QuantityType<Energy> energyUsedPerPhase) {
public @ActionOutputs({
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
@ActionOutput(name = "LowestPrice", label = "@text/action.calculate-cheapest-period.output.lowest-price.label", type = "java.math.BigDecimal"),
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"),
@ActionOutput(name = "HighestPrice", label = "@text/action.calculate-cheapest-period.output.highest-price.label", type = "java.math.BigDecimal") }) Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "totalDuration", label = "@text/action.calculate-cheapest-period.input.total-duration.label", type = "java.time.Duration") Duration totalDuration,
@ActionInput(name = "durationPhases", label = "@text/action.calculate-cheapest-period.input.duration-phases.label", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
@ActionInput(name = "energyUsedPerPhase", label = "@text/action.calculate-cheapest-period.input.energy-used-per-phase.label", type = "QuantityType<Energy>") QuantityType<Energy> energyUsedPerPhase) {
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
try {
@ -177,11 +189,15 @@ public class EnergiDataServiceActions implements ThingActions {
}
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "durationPhases", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
@ActionInput(name = "powerPhases", type = "java.util.List<QuantityType<Power>>") List<QuantityType<Power>> powerPhases) {
public @ActionOutputs({
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
@ActionOutput(name = "LowestPrice", label = "@text/action.calculate-cheapest-period.output.lowest-price.label", type = "java.math.BigDecimal"),
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"),
@ActionOutput(name = "HighestPrice", label = "@text/action.calculate-cheapest-period.output.highest-price.label", type = "java.math.BigDecimal") }) Map<String, Object> calculateCheapestPeriod(
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
@ActionInput(name = "durationPhases", label = "@text/action.calculate-cheapest-period.input.duration-phases.label", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
@ActionInput(name = "powerPhases", label = "@text/action.calculate-cheapest-period.input.power-phases.label", type = "java.util.List<QuantityType<Power>>") List<QuantityType<Power>> powerPhases) {
if (durationPhases.size() != powerPhases.size()) {
logger.warn("Number of duration phases ({}) is different from number of consumption phases ({})",
durationPhases.size(), powerPhases.size());

View File

@ -110,9 +110,25 @@ offline.conf-error.invalid-energinet-gln = Invalid Energinet GLN
action.calculate-cheapest-period.label = calculate cheapest period
action.calculate-cheapest-period.description = calculate cheapest period for using power according to a supplied timetable (excl. VAT)
action.calculate-cheapest-period.output.cheapest-start.label = Cheapest Start
action.calculate-cheapest-period.output.most-expensive-start.label = Most Expensive Start
action.calculate-cheapest-period.output.lowest-price.label = Lowest Price
action.calculate-cheapest-period.output.highest-price.label = Highest Price
action.calculate-cheapest-period.input.earliest-start.label = Earliest Start
action.calculate-cheapest-period.input.latest-end.label = Latest End
action.calculate-cheapest-period.input.duration.label = Duration
action.calculate-cheapest-period.input.power.label = Power
action.calculate-cheapest-period.input.total-duration.label = Total Duration
action.calculate-cheapest-period.input.duration-phases.label = Duration Phases
action.calculate-cheapest-period.input.energy-used-per-phase.label = Energy Used Per Phase
action.calculate-cheapest-period.input.power-phases.label = Power Phases
action.calculate-price.label = calculate price
action.calculate-price.description = calculate price for power consumption in period excl. VAT
action.calculate-price.output.label = Price
action.calculate-price.input.start.label = Start
action.calculate-price.input.end.label = End
action.calculate-price.input.power.label = Power
action.get-prices.label = get prices
action.get-prices.description = get hourly prices excl. VAT
action.get-prices.priceComponents.label = price components
action.get-prices.priceComponents.label = Price Components
action.get-prices.priceComponents.description = comma-separated list of price components to include in sums