From 79c925a0cb0d3440e0b1c50311d1e2ddd6c7c401 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Fri, 26 Jul 2024 14:21:40 +0200 Subject: [PATCH] Link add: Add support for linking Number channel to Switch Item with profile Closes #1478. Signed-off-by: Florian Hotze --- .../pages/settings/things/link/link-add.vue | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 34468c9f0c..c19e523509 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 @@ -83,7 +83,7 @@ item.name === this.selectedItemName) : null + return this.item ? this.item : (this.createMode ? this.newItem : (this.items ? this.items.find(item => item.name === this.selectedItemName) : null)) }, 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])) + return this.profileTypes + .filter(p => !p.supportedItemTypes.length || p.supportedItemTypes.includes(currentItemType.split(':', 1)[0])) + .filter(p => this.isNumberChannelButNoNumberItem && (p.uid !== 'system:default' && p.uid !== 'system:follow')) + }, + isNumberChannelButNoNumberItem () { + if (!this.channel || !this.channel.itemType) return false + if (!this.currentItem || !this.currentItem.type) return false + return this.channel.itemType.startsWith('Number') && !this.currentItem.type.startsWith('Number') } }, methods: { @@ -245,7 +252,7 @@ export default { let compatibleItemTypes = [] if (this.channel.itemType) { compatibleItemTypes.push(this.channel.itemType) - if (this.channel.itemType.indexOf('Number:') === 0) { compatibleItemTypes.push('Number') } + if (this.channel.itemType.startsWith('Number')) { compatibleItemTypes.push('Number', 'Switch') } if (this.channel.itemType === 'Color') { compatibleItemTypes.push('Switch', 'Dimmer') } if (this.channel.itemType === 'Dimmer') { compatibleItemTypes.push('Switch') } } @@ -297,6 +304,10 @@ export default { return } } + if (this.isNumberChannelButNoNumberItem && (!this.currentProfileType || !this.compatibleProfileTypes.includes(this.currentProfileType))) { + this.$f7.dialog.alert('Please configure a valid profile') + return + } if (this.createMode) { this.saveItem(this.newItem).then((data) => {