From e2d6cc7deebbff0d128722bbaaa612ac20c2185f Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Mon, 21 Oct 2024 21:44:33 +0200 Subject: [PATCH 1/3] Thing page: Add support for invoking Thing actions & Viewing action output Refs https://github.com/openhab/openhab-core/pull/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. 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 --- .../settings/things/thing-action-popup.vue | 111 ++++++++++++++++++ .../pages/settings/things/thing-details.vue | 59 +++++++++- 2 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 bundles/org.openhab.ui/web/src/pages/settings/things/thing-action-popup.vue diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/thing-action-popup.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/thing-action-popup.vue new file mode 100644 index 0000000000..f98de7803f --- /dev/null +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/thing-action-popup.vue @@ -0,0 +1,111 @@ + + + diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue index fbdffe889c..052b1cfa8c 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue @@ -92,6 +92,15 @@ :status="configStatusInfo" :set-empty-config-as-null="true" :read-only="!editable" /> + + @@ -266,6 +275,7 @@ import buildTextualDefinition from './thing-textual-definition' import ThingStatus from '@/components/thing/thing-status-mixin' import DirtyMixin from '../dirty-mixin' +import ThingActionPopup from '@/pages/settings/things/thing-action-popup.vue' let copyToast = null @@ -291,7 +301,11 @@ export default { thingType: {}, channelTypes: {}, configDescriptions: {}, + thingActions: [], configStatusInfo: [], + /** + * @deprecated + */ configActionsByGroup: [], thingEnabled: true, codePopupOpened: false, @@ -397,6 +411,24 @@ export default { this.thingYaml = this.toYaml() } }, + /** + * Loads the Thing actions. + * + * @returns {Promise} + */ + loadThingActions () { + return this.$oh.api.get('/rest/actions/' + this.thingId).then(data => { + this.thingActions = data + return Promise.resolve() + }).catch(err => { + if (err === 'Not Found' || err === 404) { + console.log('No actions available for this Thing') + return Promise.resolve() + } + console.error('Error loading thing actions: ' + err) + return Promise.reject(err) + }) + }, load () { // if (this.ready) return if (this.loading) return @@ -413,10 +445,11 @@ export default { this.$oh.api.get('/rest/things/' + this.thingId).then(data => { this.$set(this, 'thing', data) - let typePromises = [this.$oh.api.get('/rest/thing-types/' + this.thing.thingTypeUID), - this.$oh.api.get('/rest/channel-types?prefixes=system,' + this.thing.thingTypeUID.split(':')[0])] + const promises = [this.$oh.api.get('/rest/thing-types/' + this.thing.thingTypeUID), + this.$oh.api.get('/rest/channel-types?prefixes=system,' + this.thing.thingTypeUID.split(':')[0]), + this.loadThingActions()] - Promise.all(typePromises).then(data2 => { + Promise.all(promises).then(data2 => { this.thingType = data2[0] this.channelTypes = data2[1] @@ -490,6 +523,9 @@ export default { } return uiActions }, + /** + * @deprecated to be removed once all Things that use config actions use real Thing actions instead + */ getBindingActions (configDescriptionsResponse) { // Returns an array of parameters which qualify as "actions", grouped by the paramGroup. The actions themselves are enriched by execute() method let actionContextGroups = configDescriptionsResponse.parameterGroups.filter((pg) => pg.context === 'actions') @@ -546,6 +582,23 @@ export default { }).open() }) }, + doThingAction (action) { + const popup = { + component: ThingActionPopup + } + this.$f7router.navigate({ + url: 'thing-action', + route: { + path: 'thing-action', + popup + } + }, { + props: { + thingUID: this.thingId, + action + } + }) + }, doConfigAction (action) { if (action.type !== 'BOOLEAN') { console.warn('Invalid action type', action) From ad1441797dc760a204283798cebfbffe38817e5f Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Tue, 22 Oct 2024 16:38:20 +0200 Subject: [PATCH 2/3] Thing page: Fix navbar style issue when handler not available Signed-off-by: Florian Hotze --- .../web/src/pages/settings/things/thing-details.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue index 052b1cfa8c..b63487b036 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue @@ -1,7 +1,7 @@