@@ -289,6 +289,63 @@ async def test_it_gets_device_status_with_zigbee_failure(
289289 assert calls [2 ] == (("192.168.1.100" , "Shelly.GetStatus" ), {"timeout" : 10.0 })
290290 assert calls [3 ] == (("192.168.1.100" , "Shelly.ListMethods" ), {"timeout" : 10.0 })
291291
292+ async def test_it_returns_the_rpc_payload_not_the_response_frame (
293+ self , gateway , mock_rpc_client
294+ ):
295+ # Frame captured verbatim from a Gen4 device: the config a caller wants
296+ # sits under "result", alongside the request id and the device id.
297+ mock_rpc_client .make_rpc_request = AsyncMock (
298+ side_effect = [
299+ ({"methods" : ["Switch.GetConfig" ]}, 0.1 ),
300+ (
301+ {
302+ "id" : "68ef3f1a-b13a-490b-9ab0-d4b8f21d5580" ,
303+ "src" : "shelly1pmminig4-7c2c676d30d4" ,
304+ "result" : {"id" : 0 , "name" : None , "in_mode" : "flip" },
305+ },
306+ 0.1 ,
307+ ),
308+ ]
309+ )
310+
311+ result = await gateway .execute_component_action (
312+ "192.168.1.100" , "switch:0" , "GetConfig"
313+ )
314+
315+ assert result .success is True
316+ assert result .data == {"id" : 0 , "name" : None , "in_mode" : "flip" }
317+
318+ async def test_it_reports_a_device_rejection_as_a_failed_action (
319+ self , gateway , mock_rpc_client
320+ ):
321+ # Devices answer a rejected call with HTTP 200 and an "error" member,
322+ # so a frame that is never opened reads as a success.
323+ mock_rpc_client .make_rpc_request = AsyncMock (
324+ side_effect = [
325+ ({"methods" : ["Switch.GetConfig" ]}, 0.1 ),
326+ (
327+ {
328+ "id" : "b036bb7f-91f8-4b4b-b81b-0376cafedee0" ,
329+ "src" : "shelly1pmminig4-7c2c676d30d4" ,
330+ "error" : {
331+ "code" : - 105 ,
332+ "message" : "Argument 'id', value 99 not found!" ,
333+ },
334+ },
335+ 0.1 ,
336+ ),
337+ ]
338+ )
339+
340+ result = await gateway .execute_component_action (
341+ "192.168.1.100" , "switch:99" , "GetConfig"
342+ )
343+
344+ assert result .success is False
345+ assert result .data is None
346+ assert "value 99 not found" in result .error
347+ assert "-105" in result .error
348+
292349 async def test_it_handles_update_check_failure_gracefully (
293350 self , gateway , mock_rpc_client
294351 ):
0 commit comments