@@ -97,6 +97,48 @@ describe("Shelly 2PM Gen4 cover mode", () => {
9797 expect ( state ) . toStrictEqual ( { switch_type_sw1 : "toggle" } ) ;
9898 } ) ;
9999
100+ it ( "reads switch input type through the Shelly RPC endpoint" , async ( ) => {
101+ const response = JSON . stringify ( { id : 1 , result : { id : 1 , type : "button" , enable : true , invert : false } } ) ;
102+ const read = vi . fn ( ) . mockResolvedValueOnce ( { rxCtl : response . length } ) . mockResolvedValueOnce ( { data : response } ) ;
103+ const device = mockShelly2PMCoverWithInputs ( read ) ;
104+ const definition = await findByDevice ( device ) ;
105+ const converter = definition . toZigbee . find ( ( converter ) => converter . key . includes ( "switch_type" ) ) as Tz . Converter ;
106+ const publish = vi . fn ( ) ;
107+
108+ await converter . convertGet ?.( device . getEndpoint ( 3 ) , "switch_type" , { endpoint_name : "sw2" , message : { } , publish} as never ) ;
109+
110+ expect ( device . getEndpoint ( 239 ) . write ) . toHaveBeenCalledWith (
111+ "shellyRPCCluster" ,
112+ { data : expect . stringContaining ( "Input.GetConfig" ) } ,
113+ expect . any ( Object ) ,
114+ ) ;
115+ expect ( device . getEndpoint ( 239 ) . write ) . toHaveBeenCalledWith ( "shellyRPCCluster" , { data : expect . stringContaining ( '"id":1' ) } , expect . any ( Object ) ) ;
116+ expect ( read ) . toHaveBeenCalledWith ( "shellyRPCCluster" , [ "rxCtl" ] , expect . any ( Object ) ) ;
117+ expect ( read ) . toHaveBeenCalledWith ( "shellyRPCCluster" , [ "data" ] , expect . any ( Object ) ) ;
118+ expect ( device . getEndpoint ( 3 ) . read ) . not . toHaveBeenCalled ( ) ;
119+ expect ( publish ) . toHaveBeenCalledWith ( { switch_type_sw2 : "momentary" } ) ;
120+ } ) ;
121+
122+ it ( "writes switch input type through the Shelly RPC endpoint" , async ( ) => {
123+ const device = mockShelly2PMCoverWithInputs ( ) ;
124+ const definition = await findByDevice ( device ) ;
125+ const converter = definition . toZigbee . find ( ( converter ) => converter . key . includes ( "switch_type" ) ) as Tz . Converter ;
126+
127+ await converter . convertSet ?.( device . getEndpoint ( 3 ) , "switch_type" , "momentary" , { endpoint_name : "sw2" , message : { } } as never ) ;
128+
129+ expect ( device . getEndpoint ( 239 ) . write ) . toHaveBeenCalledWith (
130+ "shellyRPCCluster" ,
131+ { data : expect . stringContaining ( "Input.SetConfig" ) } ,
132+ expect . any ( Object ) ,
133+ ) ;
134+ expect ( device . getEndpoint ( 239 ) . write ) . toHaveBeenCalledWith (
135+ "shellyRPCCluster" ,
136+ { data : expect . stringContaining ( '"type":"button"' ) } ,
137+ expect . any ( Object ) ,
138+ ) ;
139+ expect ( device . getEndpoint ( 3 ) . write ) . not . toHaveBeenCalled ( ) ;
140+ } ) ;
141+
100142 it ( "reads two-channel switch mode through the Shelly RPC endpoint" , async ( ) => {
101143 const response = JSON . stringify ( { id : 1 , result : { id : 1 , in_mode : "detached" } } ) ;
102144 const read = vi . fn ( ) . mockResolvedValueOnce ( { rxCtl : response . length } ) . mockResolvedValueOnce ( { data : response } ) ;
0 commit comments