forked from openhab/openhab-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link add/edit: Fix profile selection (openhab#2941)
Regression from openhab#2690. Reported here: https://community.openhab.org/t/enocean-impossible-to-link-a-rockerswitch-channel-with-an-item-in-main-ui-there-is-no-profile-available-for-the-selected-item/160987 When creating a Thing channel link to an item, the profile selection are disabled. This presents two problems: - It made linking a trigger channel to an item not possible, because a profile must be selected, but they're disabled. - Linking a non-trigger channel to a new item is possible, but selecting a profile is not possible at link creation. The user has to create the link without a profile first, then go back to edit the link in order to assign a profile. When editing a channel link, profile selection was possible for unsupported profiles, e.g. when editing a link between a Switch Item and a Number channel, one could edit the link to use the default or follow profiles. --------- Signed-off-by: Florian Hotze <[email protected]>
- Loading branch information
1 parent
3861fa8
commit bd9c6f0
Showing
3 changed files
with
41 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
bundles/org.openhab.ui/web/src/pages/settings/things/link/link-mixin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} | ||
} | ||
} |