@@ -3841,6 +3841,179 @@ describe("Extension: Bridge", () => {
38413841 ) ;
38423842 } ) ;
38433843
3844+ it ( "Should allow to read reporting config with endpoint as number" , async ( ) => {
3845+ const device = devices . bulb ;
3846+ const endpoint = device . getEndpoint ( 1 ) ! ;
3847+ endpoint . bind . mockClear ( ) ;
3848+ endpoint . readReportingConfig . mockClear ( ) ;
3849+ mockMQTTPublishAsync . mockClear ( ) ;
3850+ mockMQTTEvents . message (
3851+ "zigbee2mqtt/bridge/request/device/read_reporting_config" ,
3852+ stringify ( {
3853+ id : "0x000b57fffec6a5b2" ,
3854+ endpoint : 1 ,
3855+ cluster : "genLevelCtrl" ,
3856+ configs : [ { attribute : "currentLevel" } ] ,
3857+ } ) ,
3858+ ) ;
3859+ await flushPromises ( ) ;
3860+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledTimes ( 1 ) ;
3861+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledWith ( "genLevelCtrl" , [ { attribute : "currentLevel" } ] , { } ) ;
3862+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith (
3863+ "zigbee2mqtt/bridge/response/device/read_reporting_config" ,
3864+ stringify ( {
3865+ data : {
3866+ id : "0x000b57fffec6a5b2" ,
3867+ endpoint : 1 ,
3868+ cluster : "genLevelCtrl" ,
3869+ configs : [ { attribute : "currentLevel" } ] ,
3870+ } ,
3871+ status : "ok" ,
3872+ } ) ,
3873+ { } ,
3874+ ) ;
3875+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith ( "zigbee2mqtt/bridge/devices" , expect . any ( String ) , { retain : true } ) ;
3876+ } ) ;
3877+
3878+ it ( "Should allow to read reporting config with endpoint as string" , async ( ) => {
3879+ const device = devices . bulb ;
3880+ const endpoint = device . getEndpoint ( 1 ) ! ;
3881+ endpoint . bind . mockClear ( ) ;
3882+ endpoint . readReportingConfig . mockClear ( ) ;
3883+ mockMQTTPublishAsync . mockClear ( ) ;
3884+ mockMQTTEvents . message (
3885+ "zigbee2mqtt/bridge/request/device/read_reporting_config" ,
3886+ stringify ( {
3887+ id : "0x000b57fffec6a5b2" ,
3888+ endpoint : "1" ,
3889+ cluster : "genLevelCtrl" ,
3890+ configs : [ { attribute : "currentLevel" } ] ,
3891+ } ) ,
3892+ ) ;
3893+ await flushPromises ( ) ;
3894+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledTimes ( 1 ) ;
3895+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledWith ( "genLevelCtrl" , [ { attribute : "currentLevel" } ] , { } ) ;
3896+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith (
3897+ "zigbee2mqtt/bridge/response/device/read_reporting_config" ,
3898+ stringify ( {
3899+ data : {
3900+ id : "0x000b57fffec6a5b2" ,
3901+ endpoint : "1" ,
3902+ cluster : "genLevelCtrl" ,
3903+ configs : [ { attribute : "currentLevel" } ] ,
3904+ } ,
3905+ status : "ok" ,
3906+ } ) ,
3907+ { } ,
3908+ ) ;
3909+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith ( "zigbee2mqtt/bridge/devices" , expect . any ( String ) , { retain : true } ) ;
3910+ } ) ;
3911+
3912+ it ( "Should allow to read reporting config with manufacturer code" , async ( ) => {
3913+ const device = devices . bulb ;
3914+ const endpoint = device . getEndpoint ( 1 ) ! ;
3915+ endpoint . bind . mockClear ( ) ;
3916+ endpoint . readReportingConfig . mockClear ( ) ;
3917+ mockMQTTPublishAsync . mockClear ( ) ;
3918+ mockMQTTEvents . message (
3919+ "zigbee2mqtt/bridge/request/device/read_reporting_config" ,
3920+ stringify ( {
3921+ id : "0x000b57fffec6a5b2" ,
3922+ endpoint : 1 ,
3923+ cluster : "genLevelCtrl" ,
3924+ configs : [ { attribute : "currentLevel" } ] ,
3925+ manufacturerCode : 0x1234 ,
3926+ } ) ,
3927+ ) ;
3928+ await flushPromises ( ) ;
3929+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledTimes ( 1 ) ;
3930+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledWith ( "genLevelCtrl" , [ { attribute : "currentLevel" } ] , { manufacturerCode : 0x1234 } ) ;
3931+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith (
3932+ "zigbee2mqtt/bridge/response/device/read_reporting_config" ,
3933+ stringify ( {
3934+ data : {
3935+ id : "0x000b57fffec6a5b2" ,
3936+ endpoint : 1 ,
3937+ cluster : "genLevelCtrl" ,
3938+ configs : [ { attribute : "currentLevel" } ] ,
3939+ manufacturerCode : 0x1234 ,
3940+ } ,
3941+ status : "ok" ,
3942+ } ) ,
3943+ { } ,
3944+ ) ;
3945+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith ( "zigbee2mqtt/bridge/devices" , expect . any ( String ) , { retain : true } ) ;
3946+ } ) ;
3947+
3948+ it ( "Should throw error when read reporting config is called with malformed payload" , async ( ) => {
3949+ const device = devices . bulb ;
3950+ const endpoint = device . getEndpoint ( 1 ) ! ;
3951+ endpoint . readReportingConfig . mockClear ( ) ;
3952+ mockMQTTPublishAsync . mockClear ( ) ;
3953+ mockMQTTEvents . message (
3954+ "zigbee2mqtt/bridge/request/device/read_reporting_config" ,
3955+ stringify ( {
3956+ id : "bulb" ,
3957+ // endpoint: '1',
3958+ cluster : "genLevelCtrl" ,
3959+ configs : [ { attribute : "currentLevel" } ] ,
3960+ } ) ,
3961+ ) ;
3962+ await flushPromises ( ) ;
3963+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledTimes ( 0 ) ;
3964+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith (
3965+ "zigbee2mqtt/bridge/response/device/read_reporting_config" ,
3966+ stringify ( { data : { } , status : "error" , error : "Invalid payload" } ) ,
3967+ { } ,
3968+ ) ;
3969+ } ) ;
3970+
3971+ it ( "Should throw error when read reporting config is called for non-existing device" , async ( ) => {
3972+ const device = devices . bulb ;
3973+ const endpoint = device . getEndpoint ( 1 ) ! ;
3974+ endpoint . readReportingConfig . mockClear ( ) ;
3975+ mockMQTTPublishAsync . mockClear ( ) ;
3976+ mockMQTTEvents . message (
3977+ "zigbee2mqtt/bridge/request/device/read_reporting_config" ,
3978+ stringify ( {
3979+ id : "non_existing_device" ,
3980+ endpoint : "1" ,
3981+ cluster : "genLevelCtrl" ,
3982+ configs : [ { attribute : "currentLevel" } ] ,
3983+ } ) ,
3984+ ) ;
3985+ await flushPromises ( ) ;
3986+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledTimes ( 0 ) ;
3987+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith (
3988+ "zigbee2mqtt/bridge/response/device/read_reporting_config" ,
3989+ stringify ( { data : { } , status : "error" , error : "Device 'non_existing_device' does not exist" } ) ,
3990+ { } ,
3991+ ) ;
3992+ } ) ;
3993+
3994+ it ( "Should throw error when read reporting config is called for non-existing endpoint" , async ( ) => {
3995+ const device = devices . bulb ;
3996+ const endpoint = device . getEndpoint ( 1 ) ! ;
3997+ endpoint . readReportingConfig . mockClear ( ) ;
3998+ mockMQTTPublishAsync . mockClear ( ) ;
3999+ mockMQTTEvents . message (
4000+ "zigbee2mqtt/bridge/request/device/read_reporting_config" ,
4001+ stringify ( {
4002+ id : "0x000b57fffec6a5b2" ,
4003+ endpoint : "non_existing_endpoint" ,
4004+ cluster : "genLevelCtrl" ,
4005+ configs : [ { attribute : "currentLevel" } ] ,
4006+ } ) ,
4007+ ) ;
4008+ await flushPromises ( ) ;
4009+ expect ( endpoint . readReportingConfig ) . toHaveBeenCalledTimes ( 0 ) ;
4010+ expect ( mockMQTTPublishAsync ) . toHaveBeenCalledWith (
4011+ "zigbee2mqtt/bridge/response/device/read_reporting_config" ,
4012+ stringify ( { data : { } , status : "error" , error : "Device '0x000b57fffec6a5b2' does not have endpoint 'non_existing_endpoint'" } ) ,
4013+ { } ,
4014+ ) ;
4015+ } ) ;
4016+
38444017 it ( "Should allow to create a backup" , async ( ) => {
38454018 fs . mkdirSync ( path . join ( data . mockDir , "ext_converters" ) ) ;
38464019 fs . writeFileSync ( path . join ( data . mockDir , "ext_converters" , "afile.js" ) , "test123" ) ;
0 commit comments