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 c19e523509..8f5b2b95da 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 @@ -81,9 +81,9 @@ Learn more about profiles. - + 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])) - .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') + return this.profileTypes.filter(p => this.isProfileTypeCompatible(this.channel, p, this.currentItem)) } }, methods: { @@ -220,8 +212,7 @@ export default { loadProfileTypes (channel) { this.ready = false this.selectedChannel = channel - const getProfileTypes = this.$oh.api.get('/rest/profile-types?channelTypeUID=' + channel.channelTypeUID) - getProfileTypes.then((data) => { + this.$oh.api.get('/rest/profile-types?channelTypeUID=' + channel.channelTypeUID).then((data) => { this.profileTypes = data this.profileTypes.unshift(data.splice(data.findIndex(p => p.uid === 'system:default'), 1)[0]) // move default to be first this.ready = true @@ -304,7 +295,7 @@ export default { return } } - if (this.isNumberChannelButNoNumberItem && (!this.currentProfileType || !this.compatibleProfileTypes.includes(this.currentProfileType))) { + if (!this.itemTypeIsChannelType(this.currentItem, this.channel) && (!this.currentProfileType || !this.compatibleProfileTypes.includes(this.currentProfileType))) { this.$f7.dialog.alert('Please configure a valid profile') return } diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-edit.vue b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-edit.vue index ba39a044c4..06f27ffd17 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-edit.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-edit.vue @@ -93,9 +93,10 @@ import ConfigSheet from '@/components/config/config-sheet.vue' import Item from '@/components/item/item.vue' import ItemStatePreview from '@/components/item/item-state-preview.vue' import ThingStatus from '@/components/thing/thing-status-mixin' +import LinkMixin from '@/pages/settings/things/link/link-mixin' export default { - mixins: [ThingStatus], + mixins: [ThingStatus, LinkMixin], components: { ConfigSheet, Item, @@ -137,7 +138,7 @@ export default { this.$oh.api.get('/rest/profile-types?channelTypeUID=' + this.channel.channelTypeUID + '&itemType=' + itemType).then((data) => { this.profileTypes = data this.profileTypes.unshift(data.splice(data.findIndex(p => p.uid === 'system:default'), 1)[0]) // move default to be first - this.profileTypes = this.profileTypes.filter(p => !p.supportedItemTypes.length || p.supportedItemTypes.includes(this.item.type.split(':', 1)[0])) // only show compatible profile types + this.profileTypes = this.profileTypes.filter(p => this.isProfileTypeCompatible(this.channel, p, this.item)) // only show compatible profile types this.$oh.api.get('/rest/links/' + itemName + '/' + channelUID).then((data2) => { this.link = data2 diff --git a/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-mixin.js b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-mixin.js new file mode 100644 index 0000000000..3222d346fb --- /dev/null +++ b/bundles/org.openhab.ui/web/src/pages/settings/things/link/link-mixin.js @@ -0,0 +1,31 @@ +export default { + methods: { + /** + * Check whether the type of the given Item does match the type of the given channel. + * @param {object} item + * @param {object} channel + * @return {boolean} + */ + itemTypeIsChannelType (item, channel) { + if (!channel || !channel.itemType) return true + if (!item || !item.type) return true + if (channel.itemType.startsWith('Number')) { + return item.type.startsWith('Number') + } + return channel.itemType === item.type + }, + /** + * Check whether the given profileType is compatible with the given Item for the given channel. + * + * @param {object} channel + * @param {object} profileType + * @param {object} item + * @return {boolean} + */ + isProfileTypeCompatible (channel, profileType, item) { + if (!this.itemTypeIsChannelType(item, channel) && (profileType.uid === 'system:default' || profileType.uid === 'system:follow')) return false + if (!profileType.supportedItemTypes || profileType.supportedItemTypes.length === 0) return true + return profileType.supportedItemTypes.includes(item.type.split(':', 1)[0]) + } + } +}