From b2de991c86e2035eb75ecebb84c96de405e1a3fc Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Fri, 1 Mar 2024 11:06:35 +0100 Subject: [PATCH 01/24] unit-hint on item creation Signed-off-by: Mark Herwege --- .../org.openhab.ui/web/src/components/item/item-form.vue | 8 +++++--- .../web/src/pages/settings/things/link/link-add.vue | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/components/item/item-form.vue b/bundles/org.openhab.ui/web/src/components/item/item-form.vue index a1fc5d6d0a..e10beb3000 100644 --- a/bundles/org.openhab.ui/web/src/components/item/item-form.vue +++ b/bundles/org.openhab.ui/web/src/components/item/item-form.vue @@ -98,7 +98,7 @@ import uomMixin from '@/components/item/uom-mixin' export default { mixins: [ItemMixin, uomMixin], - props: ['item', 'items', 'createMode', 'hideCategory', 'hideType', 'hideSemantics', 'forceSemantics'], + props: ['item', 'items', 'createMode', 'hideCategory', 'hideType', 'hideSemantics', 'forceSemantics', 'unitHint'], components: { SemanticsPicker, ItemPicker, @@ -144,8 +144,10 @@ export default { } const dimension = this.dimensions.find((d) => d.name === newDimension) this.$set(this.item, 'type', 'Number:' + dimension.name) - this.$set(this.item, 'unit', dimension.systemUnit) - this.$set(this.item, 'stateDescriptionPattern', `%.0f ${dimension.systemUnit}`) + if (!this.item.unit) { + this.$set(this.item, 'unit', dimension.systemUnit) + } + this.$set(this.item, 'stateDescriptionPattern', '%.0f %unit%') }, initializeAutocomplete (inputElement) { this.categoryAutocomplete = this.$f7.autocomplete.create({ diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue index 664ba9f1e7..8df86a2314 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue @@ -153,6 +153,7 @@ export default { channelUID: null, configuration: {} }, + measurementSystem: 'SI', selectedItemName: null, selectedThingId: '', selectedThing: {}, @@ -172,6 +173,9 @@ export default { this.$oh.api.get('/rest/items').then((items) => { this.items = items }) + this.$oh.api.get('/').then((root) => { + this.measurementSystem = root.measurementSystem + }) } }, computed: { @@ -181,6 +185,10 @@ export default { compatibleProfileTypes () { let currentItemType = this.currentItem && this.currentItem.type ? this.currentItem.type : '' return this.profileTypes.filter(p => !p.supportedItemTypes.length || p.supportedItemTypes.includes(currentItemType.split(':', 1)[0])) + }, + unit () { + let units = (this.channelType ? this.channelType.unitHint : '').split(',') + return (this.measurementSystem === 'US' && units.length > 1) ? units[1].trim() : units[0].trim } }, methods: { @@ -197,6 +205,7 @@ export default { category: (this.channelType) ? this.channelType.category : '', groupNames: [], type: this.channel.itemType || 'Switch', + unit: this.unit, tags: (defaultTags.find((t) => this.$store.getters.semanticClasses.Points.indexOf(t) >= 0)) ? defaultTags : [...defaultTags, 'Point'] }) }, From 226e3055feec481456986e4cabf2cd8e3c45989d Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Fri, 1 Mar 2024 11:06:35 +0100 Subject: [PATCH 02/24] from thing to model Signed-off-by: Mark Herwege --- .../web/src/components/item/uom-mixin.js | 10 ++++++++++ .../web/src/components/thing/channel-list.vue | 5 +++++ .../src/pages/settings/things/link/link-add.vue | 15 +++++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js b/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js index b7a6d515cf..13801e2559 100644 --- a/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js +++ b/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js @@ -1,10 +1,14 @@ export default { data () { return { + measurementSystem: 'SI', dimensions: [] } }, created () { + this.$oh.api.get('/').then((root) => { + this.measurementSystem = root.measurementSystem + }), this.$oh.api.get('/rest/systeminfo/uom').then((data) => { data.uomInfo.dimensions.forEach((d) => { this.dimensions.push({ @@ -14,5 +18,11 @@ export default { }) }) }) + }, + methods: { + getUnitHint (channelType) { + let units = ((channelType && channelType.unitHint) ? channelType.unitHint : '').split(',') + return (this.measurementSystem === 'US' && units.length > 1) ? units[1].trim() : units[0].trim() + } } } diff --git a/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue b/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue index 05d0d42613..93b051c70c 100644 --- a/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue +++ b/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue @@ -93,7 +93,10 @@ import ChannelGroup from './channel-group.vue' import ChannelLink from './channel-link.vue' import ItemForm from '@/components/item/item-form.vue' +import uomMixin from '@/components/item/uom-mixin' + export default { + mixins: [uomMixin], props: ['thingType', 'thing', 'channelTypes', 'items', 'pickerMode', 'multipleLinksMode', 'itemTypeFilter', 'newItemsPrefix', 'newItems', 'context'], components: { ChannelGroup, @@ -189,6 +192,7 @@ export default { } newItemName += this.$oh.utils.normalizeLabel(suffix) const defaultTags = (channel.defaultTags.length > 0) ? channel.defaultTags : channelType.tags + const unit = this.getUnitHint(channelType); const newItem = { channel: channel, channelType: channelType, @@ -196,6 +200,7 @@ export default { label: channel.label || channelType.label, category: (channelType) ? channelType.category : '', type: channel.itemType, + unit: unit, tags: (defaultTags.find((t) => this.$store.getters.semanticClasses.Points.indexOf(t) >= 0)) ? defaultTags : [...defaultTags, 'Point'] } this.newItems.push(newItem) diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue index 8df86a2314..3c887d71e6 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue @@ -132,8 +132,10 @@ import Item from '@/components/item/item.vue' import * as Types from '@/assets/item-types.js' import ItemMixin from '@/components/item/item-mixin' +import uomMixin from '@/components/item/uom-mixin' + export default { - mixins: [ItemMixin], + mixins: [ItemMixin, uomMixin], components: { ConfigSheet, ItemPicker, @@ -153,7 +155,6 @@ export default { channelUID: null, configuration: {} }, - measurementSystem: 'SI', selectedItemName: null, selectedThingId: '', selectedThing: {}, @@ -173,9 +174,6 @@ export default { this.$oh.api.get('/rest/items').then((items) => { this.items = items }) - this.$oh.api.get('/').then((root) => { - this.measurementSystem = root.measurementSystem - }) } }, computed: { @@ -186,10 +184,6 @@ export default { let currentItemType = this.currentItem && this.currentItem.type ? this.currentItem.type : '' return this.profileTypes.filter(p => !p.supportedItemTypes.length || p.supportedItemTypes.includes(currentItemType.split(':', 1)[0])) }, - unit () { - let units = (this.channelType ? this.channelType.unitHint : '').split(',') - return (this.measurementSystem === 'US' && units.length > 1) ? units[1].trim() : units[0].trim - } }, methods: { onPageAfterIn (event) { @@ -199,13 +193,14 @@ export default { newItemName += '_' newItemName += this.$oh.utils.normalizeLabel(this.channel.label || this.channelType.label) const defaultTags = (this.channel.defaultTags.length > 0) ? this.channel.defaultTags : this.channelType.tags + const unit = this.getUnitHint(this.channelType) this.$set(this, 'newItem', { name: newItemName, label: this.channel.label || this.channelType.label, category: (this.channelType) ? this.channelType.category : '', groupNames: [], type: this.channel.itemType || 'Switch', - unit: this.unit, + unit: unit, tags: (defaultTags.find((t) => this.$store.getters.semanticClasses.Points.indexOf(t) >= 0)) ? defaultTags : [...defaultTags, 'Point'] }) }, From 1431b68bed9c1a224834c0167d6979f8128f64e8 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Fri, 1 Mar 2024 11:06:36 +0100 Subject: [PATCH 03/24] fixes Signed-off-by: Mark Herwege --- bundles/org.openhab.ui/web/src/components/item/item-mixin.js | 2 +- bundles/org.openhab.ui/web/src/components/item/uom-mixin.js | 2 +- .../org.openhab.ui/web/src/components/thing/channel-list.vue | 2 +- .../web/src/pages/settings/things/link/link-add.vue | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/components/item/item-mixin.js b/bundles/org.openhab.ui/web/src/components/item/item-mixin.js index 12283832ef..3e860c153f 100644 --- a/bundles/org.openhab.ui/web/src/components/item/item-mixin.js +++ b/bundles/org.openhab.ui/web/src/components/item/item-mixin.js @@ -73,7 +73,7 @@ export default { }).then(() => { // Save state description if Item is an UoM Item and if state description changed from the default value if (this.createMode && (item.type.startsWith('Number:') || item.groupType?.startsWith('Number:')) && stateDescriptionPattern) { - if (stateDescriptionPattern !== `%.0f ${unit}`) { + if (stateDescriptionPattern !== '%.0f %unit%') { const metadata = { value: ' ', config: { diff --git a/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js b/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js index 13801e2559..c761a4a2dc 100644 --- a/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js +++ b/bundles/org.openhab.ui/web/src/components/item/uom-mixin.js @@ -8,7 +8,7 @@ export default { created () { this.$oh.api.get('/').then((root) => { this.measurementSystem = root.measurementSystem - }), + }) this.$oh.api.get('/rest/systeminfo/uom').then((data) => { data.uomInfo.dimensions.forEach((d) => { this.dimensions.push({ diff --git a/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue b/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue index 93b051c70c..6ac08ec238 100644 --- a/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue +++ b/bundles/org.openhab.ui/web/src/components/thing/channel-list.vue @@ -192,7 +192,7 @@ export default { } newItemName += this.$oh.utils.normalizeLabel(suffix) const defaultTags = (channel.defaultTags.length > 0) ? channel.defaultTags : channelType.tags - const unit = this.getUnitHint(channelType); + const unit = this.getUnitHint(channelType) const newItem = { channel: channel, channelType: channelType, diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue index 3c887d71e6..6208d09195 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-add.vue @@ -183,7 +183,7 @@ export default { compatibleProfileTypes () { let currentItemType = this.currentItem && this.currentItem.type ? this.currentItem.type : '' return this.profileTypes.filter(p => !p.supportedItemTypes.length || p.supportedItemTypes.includes(currentItemType.split(':', 1)[0])) - }, + } }, methods: { onPageAfterIn (event) { From a9ab3547bc23b08b7fe0359a17e1fa6fc55e1401 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Fri, 1 Mar 2024 11:06:36 +0100 Subject: [PATCH 04/24] groups Signed-off-by: Mark Herwege --- .../web/src/components/item/group-form.vue | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.ui/web/src/components/item/group-form.vue b/bundles/org.openhab.ui/web/src/components/item/group-form.vue index 1d14d4be22..131568c4c2 100644 --- a/bundles/org.openhab.ui/web/src/components/item/group-form.vue +++ b/bundles/org.openhab.ui/web/src/components/item/group-form.vue @@ -146,7 +146,43 @@ export default { this.item.functionKey += '_' + this.item.function.params.join('_') } } else { - this.$set(this.item, 'functionKey', '') + this.$set(this.item, 'functionKey', 'None') + } + }, + methods: { + setGroupType (type) { + this.$set(this.item, 'groupType', '') + this.$set(this.item, 'functionKey', 'None') + this.$nextTick(() => { + if (type !== 'None') this.$set(this.item, 'groupType', type) + }) + }, + setDimension (index) { + if (index === 'Number') { + this.setGroupType('Number') + return + } + const dimension = this.dimensions[index] + this.setGroupType('Number:' + dimension.name) + if (!this.item.unit) { + this.$set(this.item, 'unit', dimension.systemUnit) + } + this.$set(this.item, 'stateDescriptionPattern', '%.0f %unit%') + }, + setFunction (key) { + if (!key) { + delete this.item.function + return + } + this.$set(this.item, 'functionKey', key) + const splitted = key.split('_') + let func = { + name: splitted[0] + } + if (splitted.length > 1) { + func.params = [splitted[1], splitted[2]] + } + this.$set(this.item, 'function', func) } } } From 4ca80025c77dff5809a81b2421ad2cf04bad5b28 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Fri, 1 Mar 2024 11:06:36 +0100 Subject: [PATCH 05/24] curated unit list Signed-off-by: Mark Herwege --- .../org.openhab.ui/web/src/assets/units.js | 9 ++++ .../web/src/components/item/group-form.vue | 36 ++++++++++++-- .../web/src/components/item/item-form.vue | 48 +++++++++++++++---- .../web/src/components/item/uom-mixin.js | 46 ++++++++++++++++-- .../web/src/components/thing/channel-list.vue | 11 +++-- .../pages/settings/things/link/link-add.vue | 9 ++-- 6 files changed, 132 insertions(+), 27 deletions(-) create mode 100644 bundles/org.openhab.ui/web/src/assets/units.js diff --git a/bundles/org.openhab.ui/web/src/assets/units.js b/bundles/org.openhab.ui/web/src/assets/units.js new file mode 100644 index 0000000000..c5ece33399 --- /dev/null +++ b/bundles/org.openhab.ui/web/src/assets/units.js @@ -0,0 +1,9 @@ +export const Units = [{ + dimension: 'Dimensionless', + units: ['one', '%', 'dB', 'ppm'], + default: '%' +} , { + dimension: 'Length', + unitsSI: ['mm', 'cm', 'dm', 'm', 'km'], + unitsUS: ['in', 'ft', 'mi'] +}] \ No newline at end of file diff --git a/bundles/org.openhab.ui/web/src/components/item/group-form.vue b/bundles/org.openhab.ui/web/src/components/item/group-form.vue index 131568c4c2..6e51910c44 100644 --- a/bundles/org.openhab.ui/web/src/components/item/group-form.vue +++ b/bundles/org.openhab.ui/web/src/components/item/group-form.vue @@ -21,16 +21,17 @@ +