[Main UI] Include bridgeID in thingUID on manual creation (#298)

This will include the ID of the bridge in the ThingUID if it is specified during the
manual creation of the thing.

The thingUID format will therefore be
`binding:thingType:bridgeID:thingID` if a
bridge is specified during the creation,
otherwise it will be `binding:thingType:thingID`.
This is consistent with the naming convention
adopted when creating things by other means
(files, inbox).

Note that the thingUID is immutable once the thing has been created, so the
bridge ID part will be false or missing when
the bridge is altered or assigned after the
creation.
Relying on the thingUID to determine the bridge
should be discouraged.
See https://github.com/openhab/openhab-addons/pull/7496#discussion_r426005622

Fixes #290.

Signed-off-by: Yannick Schaus <github@schaus.net>
pull/302/head
Yannick Schaus 2020-08-08 19:44:21 +02:00 committed by GitHub
parent 7453955770
commit 70b3b9f750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -26,7 +26,7 @@
<f7-list v-if="thingType.supportedBridgeTypeUIDs.length" inline-labels no-hairlines-md>
<thing-picker
title="Bridge" name="bridge" :value="thing.bridgeUID"
@input="(value) => { thing.bridgeUID = value; $emit('updated') }"
@input="updateBridge"
:filterType="thingType.supportedBridgeTypeUIDs" />
</f7-list>
</f7-col>
@ -45,9 +45,19 @@ export default {
ThingPicker
},
methods: {
computedThingUid () {
return (this.thing.bridgeUID)
? [this.thing.thingTypeUID, this.thing.bridgeUID.substring(this.thing.bridgeUID.lastIndexOf(':') + 1), this.thing.ID].join(':')
: [this.thing.thingTypeUID, this.thing.ID].join(':')
},
changeUID (event) {
this.thing.ID = event.target.value
this.thing.UID = this.thing.thingTypeUID + ':' + this.thing.ID
if (this.createMode) this.thing.UID = this.computedThingUid()
},
updateBridge (value) {
this.thing.bridgeUID = value
this.$emit('updated')
if (this.createMode) this.thing.UID = this.computedThingUid()
}
}
}