-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fronius] Thing actions: Return boolean & Annotate all inputs as required #17623
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.fronius.internal.handler.FroniusSymoInverterHandler; | ||
import org.openhab.core.automation.annotation.ActionInput; | ||
import org.openhab.core.automation.annotation.ActionOutput; | ||
import org.openhab.core.automation.annotation.RuleAction; | ||
import org.openhab.core.library.types.QuantityType; | ||
import org.openhab.core.thing.binding.ThingActions; | ||
|
@@ -41,59 +42,59 @@ | |
public class FroniusSymoInverterActions implements ThingActions { | ||
private @Nullable FroniusSymoInverterHandler handler; | ||
|
||
public static void resetBatteryControl(ThingActions actions) { | ||
public static boolean resetBatteryControl(ThingActions actions) { | ||
if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) { | ||
froniusSymoInverterActions.resetBatteryControl(); | ||
return froniusSymoInverterActions.resetBatteryControl(); | ||
} else { | ||
throw new IllegalArgumentException( | ||
"The 'actions' argument is not an instance of FroniusSymoInverterActions"); | ||
} | ||
} | ||
|
||
public static void holdBatteryCharge(ThingActions actions) { | ||
public static boolean holdBatteryCharge(ThingActions actions) { | ||
if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) { | ||
froniusSymoInverterActions.holdBatteryCharge(); | ||
return froniusSymoInverterActions.holdBatteryCharge(); | ||
} else { | ||
throw new IllegalArgumentException( | ||
"The 'actions' argument is not an instance of FroniusSymoInverterActions"); | ||
} | ||
} | ||
|
||
public static void addHoldBatteryChargeSchedule(ThingActions actions, LocalTime from, LocalTime until) { | ||
public static boolean addHoldBatteryChargeSchedule(ThingActions actions, LocalTime from, LocalTime until) { | ||
if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) { | ||
froniusSymoInverterActions.addHoldBatteryChargeSchedule(from, until); | ||
return froniusSymoInverterActions.addHoldBatteryChargeSchedule(from, until); | ||
} else { | ||
throw new IllegalArgumentException( | ||
"The 'actions' argument is not an instance of FroniusSymoInverterActions"); | ||
} | ||
} | ||
|
||
public static void addHoldBatteryChargeSchedule(ThingActions actions, ZonedDateTime from, ZonedDateTime until) { | ||
addHoldBatteryChargeSchedule(actions, from.toLocalTime(), until.toLocalTime()); | ||
public static boolean addHoldBatteryChargeSchedule(ThingActions actions, ZonedDateTime from, ZonedDateTime until) { | ||
return addHoldBatteryChargeSchedule(actions, from.toLocalTime(), until.toLocalTime()); | ||
} | ||
|
||
public static void forceBatteryCharging(ThingActions actions, QuantityType<Power> power) { | ||
public static boolean forceBatteryCharging(ThingActions actions, QuantityType<Power> power) { | ||
if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) { | ||
froniusSymoInverterActions.forceBatteryCharging(power); | ||
return froniusSymoInverterActions.forceBatteryCharging(power); | ||
} else { | ||
throw new IllegalArgumentException( | ||
"The 'actions' argument is not an instance of FroniusSymoInverterActions"); | ||
} | ||
} | ||
|
||
public static void addForcedBatteryChargingSchedule(ThingActions actions, LocalTime from, LocalTime until, | ||
public static boolean addForcedBatteryChargingSchedule(ThingActions actions, LocalTime from, LocalTime until, | ||
QuantityType<Power> power) { | ||
if (actions instanceof FroniusSymoInverterActions froniusSymoInverterActions) { | ||
froniusSymoInverterActions.addForcedBatteryChargingSchedule(from, until, power); | ||
return froniusSymoInverterActions.addForcedBatteryChargingSchedule(from, until, power); | ||
} else { | ||
throw new IllegalArgumentException( | ||
"The 'actions' argument is not an instance of FroniusSymoInverterActions"); | ||
} | ||
} | ||
|
||
public static void addForcedBatteryChargingSchedule(ThingActions actions, ZonedDateTime from, ZonedDateTime until, | ||
QuantityType<Power> power) { | ||
addForcedBatteryChargingSchedule(actions, from.toLocalTime(), until.toLocalTime(), power); | ||
public static boolean addForcedBatteryChargingSchedule(ThingActions actions, ZonedDateTime from, | ||
ZonedDateTime until, QuantityType<Power> power) { | ||
return addForcedBatteryChargingSchedule(actions, from.toLocalTime(), until.toLocalTime(), power); | ||
} | ||
|
||
@Override | ||
|
@@ -107,56 +108,62 @@ public void setThingHandler(@Nullable ThingHandler handler) { | |
} | ||
|
||
@RuleAction(label = "@text/actions.reset-battery-control.label", description = "@text/actions.reset-battery-control.description") | ||
public void resetBatteryControl() { | ||
public @ActionOutput(type = "boolean", label = "Success") boolean resetBatteryControl() { | ||
FroniusSymoInverterHandler handler = this.handler; | ||
if (handler != null) { | ||
handler.resetBatteryControl(); | ||
return handler.resetBatteryControl(); | ||
} | ||
return false; | ||
} | ||
|
||
@RuleAction(label = "@text/actions.hold-battery-charge.label", description = "@text/actions.hold-battery-charge.description") | ||
public void holdBatteryCharge() { | ||
public @ActionOutput(type = "boolean", label = "Success") boolean holdBatteryCharge() { | ||
FroniusSymoInverterHandler handler = this.handler; | ||
if (handler != null) { | ||
handler.holdBatteryCharge(); | ||
return handler.holdBatteryCharge(); | ||
} | ||
return false; | ||
} | ||
|
||
@RuleAction(label = "@text/actions.add-hold-battery-charge-schedule.label", description = "@text/actions.add-hold-battery-charge-schedule.description") | ||
public void addHoldBatteryChargeSchedule( | ||
@ActionInput(name = "from", label = "@text/actions.from.label", description = "@text/actions.from.description") LocalTime from, | ||
@ActionInput(name = "until", label = "@text/actions.until.label", description = "@text/actions.until.description") LocalTime until) { | ||
public @ActionOutput(type = "boolean", label = "Success") boolean addHoldBatteryChargeSchedule( | ||
@ActionInput(name = "from", label = "@text/actions.from.label", description = "@text/actions.from.description", required = true) LocalTime from, | ||
@ActionInput(name = "until", label = "@text/actions.until.label", description = "@text/actions.until.description", required = true) LocalTime until) { | ||
FroniusSymoInverterHandler handler = this.handler; | ||
if (handler != null) { | ||
handler.addHoldBatteryChargeSchedule(from, until); | ||
return handler.addHoldBatteryChargeSchedule(from, until); | ||
} | ||
return false; | ||
} | ||
|
||
public void addHoldBatteryChargeSchedule(ZonedDateTime from, ZonedDateTime until) { | ||
addHoldBatteryChargeSchedule(from.toLocalTime(), until.toLocalTime()); | ||
public boolean addHoldBatteryChargeSchedule(ZonedDateTime from, ZonedDateTime until) { | ||
return addHoldBatteryChargeSchedule(from.toLocalTime(), until.toLocalTime()); | ||
} | ||
|
||
@RuleAction(label = "@text/actions.force-battery-charging.label", description = "@text/actions.force-battery-charging.description") | ||
public void forceBatteryCharging( | ||
@ActionInput(name = "power", label = "@text/actions.power.label", description = "@text/actions.power.label", type = "QuantityType<Power>") QuantityType<Power> power) { | ||
public @ActionOutput(type = "boolean", label = "Success") boolean forceBatteryCharging( | ||
@ActionInput(name = "power", label = "@text/actions.power.label", description = "@text/actions.power.label", type = "QuantityType<Power>", required = true) QuantityType<Power> power) { | ||
FroniusSymoInverterHandler handler = this.handler; | ||
if (handler != null) { | ||
handler.forceBatteryCharging(power); | ||
return handler.forceBatteryCharging(power); | ||
} | ||
return false; | ||
} | ||
|
||
@RuleAction(label = "@text/actions.add-forced-battery-charging-schedule.label", description = "@text/actions.add-forced-battery-charging-schedule.description") | ||
public void addForcedBatteryChargingSchedule( | ||
@ActionInput(name = "from", label = "@text/actions.from.label", description = "@text/actions.from.description") LocalTime from, | ||
@ActionInput(name = "until", label = "@text/actions.until.label", description = "@text/actions.until.description") LocalTime until, | ||
@ActionInput(name = "power", label = "@text/actions.power.label", description = "@text/actions.power.label", type = "QuantityType<Power>") QuantityType<Power> power) { | ||
public @ActionOutput(type = "boolean", label = "Success") boolean addForcedBatteryChargingSchedule( | ||
@ActionInput(name = "from", label = "@text/actions.from.label", description = "@text/actions.from.description", required = true) LocalTime from, | ||
@ActionInput(name = "until", label = "@text/actions.until.label", description = "@text/actions.until.description", required = true) LocalTime until, | ||
@ActionInput(name = "power", label = "@text/actions.power.label", description = "@text/actions.power.label", type = "QuantityType<Power>", required = true) QuantityType<Power> power) { | ||
FroniusSymoInverterHandler handler = this.handler; | ||
if (handler != null) { | ||
handler.addForcedBatteryChargingSchedule(from, until, power); | ||
return handler.addForcedBatteryChargingSchedule(from, until, power); | ||
} | ||
return false; | ||
} | ||
|
||
public void addForcedBatteryChargingSchedule(ZonedDateTime from, ZonedDateTime until, QuantityType<Power> power) { | ||
addForcedBatteryChargingSchedule(from.toLocalTime(), until.toLocalTime(), power); | ||
public boolean addForcedBatteryChargingSchedule(ZonedDateTime from, ZonedDateTime until, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Annotations are missing for this action. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
QuantityType<Power> power) { | ||
return addForcedBatteryChargingSchedule(from.toLocalTime(), until.toLocalTime(), power); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations are missing for this action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is deliberately, I don’t need those overrides to show up in the UI or be available as rule module. These overrides solely exist to allow easier usage from scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unusual but ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure which binding it was but not annotation any existing override helps improving the UI experience.