@@ -23,6 +23,7 @@ const dbEnum = require('../src-shared/db-enum')
2323const queryZcl = require ( '../src-electron/db/query-zcl' )
2424const queryDeviceType = require ( '../src-electron/db/query-device-type' )
2525const queryCommand = require ( '../src-electron/db/query-command' )
26+ const queryEvent = require ( '../src-electron/db/query-event' )
2627const queryPackage = require ( '../src-electron/db/query-package' )
2728const queryPackageNotification = require ( '../src-electron/db/query-package-notification' )
2829const zclLoader = require ( '../src-electron/zcl/zcl-loader' )
@@ -594,14 +595,14 @@ test(
594595 let ctx = await zclLoader . loadZcl ( db , env . builtinMatterZclMetafile ( ) )
595596 let packageId = ctx . packageId
596597
597- let zclCluster = await queryZcl . selectClusterByCode ( db , packageId , 0x001f )
598+ let aclCluster = await queryZcl . selectClusterByCode ( db , packageId , 0x001f )
598599
599600 /* Verify that the ACL attribute, defined using the list type format `array="true" type="X"` in XML,
600601 is correctly parsed and stored in the database as an array of AccessControlEntryStruct. */
601602 let attributes = await dbApi . dbAll (
602603 db ,
603604 "SELECT * FROM ATTRIBUTE WHERE CLUSTER_REF = ? AND CODE = 0x0000 AND NAME = 'ACL'" ,
604- [ zclCluster . id ]
605+ [ aclCluster . id ]
605606 )
606607 expect ( attributes . length ) . toBe ( 1 )
607608 let aclAttribute = attributes [ 0 ]
@@ -623,3 +624,111 @@ test(
623624 } ,
624625 testUtil . timeout . long ( )
625626)
627+
628+ test (
629+ 'test loading IS_OPTIONAL column for Matter attributes, commands, and events' ,
630+ async ( ) => {
631+ let db = await dbApi . initRamDatabase ( )
632+ try {
633+ await dbApi . loadSchema ( db , env . schemaFile ( ) , env . zapVersion ( ) )
634+ let ctx = await zclLoader . loadZcl ( db , env . builtinMatterZclMetafile ( ) )
635+ let packageId = ctx . packageId
636+
637+ let doorLockCluster = await queryZcl . selectClusterByCode (
638+ db ,
639+ packageId ,
640+ 0x0101
641+ )
642+ let doorLockClusterId = doorLockCluster . id
643+
644+ let attributes =
645+ await queryZcl . selectAttributesByClusterIdIncludingGlobal (
646+ db ,
647+ doorLockClusterId ,
648+ [ packageId ]
649+ )
650+ // optional attribute undefined, conformance undefined -> mandatory
651+ expect (
652+ testQuery . checkIfElementIsOptional ( attributes , 'ActuatorEnabled' )
653+ ) . toBeFalsy ( )
654+ // optional="true", conformance undefined -> optional
655+ expect (
656+ testQuery . checkIfElementIsOptional ( attributes , 'DoorClosedEvents' )
657+ ) . toBeTruthy ( )
658+ // optional="false", conformance undefined -> mandatory
659+ expect (
660+ testQuery . checkIfElementIsOptional ( attributes , 'LockType' )
661+ ) . toBeFalsy ( )
662+ // mandatory conformance, optional attribute undefined -> mandatory
663+ expect (
664+ testQuery . checkIfElementIsOptional ( attributes , 'OperatingMode' )
665+ ) . toBeFalsy ( )
666+ // optionalConform to feature DPS, optional="true" -> optional
667+ expect (
668+ testQuery . checkIfElementIsOptional ( attributes , 'DoorOpenEvents' )
669+ ) . toBeTruthy ( )
670+ // mandatory conformance, optional="true" -> optional as optional="true" takes precedence
671+ expect (
672+ testQuery . checkIfElementIsOptional ( attributes , 'LockState' )
673+ ) . toBeTruthy ( )
674+ // mandatoryConform to feature DPS, optional="false" -> mandatory as optional="false" takes precedence
675+ expect (
676+ testQuery . checkIfElementIsOptional ( attributes , 'DoorState' )
677+ ) . toBeFalsy ( )
678+
679+ let commands = await queryCommand . selectCommandsByClusterId (
680+ db ,
681+ doorLockClusterId ,
682+ [ packageId ]
683+ )
684+ // optional attribute undefined, conformance undefined -> mandatory
685+ expect (
686+ testQuery . checkIfElementIsOptional ( commands , 'LockDoor' )
687+ ) . toBeFalsy ( )
688+ // optional="true", conformance undefined -> optional
689+ expect (
690+ testQuery . checkIfElementIsOptional ( commands , 'GetWeekDaySchedule' )
691+ ) . toBeTruthy ( )
692+ // mandatory conformance, optional attribute undefined -> mandatory
693+ expect (
694+ testQuery . checkIfElementIsOptional ( commands , 'UnlockDoor' )
695+ ) . toBeFalsy ( )
696+ // mandatoryConform to feature WDSCH, optional="true" -> optional
697+ expect (
698+ testQuery . checkIfElementIsOptional ( commands , 'SetWeekDaySchedule' )
699+ ) . toBeTruthy ( )
700+ // optional conformance, optional="false" -> mandatory as optional="false" takes precedence
701+ expect (
702+ testQuery . checkIfElementIsOptional ( commands , 'UnlockWithTimeout' )
703+ ) . toBeFalsy ( )
704+
705+ let events = await queryEvent . selectEventsByClusterId (
706+ db ,
707+ doorLockClusterId
708+ )
709+ // optional attribute undefined, conformance undefined -> mandatory
710+ expect (
711+ testQuery . checkIfElementIsOptional ( events , 'LockUserChange' )
712+ ) . toBeFalsy ( )
713+ // optional="true", conformance undefined -> optional
714+ expect (
715+ testQuery . checkIfElementIsOptional ( events , 'LockOperation' )
716+ ) . toBeTruthy ( )
717+ // mandatory conformance, optional attribute undefined -> mandatory
718+ expect (
719+ testQuery . checkIfElementIsOptional ( events , 'LockOperationError' )
720+ ) . toBeFalsy ( )
721+ // mandatoryConform to feature DPS, optional="true" -> optional
722+ expect (
723+ testQuery . checkIfElementIsOptional ( events , 'DoorStateChange' )
724+ ) . toBeTruthy ( )
725+ // mandatory conformance, optional="true" -> optional as optional="true" takes precedence
726+ expect (
727+ testQuery . checkIfElementIsOptional ( events , 'DoorLockAlarm' )
728+ ) . toBeTruthy ( )
729+ } finally {
730+ await dbApi . closeDatabase ( db )
731+ }
732+ } ,
733+ testUtil . timeout . long ( )
734+ )
0 commit comments