Skip to content
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

Thing page: Support invoking Thing actions & Viewing their output #2818

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Oct 21, 2024

Refs openhab/openhab-core#4392.
Closes #2817.

This adds a new section "Actions" to the Thing tab of the Thing page, which provides a button for each UI-supported Thing action.
Clicking on that button will open a popup, where action input can be configured and action output can be viewed.

All keys of the action output response object from REST are rendered as list Items, the labels are taken from the action output definitions and fallback to the key.
If the key is qrCode or its output type is defined as qrCode, its value is rendered as QR code.

For actions without inputs or without outputs, messages are shown indicating that there is no such.

image

This PR marks the cold related to the old config actions as deprecated, my wish is to get rid of those config actions and have Thing actions used instead.

…utput

Refs openhab/openhab-core#4392.
Closes openhab#2817.

This adds a new section "Actions" to the Thing tab of the Thing page,
which provides a button for each UI-supported Thing action.
Clicking on that button will open a popup,
where action input can be configured and action output can be viewed.

Currently, action output is displayed pretty for the `result`, `qrPairingCode` and `manualPairingCode` keys of the response object.
In addition to that, the raw output can be viewed.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
@florian-h05 florian-h05 added enhancement New feature or request main ui Main UI labels Oct 21, 2024
@florian-h05 florian-h05 added this to the 4.3 milestone Oct 21, 2024
@florian-h05
Copy link
Contributor Author

@digitaldan WDYT?

Copy link

relativeci bot commented Oct 21, 2024

#2388 Bundle Size — 10.84MiB (+0.04%).

cd8abd9(current) vs 85c3c31 main#2386(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes
                 Current
#2388
     Baseline
#2386
No change  Initial JS 1.9MiB 1.9MiB
No change  Initial CSS 577.21KiB 577.21KiB
Change  Cache Invalidation 23.61% 22.77%
No change  Chunks 226 226
No change  Assets 249 249
Change  Modules 2923(+0.1%) 2920
No change  Duplicate Modules 149 149
No change  Duplicate Code 1.8% 1.8%
No change  Packages 96 96
No change  Duplicate Packages 2 2
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#2388
     Baseline
#2386
Regression  JS 9.06MiB (+0.05%) 9.05MiB
No change  CSS 864.03KiB 864.03KiB
No change  Fonts 526.1KiB 526.1KiB
No change  Media 295.6KiB 295.6KiB
No change  IMG 140.74KiB 140.74KiB
No change  HTML 1.38KiB 1.38KiB
No change  Other 871B 871B

Bundle analysis reportBranch florian-h05:thing-actionsProject dashboard


Generated by RelativeCIDocumentationReport issue

@lolodomo
Copy link
Contributor

I assume you display the action output label.
To be not too much specific I would suggest you consider two output names: result and qrCode.
Then @digitaldan could adjust his code to return a map with entries "result" and "qrCode" and set proper labels to each output like "Manual pairing code" and " QR pairing code".
WDYT?

@florian-h05 florian-h05 marked this pull request as draft October 21, 2024 21:39
@florian-h05
Copy link
Contributor Author

Sounds good 👍
I will adjust the code tomorrow.

@lolodomo
Copy link
Contributor

lolodomo commented Oct 21, 2024

Do not forget to consider actions without any input.

I am bluffled, you did that so fast!

@lolodomo
Copy link
Contributor

I will have to check again all existing thing actions with output(s) to check that output "name" is properly defined.

Copy link
Member

@ghys ghys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No notes.

If it's good for everybody, it's good for me.

@florian-h05
Copy link
Contributor Author

Do not forget to consider actions without any input.

Those are considered as well as actions without any output — in both cases a specific message is displayed instead of the inputs or output.

I am bluffled, you did that so fast!

The only thing missing at the moment is to render the outputs based on the output definition provided by the API — currently the pretty output rendering is hard-coded, but the raw output can be seen.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
@florian-h05
Copy link
Contributor Author

The output rendering now renders all keys of the response object and takes the labels from the output definition.
If an output is named qrCode or has type qrCode, it is rendered as QR code.

@digitaldan For the matter binding, you can either define:

@ActionOutputs({ @ActionOutput(name = "qrPairingCode", label = "QR Pairing Code", type = "qrCode"), @ActionOutput(name = "manualPairingCode", label = "Manual Pairing Code", type = "java.lang.String") })

or

@ActionOutputs({ @ActionOutput(name = "qrCode", label = "QR Pairing Code", type = "java.lang.String"), @ActionOutput(name = "manualPairingCode", label = "Manual Pairing Code", type = "java.lang.String") })

Signed-off-by: Florian Hotze <dev@florianhotze.com>
@florian-h05 florian-h05 marked this pull request as ready for review October 22, 2024 15:09
@florian-h05
Copy link
Contributor Author

FYI it seems the ActionsOutput annotation is used wrong in many bindings given the core implementation of annotation parsing, I have created a doc PR to fix that: openhab/openhab-docs#2388

@lolodomo
Copy link
Contributor

lolodomo commented Oct 22, 2024

FYI it seems the ActionsOutput annotation is used wrong in many bindings given the core implementation of annotation parsing

We will have to check and fix all existing thing actions returning something.

Do we really need the @ActionsOutputs annotation when there is only one @ActionsOutput annotation?

@lolodomo
Copy link
Contributor

I find 0 trace of ActionOutputs in our code base.
Are you sure it is needed?
If true, that means we would have none thing actions with return properly defined!

@florian-h05
Copy link
Contributor Author

We will have to check and fix all existing thing actions returning something.

If I understand the current docs, the annotation is only to be added if you return a Map<String,Object>.
If you return a single value, you don’t need an annotation, some add-ons have it but it can be removed.

My correction to the docs is, that if you return a Map<…>, you need to annotate with ActionInputs for core to recognise the annotation — see the linked core code in my doc PR.

@florian-h05
Copy link
Contributor Author

@lolodomo But let us continue this discussion in openhab/openhab-docs#2388 as this is not related to the UI.

@florian-h05
Copy link
Contributor Author

@digitaldan I think I will merge this PR so you can use it in the latest snapshot, from my testing it works fine.

Please refer to #2818 (comment) for the required annotation for the Thing action.

@florian-h05 florian-h05 merged commit 5febf02 into openhab:main Oct 22, 2024
8 checks passed
@florian-h05 florian-h05 deleted the thing-actions branch October 22, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request main ui Main UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for invoking Thing actions from the Thing details page
3 participants