Skip to content

Commit fe8004a

Browse files
committed
Add primary device type selection logic
1 parent 560c3de commit fe8004a

File tree

2 files changed

+46
-64
lines changed

2 files changed

+46
-64
lines changed

src/components/ZclCreateModifyEndpoint.vue

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,16 @@ export default {
175175

176176
// Set device types only in edit mode
177177
this.deviceTypeTmp = deviceTypes
178-
this.primaryDeviceTypeTmp = deviceTypes[0] ?? null // TODO set it here from the store
178+
this.primaryDeviceTypeTmp = deviceTypes[0] ?? null // First item is the primary device type
179179
} else {
180180
this.shownEndpoint.endpointIdentifier = this.getSmallestUnusedEndpointId()
181181
}
182-
const enableMultiDeviceFeatures = true
183-
this.enableMultipleDevice = enableMultiDeviceFeatures // TODO make it data driven from the store
184-
this.enablePrimaryDevice = enableMultiDeviceFeatures // TODO make it data driven from the store
182+
183+
const enableMultiDeviceFeatures =
184+
this.$store.state.zap.selectedZapConfig?.zclProperties?.category ===
185+
'matter'
186+
this.enableMultipleDevice = enableMultiDeviceFeatures
187+
this.enablePrimaryDevice = enableMultiDeviceFeatures
185188
},
186189
data() {
187190
return {
@@ -291,19 +294,19 @@ export default {
291294
const newPrimaryDeviceType =
292295
Array.isArray(value) && value.length > 0 ? value[0] : null
293296
if (this.enablePrimaryDevice) {
294-
if (this.primaryDeviceType === null) {
295-
this.primaryDeviceType = newPrimaryDeviceType
297+
if (this.primaryDeviceTypeTmp === null) {
298+
this.primaryDeviceTypeTmp = newPrimaryDeviceType
296299
} else {
297300
if (
298301
!value.includes(
299302
(deviceType) =>
300303
deviceType.deviceTypeRef ===
301-
this.primaryDeviceType.deviceTypeRef &&
304+
this.primaryDeviceTypeTmp.deviceTypeRef &&
302305
deviceType.deviceIdentifier ===
303-
this.primaryDeviceType.deviceIdentifier
306+
this.primaryDeviceTypeTmp.deviceIdentifier
304307
)
305308
) {
306-
this.primaryDeviceType = newPrimaryDeviceType
309+
this.primaryDeviceTypeTmp = newPrimaryDeviceType
307310
}
308311
}
309312
}
@@ -314,9 +317,16 @@ export default {
314317
return this.primaryDeviceTypeTmp
315318
},
316319
set(value) {
317-
this.primaryDeviceTypeTmp = value
318-
319-
// TODO write back to the store and backend here
320+
if (this.primaryDeviceTypeTmp?.deviceTypeRef == value?.deviceTypeRef) {
321+
return
322+
}
323+
const newPrimaryDevice = value
324+
let tempDeviceType = this.deviceType
325+
tempDeviceType = tempDeviceType.filter(
326+
(d) => d.deviceTypeRef !== newPrimaryDevice.deviceTypeRef
327+
)
328+
tempDeviceType.unshift(newPrimaryDevice)
329+
this.deviceType = tempDeviceType
320330
},
321331
},
322332
},
@@ -516,18 +526,6 @@ export default {
516526
},
517527
getDeviceOptionLabel(item) {
518528
if (item == null || item.deviceTypeRef == null) return ''
519-
// if (Array.isArray(item.deviceTypeRef)) {
520-
// let deviceOptionLabels = []
521-
// item.deviceTypeRef.forEach((d) =>
522-
// deviceOptionLabels.push(
523-
// this.zclDeviceTypes[d].description +
524-
// ' (' +
525-
// this.asHex(this.zclDeviceTypes[d].code, 4) +
526-
// ')'
527-
// )
528-
// )
529-
// return deviceOptionLabels
530-
// } else {
531529
if (
532530
item.deviceIdentifier != this.zclDeviceTypes[item.deviceTypeRef].code
533531
) {

src/components/ZclEndpointCard.vue

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ limitations under the License.
101101
</div>
102102
<div class="col-6">
103103
{{
104-
`${deviceType[0].description} (${asHex(deviceType[0].code, 4)})`
104+
`${deviceType[0]?.description} (${asHex(
105+
deviceType[0]?.code,
106+
4
107+
)})`
105108
}}
106109
</div>
107110
</div>
@@ -111,7 +114,7 @@ limitations under the License.
111114
<strong>Primary Device</strong>
112115
</div>
113116
<div class="col-6">
114-
{{ getPrimaryDeviceOptionLabel() }}
117+
{{ getPrimaryDeviceOptionLabel }}
115118
</div>
116119
</q-item>
117120
<q-item class="row">
@@ -264,43 +267,6 @@ export default {
264267
)
265268
this.deleteEpt()
266269
},
267-
getDeviceOptionLabel() {
268-
if (this.deviceType == null) return ''
269-
if (Array.isArray(this.deviceType)) {
270-
let deviceOptionLabels = []
271-
this.deviceType.forEach((d, index) =>
272-
deviceOptionLabels.push(
273-
d.description + '(' + this.asHex(d.code, 4) + ')'
274-
)
275-
)
276-
return deviceOptionLabels
277-
} else {
278-
return (
279-
this.deviceType.description +
280-
' (' +
281-
this.asHex(this.deviceType.code, 4) +
282-
')'
283-
)
284-
}
285-
},
286-
getPrimaryDeviceOptionLabel() {
287-
if (this.deviceType == null) return ''
288-
if (Array.isArray(this.deviceType)) {
289-
return (
290-
this.deviceType[0].description +
291-
' (' +
292-
this.asHex(this.deviceType[0].code, 4) +
293-
')'
294-
)
295-
} else {
296-
return (
297-
this.deviceType.description +
298-
' (' +
299-
this.asHex(this.deviceType.code, 4) +
300-
')'
301-
)
302-
}
303-
},
304270
handleDeletionDialog() {
305271
if (this.getStorageParam() == 'true') {
306272
this.deleteEpt()
@@ -382,7 +348,7 @@ export default {
382348
let refs =
383349
this.endpointDeviceTypeRef[this.endpointType[this.endpointReference]]
384350
let deviceTypes = []
385-
if (refs.length > 0) {
351+
if (refs?.length > 0) {
386352
refs.forEach((ref) => deviceTypes.push(this.zclDeviceTypes[ref]))
387353
return deviceTypes
388354
} else {
@@ -396,6 +362,24 @@ export default {
396362
}
397363
},
398364
},
365+
getPrimaryDeviceOptionLabel() {
366+
if (this.deviceType == null) return ''
367+
if (Array.isArray(this.deviceType)) {
368+
return (
369+
this.deviceType[0].description +
370+
' (' +
371+
this.asHex(this.deviceType[0].code, 4) +
372+
')'
373+
)
374+
} else {
375+
return (
376+
this.deviceType.description +
377+
' (' +
378+
this.asHex(this.deviceType.code, 4) +
379+
')'
380+
)
381+
}
382+
},
399383
isDeviceTypeArray: {
400384
get() {
401385
return Array.isArray(this.deviceType) && this.deviceType.length > 1

0 commit comments

Comments
 (0)