Skip to content

Commit

Permalink
Show correct alexa metadata categories for group items (openhab#767)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel <[email protected]>
  • Loading branch information
GiviMAD authored Jan 8, 2021
1 parent 60063d2 commit 6026e93
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ const categories = [
'WEARABLE'
]

// Group endpoints are generated from the display categories. Example from the docs: SECURITY_PANEL => Endpoint.SecurityPanel.
const groupEndpoints = categories
.map(category => {
const convertedChars = []
let capitalizeNext = false
for (var i = 0; i < category.length; i++) {
const currentChar = category.charAt(i)
if (i === 0) {
convertedChars.push(currentChar.toUpperCase())
} else if (currentChar === '_') {
capitalizeNext = true
} else if (capitalizeNext) {
convertedChars.push(currentChar.toUpperCase())
capitalizeNext = false
} else {
convertedChars.push(currentChar.toLocaleLowerCase())
}
}
return 'Endpoint.' + convertedChars.join('')
}).reduce((endpoints, endpointName) => {
endpoints[endpointName] = []
return endpoints
}, {})

const labels = {
'Switchable': [],
'Lighting': [],
Expand Down Expand Up @@ -234,6 +258,11 @@ for (let l in labels) {
classes['label:' + l] = labels[l]
}

for (let l in groupEndpoints) {
groupEndpoints[l].unshift(categoryParameter)
classes['endpoint:' + l] = groupEndpoints[l]
}

for (let c in capabilities) {
capabilities[c].unshift(categoryParameter)
classes[c] = capabilities[c]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<template>
<div>
<div style="text-align:right" class="padding-right">
<div style="text-align:right" class="padding-right" v-if="itemType !== 'Group'">
<label @click="toggleMultiple" style="cursor:pointer">Multiple</label> <f7-checkbox :checked="multiple" @change="toggleMultiple"></f7-checkbox>
</div>
<f7-list>
<f7-list-item :key="classSelectKey"
:title="(multiple) ? 'Alexa Classes' : 'Alexa Class'" smart-select :smart-select-params="{ openIn: 'popup', searchbar: true, closeOnSelect: !multiple, scrollToSelectedItem: true }" ref="classes">
<select name="parameters" @change="updateClasses" :multiple="multiple">
<option v-if="!multiple" value=""></option>
<optgroup label="Labels" v-if="!multiple">
<optgroup label="Labels" v-if="!multiple && itemType !== 'Group'">
<option v-for="cl in orderedClasses.filter((c) => c.indexOf('label:') === 0)"
:value="cl.replace('label:', '')" :key="cl"
:selected="isSelected(cl.replace('label:', ''))">
{{cl.replace('label:', '')}}
</option>
</optgroup>
<optgroup label="Capabilities">
<option v-for="cl in orderedClasses.filter((c) => c.indexOf('label:') !== 0)"
:value="cl" :key="cl"
:selected="isSelected(cl)">
{{cl}}
<option v-for="cl in orderedClasses.filter((c) => c.indexOf('label:') !== 0 && c.indexOf('endpoint:') === (itemType === 'Group'? 0 : -1))"
:value="cl.replace('endpoint:', '')" :key="cl"
:selected="isSelected(cl.replace('endpoint:', ''))">
{{cl.replace('endpoint:', '')}}
</option>
</optgroup>
</select>
Expand All @@ -39,14 +39,15 @@ import AlexaDefinitions from '@/assets/definitions/metadata/alexa'
import ConfigSheet from '@/components/config/config-sheet.vue'
export default {
props: ['itemName', 'metadata', 'namespace'],
props: ['item', 'metadata', 'namespace'],
components: {
ConfigSheet
},
data () {
return {
itemType: this.item.type,
classesDefs: Object.keys(AlexaDefinitions),
multiple: !!this.metadata.value && this.metadata.value.indexOf(',') > 0,
multiple: this.item.type !== 'Group' && !!this.metadata.value && this.metadata.value.indexOf(',') > 0,
classSelectKey: this.$f7.utils.id()
}
},
Expand All @@ -63,7 +64,7 @@ export default {
parameters () {
if (!this.classes) return []
if (!this.multiple) {
return AlexaDefinitions['label:' + this.classes] || [...AlexaDefinitions[this.classes]]
return AlexaDefinitions['label:' + this.classes] || AlexaDefinitions['endpoint:' + this.classes] || [...AlexaDefinitions[this.classes]]
}
const params = []
this.classes.forEach((c) => {
Expand Down

0 comments on commit 6026e93

Please sign in to comment.