Skip to content

Commit

Permalink
Thing actions: Hide if no actions available & Merge with UI actions (o…
Browse files Browse the repository at this point in the history
…penhab#2839)

Fixes openhab#2834 (comment).
Shows UI actions (currently only Z-Wave network map) with the Thing actions instead of the deprecated config actions.

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Oct 27, 2024
1 parent acb464a commit deadfdb
Showing 1 changed file with 9 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@
:set-empty-config-as-null="true"
:read-only="!editable" />

<template v-if="thingActions.length > 0">
<!-- Thing Actions & UI Actions -->
<template v-if="thingActions.length > 0 || thingType?.UID?.startsWith('zwave')">
<f7-block-title medium class="no-margin-top">
Actions
</f7-block-title>
<f7-list class="margin-top" media-list>
<template v-for="action in thingActions">
<f7-list-item v-if="action.inputConfigDescriptions !== undefined" :key="action.name" :title="action.label" :footer="action.description" link="" @click="doThingAction(action)" />
</template>
<f7-list-item v-if="thingType?.UID?.startsWith('zwave')" title="View Network Map" link="" @click="openZWaveNetworkPopup()" />
<f7-list-item v-for="action in thingActions" :key="action.name" :title="action.label" :footer="action.description" link="" @click="doThingAction(action)" />
</f7-list>
</template>
</f7-col>
Expand All @@ -118,7 +118,7 @@
</f7-col>
</f7-block>

<!-- Actions -->
<!-- Config Actions (DEPRECATED) -->
<div v-if="ready && !error">
<f7-block class="block-narrow" v-for="actionGroup in configActionsByGroup" :key="actionGroup.group.name">
<f7-col>
Expand Down Expand Up @@ -420,7 +420,9 @@ export default {
*/
loadThingActions () {
return this.$oh.api.get('/rest/actions/' + this.thingId).then(data => {
this.thingActions = data.sort((a, b) => a.label.localeCompare(b.label))
this.thingActions = data
.filter((a) => a.inputConfigDescriptions !== undefined)
.sort((a, b) => a.label.localeCompare(b.label))
return Promise.resolve()
}).catch(err => {
if (err === 'Not Found' || err === 404) {
Expand Down Expand Up @@ -463,21 +465,7 @@ export default {
let bindingActionsNames = bindingActionsGrouped.flatMap(g => g.actions).flatMap(a => a.name)
this.configDescriptions.parameters = this.configDescriptions.parameters.filter(p => !bindingActionsNames.includes(p.name)) // params except actions
// merge UI-only actions (if any) and Binding actions (by groupName)
let allActions = bindingActionsGrouped
this.getUiActions().forEach(uiAction => {
let existingGroup = allActions.find(g => g.group.name === uiAction.group.name)
if (existingGroup) {
// existing (binding-side) group found, *prepending* UI actions
existingGroup.actions = uiAction.actions.concat(existingGroup.actions)
if (uiAction.group.label !== undefined) existingGroup.group.label = uiAction.group.label
if (uiAction.group.description !== undefined) existingGroup.group.description = uiAction.group.description
} else {
// no action group from binding, adding the UI actions into their own group (appending at the very end)
allActions = allActions.concat([uiAction])
}
})
this.configActionsByGroup = allActions
this.configActionsByGroup = bindingActionsGrouped
loadingFinished()
if (!this.eventSource) this.startEventSource()
Expand All @@ -503,28 +491,6 @@ export default {
})
})
},
getUiActions () {
// Returns UI-only actions (served by the UI itself, and not coming from the binding)
let uiActions = []
if (this.thingType && this.thingType.UID && this.thingType.UID.indexOf('zwave') === 0) {
uiActions.push(
{
group: {
name: 'actions',
label: 'Z-Wave', // this label will override any name coming from binding actions (if matched by name)
description: ''
},
actions: [
{
label: 'View Network Map',
execute: () => this.openZWaveNetworkPopup()
}
]
}
)
}
return uiActions
},
/**
* @deprecated to be removed once all Things that use config actions use real Thing actions instead
*/
Expand Down

0 comments on commit deadfdb

Please sign in to comment.