Skip to content

Commit

Permalink
uom stateDescriptionPattern
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
  • Loading branch information
mherwege committed Mar 19, 2024
1 parent 67163b0 commit ad7cf03
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default {
const dimension = this.dimensions.find((d) => d.name === newDimension)
this.$set(this.item, 'groupType', 'Number:' + dimension.name)
this.groupUnit = this.getUnitHint(dimension.name)
this.$set(this.item, 'stateDescriptionPattern', this.getStateDescription())
this.$set(this.item, 'stateDescriptionPattern', this.stateDescriptionPattern)
}
},
groupUnit: {
Expand Down
5 changes: 2 additions & 3 deletions bundles/org.openhab.ui/web/src/components/item/item-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import uomMixin from '@/components/item/uom-mixin'
export default {
mixins: [ItemMixin, uomMixin],
props: ['item', 'items', 'createMode', 'hideCategory', 'hideType', 'hideSemantics', 'forceSemantics', 'unitHint'],
props: ['item', 'items', 'createMode', 'hideCategory', 'hideType', 'hideSemantics', 'forceSemantics', 'unitHint', 'stateDescription'],
components: {
SemanticsPicker,
ItemPicker,
Expand Down Expand Up @@ -149,7 +149,6 @@ export default {
const dimension = this.dimensions.find((d) => d.name === newDimension)
this.$set(this.item, 'type', 'Number:' + dimension.name)
this.itemUnit = (this.unitHint ? this.unitHint : this.getUnitHint(dimension.name))
this.$set(this.item, 'stateDescription', this.getStateDescription())
}
},
itemUnit: {
Expand All @@ -171,7 +170,7 @@ export default {
stateDescriptionPattern: {
get () {
if (this.item.stateDescriptionPattern) return this.item.stateDescriptionPattern
return this.item.metadata?.stateDescription?.config.pattern || '%.0f %unit%'
return this.item.metadata?.stateDescription?.config.pattern || this.stateDescription || (this.createMode ? '%.0f %unit%' : '')
},
set (newPattern) {
this.$set(this.item, 'stateDescriptionPattern', newPattern)
Expand Down
14 changes: 6 additions & 8 deletions bundles/org.openhab.ui/web/src/components/item/item-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@ export default {
return Promise.resolve()
}
}).then(() => {
// Save state description if Item is an UoM Item and if state description changed from the default value
// Save state description if Item is an UoM Item
if ((item.type.startsWith('Number:') || item.groupType?.startsWith('Number:')) && stateDescriptionPattern) {
if (stateDescriptionPattern !== '%.0f %unit%') {
const metadata = {
value: ' ',
config: {
pattern: stateDescriptionPattern
}
const metadata = {
value: ' ',
config: {
pattern: stateDescriptionPattern
}
return this.$oh.api.put('/rest/items/' + item.name + '/metadata/stateDescription', metadata)
}
return this.$oh.api.put('/rest/items/' + item.name + '/metadata/stateDescription', metadata)
} else {
return Promise.resolve()
}
Expand Down
12 changes: 11 additions & 1 deletion bundles/org.openhab.ui/web/src/components/thing/channel-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@
@channel-updated="(e) => $emit('channels-updated', e)" />
</template>
<template #default="{ channelType, channel }" v-else-if="multipleLinksMode">
<item-form v-if="isChecked(channel)" :item="newItem(channel)" :items="items" :createMode="true" :channel="channel" :checked="isChecked(channel)" :unitHint="getUnitHint(channel, channelType)" />
<item-form v-if="isChecked(channel)"
:item="newItem(channel)"
:items="items"
:createMode="true"
:channel="channel"
:checked="isChecked(channel)"
:unitHint="getUnitHint(channel, channelType)"
:stateDescription="stateDescription(channelType)" />
</template>
<!-- <channel-link #default="{ channelId }" /> -->
</channel-group>
Expand Down Expand Up @@ -209,6 +216,9 @@ export default {
const dimension = channel.itemType.startsWith('Number:') ? channel.itemType.split(':')[1] : ''
return dimension ? this.getUnitHint(dimension, channelType) : ''
},
stateDescription (channelType) {
return channelType?.stateDescription?.pattern
},
toggleAllChecks (checked) {
this.thing.channels.forEach((c) => {
const channelType = this.channelTypesMap.get(c.channelTypeUID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<!-- Create new item -->
<f7-col v-else>
<item-form ref="itemForm" :item="newItem" :items="items" :createMode="true" :unitHint="linkUnit()" />
<item-form ref="itemForm" :item="newItem" :items="items" :createMode="true" :unitHint="linkUnit()" :stateDescription="stateDescription()" />
</f7-col>
</template>

Expand Down Expand Up @@ -207,6 +207,9 @@ export default {
const dimension = this.channel.itemType.startsWith('Number:') ? this.channel.itemType.split(':')[1] : ''
return dimension ? this.getUnitHint(dimension, this.channelType) : ''
},
stateDescription () {
return this.channelType?.stateDescription?.pattern
},
loadProfileTypes (channel) {
this.ready = false
this.selectedChannel = channel
Expand Down

0 comments on commit ad7cf03

Please sign in to comment.