Skip to content

Commit 972351b

Browse files
authored
[energidataservice] Fix @ActionOutput annotations (openhab#17679)
Related to openhab#17636 Signed-off-by: Laurent Garnier <[email protected]>
1 parent 45cfd03 commit 972351b

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActions.java

+45-29
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
package org.openhab.binding.energidataservice.internal.action;
1414

15-
import static org.openhab.binding.energidataservice.internal.EnergiDataServiceBindingConstants.*;
15+
import static org.openhab.binding.energidataservice.internal.EnergiDataServiceBindingConstants.CURRENCY_DKK;
1616

1717
import java.math.BigDecimal;
1818
import java.time.Duration;
@@ -36,8 +36,10 @@
3636
import org.openhab.binding.energidataservice.internal.PriceComponent;
3737
import org.openhab.binding.energidataservice.internal.exception.MissingPriceException;
3838
import org.openhab.binding.energidataservice.internal.handler.EnergiDataServiceHandler;
39+
import org.openhab.core.automation.Visibility;
3940
import org.openhab.core.automation.annotation.ActionInput;
4041
import org.openhab.core.automation.annotation.ActionOutput;
42+
import org.openhab.core.automation.annotation.ActionOutputs;
4143
import org.openhab.core.automation.annotation.RuleAction;
4244
import org.openhab.core.library.types.QuantityType;
4345
import org.openhab.core.library.unit.Units;
@@ -63,8 +65,8 @@ public class EnergiDataServiceActions implements ThingActions {
6365

6466
private @Nullable EnergiDataServiceHandler handler;
6567

66-
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description")
67-
public @ActionOutput(name = "prices", type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices() {
68+
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description", visibility = Visibility.HIDDEN)
69+
public @ActionOutput(type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices() {
6870
EnergiDataServiceHandler handler = this.handler;
6971
if (handler == null) {
7072
logger.warn("EnergiDataServiceActions ThingHandler is null.");
@@ -79,8 +81,8 @@ public class EnergiDataServiceActions implements ThingActions {
7981
.collect(Collectors.toSet()));
8082
}
8183

82-
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description")
83-
public @ActionOutput(name = "prices", type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices(
84+
@RuleAction(label = "@text/action.get-prices.label", description = "@text/action.get-prices.description", visibility = Visibility.HIDDEN)
85+
public @ActionOutput(type = "java.util.Map<java.time.Instant, java.math.BigDecimal>") Map<Instant, BigDecimal> getPrices(
8486
@ActionInput(name = "priceComponents", label = "@text/action.get-prices.priceComponents.label", description = "@text/action.get-prices.priceComponents.description") @Nullable String priceComponents) {
8587
if (priceComponents == null) {
8688
logger.warn("Argument 'priceComponents' is null");
@@ -100,10 +102,10 @@ public class EnergiDataServiceActions implements ThingActions {
100102
}
101103

102104
@RuleAction(label = "@text/action.calculate-price.label", description = "@text/action.calculate-price.description")
103-
public @ActionOutput(name = "price", type = "java.math.BigDecimal") @Nullable BigDecimal calculatePrice(
104-
@ActionInput(name = "start", type = "java.time.Instant") Instant start,
105-
@ActionInput(name = "end", type = "java.time.Instant") Instant end,
106-
@ActionInput(name = "power", type = "QuantityType<Power>") QuantityType<Power> power) {
105+
public @ActionOutput(label = "@text/action.calculate-price.output.label", type = "java.math.BigDecimal") @Nullable BigDecimal calculatePrice(
106+
@ActionInput(name = "start", label = "@text/action.calculate-price.input.start.label", type = "java.time.Instant") Instant start,
107+
@ActionInput(name = "end", label = "@text/action.calculate-price.input.end.label", type = "java.time.Instant") Instant end,
108+
@ActionInput(name = "power", label = "@text/action.calculate-price.input.power.label", type = "QuantityType<Power>") QuantityType<Power> power) {
107109
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
108110

109111
try {
@@ -115,10 +117,12 @@ public class EnergiDataServiceActions implements ThingActions {
115117
}
116118

117119
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
118-
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
119-
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
120-
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
121-
@ActionInput(name = "duration", type = "java.time.Duration") Duration duration) {
120+
public @ActionOutputs({
121+
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
122+
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"), }) Map<String, Object> calculateCheapestPeriod(
123+
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
124+
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
125+
@ActionInput(name = "duration", label = "@text/action.calculate-cheapest-period.input.duration.label", type = "java.time.Duration") Duration duration) {
122126
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
123127

124128
try {
@@ -143,11 +147,15 @@ public class EnergiDataServiceActions implements ThingActions {
143147
}
144148

145149
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
146-
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
147-
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
148-
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
149-
@ActionInput(name = "duration", type = "java.time.Duration") Duration duration,
150-
@ActionInput(name = "power", type = "QuantityType<Power>") QuantityType<Power> power) {
150+
public @ActionOutputs({
151+
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
152+
@ActionOutput(name = "LowestPrice", label = "@text/action.calculate-cheapest-period.output.lowest-price.label", type = "java.math.BigDecimal"),
153+
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"),
154+
@ActionOutput(name = "HighestPrice", label = "@text/action.calculate-cheapest-period.output.highest-price.label", type = "java.math.BigDecimal") }) Map<String, Object> calculateCheapestPeriod(
155+
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
156+
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
157+
@ActionInput(name = "duration", label = "@text/action.calculate-cheapest-period.input.duration.label", type = "java.time.Duration") Duration duration,
158+
@ActionInput(name = "power", label = "@text/action.calculate-cheapest-period.input.power.label", type = "QuantityType<Power>") QuantityType<Power> power) {
151159
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
152160

153161
try {
@@ -159,12 +167,16 @@ public class EnergiDataServiceActions implements ThingActions {
159167
}
160168

161169
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
162-
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
163-
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
164-
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
165-
@ActionInput(name = "totalDuration", type = "java.time.Duration") Duration totalDuration,
166-
@ActionInput(name = "durationPhases", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
167-
@ActionInput(name = "energyUsedPerPhase", type = "QuantityType<Energy>") QuantityType<Energy> energyUsedPerPhase) {
170+
public @ActionOutputs({
171+
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
172+
@ActionOutput(name = "LowestPrice", label = "@text/action.calculate-cheapest-period.output.lowest-price.label", type = "java.math.BigDecimal"),
173+
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"),
174+
@ActionOutput(name = "HighestPrice", label = "@text/action.calculate-cheapest-period.output.highest-price.label", type = "java.math.BigDecimal") }) Map<String, Object> calculateCheapestPeriod(
175+
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
176+
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
177+
@ActionInput(name = "totalDuration", label = "@text/action.calculate-cheapest-period.input.total-duration.label", type = "java.time.Duration") Duration totalDuration,
178+
@ActionInput(name = "durationPhases", label = "@text/action.calculate-cheapest-period.input.duration-phases.label", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
179+
@ActionInput(name = "energyUsedPerPhase", label = "@text/action.calculate-cheapest-period.input.energy-used-per-phase.label", type = "QuantityType<Energy>") QuantityType<Energy> energyUsedPerPhase) {
168180
PriceCalculator priceCalculator = new PriceCalculator(getPrices());
169181

170182
try {
@@ -177,11 +189,15 @@ public class EnergiDataServiceActions implements ThingActions {
177189
}
178190

179191
@RuleAction(label = "@text/action.calculate-cheapest-period.label", description = "@text/action.calculate-cheapest-period.description")
180-
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
181-
@ActionInput(name = "earliestStart", type = "java.time.Instant") Instant earliestStart,
182-
@ActionInput(name = "latestEnd", type = "java.time.Instant") Instant latestEnd,
183-
@ActionInput(name = "durationPhases", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
184-
@ActionInput(name = "powerPhases", type = "java.util.List<QuantityType<Power>>") List<QuantityType<Power>> powerPhases) {
192+
public @ActionOutputs({
193+
@ActionOutput(name = "CheapestStart", label = "@text/action.calculate-cheapest-period.output.cheapest-start.label", type = "java.time.Instant"),
194+
@ActionOutput(name = "LowestPrice", label = "@text/action.calculate-cheapest-period.output.lowest-price.label", type = "java.math.BigDecimal"),
195+
@ActionOutput(name = "MostExpensiveStart", label = "@text/action.calculate-cheapest-period.output.most-expensive-start.label", type = "java.time.Instant"),
196+
@ActionOutput(name = "HighestPrice", label = "@text/action.calculate-cheapest-period.output.highest-price.label", type = "java.math.BigDecimal") }) Map<String, Object> calculateCheapestPeriod(
197+
@ActionInput(name = "earliestStart", label = "@text/action.calculate-cheapest-period.input.earliest-start.label", type = "java.time.Instant") Instant earliestStart,
198+
@ActionInput(name = "latestEnd", label = "@text/action.calculate-cheapest-period.input.latest-end.label", type = "java.time.Instant") Instant latestEnd,
199+
@ActionInput(name = "durationPhases", label = "@text/action.calculate-cheapest-period.input.duration-phases.label", type = "java.util.List<java.time.Duration>") List<Duration> durationPhases,
200+
@ActionInput(name = "powerPhases", label = "@text/action.calculate-cheapest-period.input.power-phases.label", type = "java.util.List<QuantityType<Power>>") List<QuantityType<Power>> powerPhases) {
185201
if (durationPhases.size() != powerPhases.size()) {
186202
logger.warn("Number of duration phases ({}) is different from number of consumption phases ({})",
187203
durationPhases.size(), powerPhases.size());

bundles/org.openhab.binding.energidataservice/src/main/resources/OH-INF/i18n/energidataservice.properties

+17-1
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,25 @@ offline.conf-error.invalid-energinet-gln = Invalid Energinet GLN
110110

111111
action.calculate-cheapest-period.label = calculate cheapest period
112112
action.calculate-cheapest-period.description = calculate cheapest period for using power according to a supplied timetable (excl. VAT)
113+
action.calculate-cheapest-period.output.cheapest-start.label = Cheapest Start
114+
action.calculate-cheapest-period.output.most-expensive-start.label = Most Expensive Start
115+
action.calculate-cheapest-period.output.lowest-price.label = Lowest Price
116+
action.calculate-cheapest-period.output.highest-price.label = Highest Price
117+
action.calculate-cheapest-period.input.earliest-start.label = Earliest Start
118+
action.calculate-cheapest-period.input.latest-end.label = Latest End
119+
action.calculate-cheapest-period.input.duration.label = Duration
120+
action.calculate-cheapest-period.input.power.label = Power
121+
action.calculate-cheapest-period.input.total-duration.label = Total Duration
122+
action.calculate-cheapest-period.input.duration-phases.label = Duration Phases
123+
action.calculate-cheapest-period.input.energy-used-per-phase.label = Energy Used Per Phase
124+
action.calculate-cheapest-period.input.power-phases.label = Power Phases
113125
action.calculate-price.label = calculate price
114126
action.calculate-price.description = calculate price for power consumption in period excl. VAT
127+
action.calculate-price.output.label = Price
128+
action.calculate-price.input.start.label = Start
129+
action.calculate-price.input.end.label = End
130+
action.calculate-price.input.power.label = Power
115131
action.get-prices.label = get prices
116132
action.get-prices.description = get hourly prices excl. VAT
117-
action.get-prices.priceComponents.label = price components
133+
action.get-prices.priceComponents.label = Price Components
118134
action.get-prices.priceComponents.description = comma-separated list of price components to include in sums

0 commit comments

Comments
 (0)