openhab-docs
openhab-docs copied to clipboard
Thing actions: Clarify use of ActionOutputs annotation
The current docs are wrong, see https://github.com/openhab/openhab-core/blob/a22349abf4b3106ec8a3eb9d36799e334cdfbf25/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/module/provider/AnnotationActionModuleTypeHelper.java#L146-L159 for core implementation.
Thanks for your pull request to the openHAB documentation! The result can be previewed at the URL below (this comment and the preview will be updated if you add more commits).
| Name | Link |
|---|---|
| Latest commit | b550cdb4572e651d6212c8f6a3bc13ff0aa1d4d7 |
| Latest deploy log | https://app.netlify.com/sites/openhab-docs-preview/deploys/6717c1be8cccbf0008bbadc4 |
| Deploy Preview | https://deploy-preview-2388--openhab-docs-preview.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
If the current docs are correct except from the above mistake, one only needs to annotate @ActionOutput inside the @ActionOutputs annotation if the action returns a Map<String, Object>.
If there is only a single return value, no annotation is required and it won't be processed by core, as core is looking for @ActionInputs.
If a method returns such a Map, the @ActionOutputs annotation is needed.
For add-ons, this means:
- we can remove
@ActionOutputfrom all action returning only a single value - we need to add
@ActionOutputsaround the@ActionOutputs of all actions returningMap<String, Object>
At the moment, 2. affects not many actions:
cat **.java | grep @ActionOutput | grep "Map<String, Object>"
public @ActionOutput(name = NEW_SCENE_ID_OUTPUT, type = "java.lang.Integer") Map<String, Object> createScene(
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
public @ActionOutput(name = "result", type = "java.util.Map<String, Object>") Map<String, Object> calculateCheapestPeriod(
public @ActionOutput(name = "errorMessages", type = "java.util.List<String>") @ActionOutput(name = "warningMessages", type = "java.util.List<String>") @ActionOutput(name = "infoMessages", type = "java.util.List<String>") @ActionOutput(name = "statusMessages", type = "java.util.List<String>") Map<String, Object> getMessages() {
public @ActionOutput(name = "success", type = "java.lang.Boolean") @ActionOutput(name = "responseMessages", type = "java.util.List<String>") Map<String, Object> sendMessageWithResponse(
public @ActionOutput(name = "index", type = "java.lang.Integer", label = "@text/actionOutputIndexLabel", description = "@text/actionOutputIndexDesc") @ActionOutput(name = "prev_index", type = "java.lang.Integer", label = "@text/actionOutputPrevIndexLabel", description = "@text/actionOutputPrevIndexDesc") @ActionOutput(name = "timestamp", type = "java.time.ZonedDateTime", label = "@text/actionOutputTimestampLabel", description = "@text/actionOutputTimestampDesc") @ActionOutput(name = "description", type = "java.lang.String", label = "@text/actionOutputDescriptionLabel", description = "@text/actionOutputDescriptionDesc") @ActionOutput(name = "details", type = "java.lang.String", label = "@text/actionOutputDetailsLabel", description = "@text/actionOutputDetailsDesc") Map<String, Object> readEvent(
To mention:
- It is not possible to have several actions with same method name.