-
-
Notifications
You must be signed in to change notification settings - Fork 424
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
Enhance ThingActions UI support #4392
Conversation
For the following action
The GET API now returns:
An example with the POST API using these input values in API explorer:
The logs:
And the returned response body:
|
...ation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java
Outdated
Show resolved
Hide resolved
...ation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java
Outdated
Show resolved
Hide resolved
...ation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java
Outdated
Show resolved
Hide resolved
7bf450e
to
2ca7f24
Compare
2ca7f24
to
9e04605
Compare
@lolodomo The |
I don't understand, Thing actions can already be invoked from rules. ??? |
After reading #1745 completely, yes they could in theory - the problem is however the same we attempt to fix with this PR: The Thing action module types only contain the inputs like the |
@lolodomo Please do not force push from now on - I will start working on your PR as well and create a PR to your PR branch afterwards. |
@lolodomo I have created lolodomo#3, which adds support for invoking Thing actions through UI-based rules. Please merge it with rebase merge to keep commit history. |
f582e92
to
f1e4101
Compare
Thanks for integrating my changes ... now we have to update the PR description: Enhance ThingActions UI supportFixes #1745. Return config description parameters for the ActionInputs of ThingActions for the REST GET Enhance the REST POST This will be used by the UI's Thing page and rule editor to allow invoking Thing actions through the UI or adding them to UI-bases rules. |
When PR is ready for review, I will squash everything, provide a proper description and mention you as co-author. |
...on/src/main/java/org/openhab/core/automation/util/mapper/SerialisedInputsToActionInputs.java
Outdated
Show resolved
Hide resolved
.../java/org/openhab/core/automation/util/mapper/ActionInputsToConfigDescriptionParameters.java
Outdated
Show resolved
Hide resolved
.../java/org/openhab/core/automation/util/mapper/ActionInputsToConfigDescriptionParameters.java
Outdated
Show resolved
Hide resolved
47e8144
to
c6d8c3c
Compare
.../java/org/openhab/core/automation/util/mapper/ActionInputsToConfigDescriptionParameters.java
Outdated
Show resolved
Hide resolved
@florian-h05 : I believe it is almost ready now. Can you please have a look to my last commits before I squash everything and update the 2 first messages ? |
I am tempted to change the expected format for "datetime" context. |
I will do.
Agreed, having seconds is better than not having seconds - and as it is not yet used, there should be no problems. |
Done. I also updated my second message with a full example when using GET and POST API. |
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.
LGTM, thanks for your work as well as improving what I have contributed!
Please update the PR title and description, I have already proposed a new one in #4392 (comment),
and add a joint sign-off.
Just two comments:
....core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameter.java
Outdated
Show resolved
Hide resolved
...in/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProvider.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java
Outdated
Show resolved
Hide resolved
Fixes openhab#1745 Return config description parameters for the ActionInputs of ThingActions for the REST GET /action/{thingUID} and REST GET /module-types endpoints. The config description parameters are only provided if all input parameters have a type that can be mapped to a config description parameter (String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long, float, Float, double, Double, Number, DecimalType, QuantityType<?>, LocalDateTime, LocalDate, LocalTime, ZonedDateTime, Date, Instant and Duration). Enhance the REST POST /actions/{thingUID}/{actionUid} endpoint (allows invoking Thing actions via REST) and the AnnotationActionHandler (allows invoking Thing actions from UI-rules) in order to be more flexible regarding the type of each provided argument value and to map the value to the expected data type. Number and string values will be accepted as inputs and the expected data type will be created from this value. This will be used by the UI's Thing page and rule editor to allow invoking Thing actions through the UI or adding them to UI-bases rules. Signed-off-by: Laurent Garnier <lg.hc@free.fr> Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
95ddb01
to
b308cd7
Compare
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.
Code looks good!
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@J-N-K : I added unit tests but I will continue later to cover more cases. |
0814083
to
2fb60c9
Compare
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
2fb60c9
to
b507711
Compare
@J-N-K : unit tests are now fully defined for class |
...b.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelplerTest.java
Outdated
Show resolved
Hide resolved
@florian-h05 : I hope you are in the starting blocks ;) |
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
d8fc749
to
e9dd8e5
Compare
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.
Just some minor comments. Nice test coverage.
...ab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java
Outdated
Show resolved
Hide resolved
|
||
@Test | ||
public void testMapActionInputToConfigDescriptionParameterWhenBoolean() { | ||
checkParamter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.lang.Boolean")), |
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.
checkParamter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.lang.Boolean")), | |
checkParameter(helper.mapActionInputToConfigDescriptionParameter(buildInput("java.lang.Boolean")), |
typo
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.
In general: This looks like a perfect example for a ParametrizedTest
:
Lines 166 to 195 in 6d0a3b3
@MethodSource | |
@ParameterizedTest | |
public void testMapToEntityIsComplete(Class<?> originalType, Class<?> mappedType, int allowedDelta) { | |
Class<?> clazz = originalType; | |
int originalTypeFieldCount = 0; | |
while (clazz != Object.class) { | |
originalTypeFieldCount += clazz.getDeclaredFields().length; | |
clazz = clazz.getSuperclass(); | |
} | |
int mappedEntityFieldCount = mappedType.getDeclaredFields().length; | |
assertThat(originalType.getName() + " not properly mapped", mappedEntityFieldCount, | |
is(originalTypeFieldCount + allowedDelta)); | |
} | |
private static Stream<Arguments> testMapToEntityIsComplete() { | |
return Stream.of( // | |
// isBridge is an extra field for storage and not present in ThingType | |
Arguments.of(ThingType.class, AbstractStorageBasedTypeProvider.ThingTypeEntity.class, 1), | |
Arguments.of(ChannelType.class, AbstractStorageBasedTypeProvider.ChannelTypeEntity.class, 0), | |
Arguments.of(ChannelDefinition.class, AbstractStorageBasedTypeProvider.ChannelDefinitionEntity.class, | |
0), | |
// configDescriptionURI is not available for ChannelGroupType | |
Arguments.of(ChannelGroupType.class, AbstractStorageBasedTypeProvider.ChannelGroupTypeEntity.class, -1), | |
Arguments.of(ChannelGroupDefinition.class, | |
AbstractStorageBasedTypeProvider.ChannelGroupDefinitionEntity.class, 0), | |
Arguments.of(StateDescriptionFragmentImpl.class, | |
AbstractStorageBasedTypeProvider.StateDescriptionFragmentEntity.class, 0)); | |
} |
If you prefer keeping it the way it is now, that is also fine. Just let me know.
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.
I already spend too much of my free time on these unit tests!
...ab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java
Outdated
Show resolved
Hide resolved
...ab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java
Outdated
Show resolved
Hide resolved
...ab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java
Show resolved
Hide resolved
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
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.
Thanks!
…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 for actions with a single output, as well as for the `result`, `qrPairingCode` and `manualPairingCode` keys of the response object. Signed-off-by: Florian Hotze <dev@florianhotze.com>
…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>
) 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. --------- Signed-off-by: Florian Hotze <dev@florianhotze.com>
…te context docs This changes the default format for the datetime context to the ISO standard. This context is not used by add-ons and supported by the UI, so it should be possible to change it (again after openhab#4392.) Also update the context docs from https://next.openhab.org/docs/developer/addons/config-xml.html#supported-contexts and the UI code. Signed-off-by: Florian Hotze <dev@florianhotze.com>
…te context docs (#4428) * ConfigDescriptionParameter: Change default format for datetime & Update context docs This changes the default format for the datetime context to the ISO standard. This context is not used by add-ons and supported by the UI, so it should be possible to change it (again after #4392.) Also update the context docs from https://next.openhab.org/docs/developer/addons/config-xml.html#supported-contexts and the UI code. Signed-off-by: Florian Hotze <dev@florianhotze.com>
Fixes #1745
Return config description parameters for the ActionInputs of ThingActions for the REST GET
/action/{thingUID}
and REST GET/module-types endpoints
.The config description parameters are only provided if all input parameters have a type that can be mapped to a config description parameter (String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long, float, Float, double, Double, Number, DecimalType,
QuantityType<?>
, LocalDateTime, LocalDate, LocalTime, ZonedDateTime, Date, Instant and Duration).Enhance the REST POST
/actions/{thingUID}/{actionUid}
endpoint (allows invoking Thing actions via REST) and theAnnotationActionHandler
(allows invoking Thing actions from UI-rules) in order to be more flexible regarding the type of each provided argument value and to map the value to the expected data type. Number and string values will be accepted as inputs and the expected data type will be created from this value.This will be used by the UI's Thing page and rule editor to allow invoking Thing actions through the UI or adding them to UI-bases rules.
Signed-off-by: Laurent Garnier lg.hc@free.fr
Signed-off-by: Florian Hotze florianh_dev@icloud.com