@@ -307,26 +307,13 @@ async def call(self, payload, suppress=True, unique_id=None):
307
307
"""
308
308
camel_case_payload = snake_to_camel_case (asdict (payload ))
309
309
310
- unique_id = (
311
- unique_id if unique_id is not None else str (self ._unique_id_generator ())
312
- )
313
-
314
310
response = await self .generic_call (
315
311
action = payload .__class__ .__name__ [:- 7 ],
316
312
payload_json = camel_case_payload ,
317
313
suppress = suppress ,
318
314
unique_id = unique_id
319
315
)
320
316
321
- if response .message_type_id == MessageType .CallError :
322
- LOGGER .warning ("Received a CALLError: %s'" , response )
323
- if suppress :
324
- return
325
- raise response .to_exception ()
326
- else :
327
- response .action = call .action
328
- validate_payload (response , self ._ocpp_version )
329
-
330
317
snake_case_payload = camel_to_snake_case (response .payload )
331
318
# Create the correct Payload instance based on the received payload. If
332
319
# this method is called with a call.BootNotificationPayload, then it
@@ -358,6 +345,10 @@ async def generic_call(self, action, payload_json, suppress=True, unique_id=None
358
345
CallError.
359
346
"""
360
347
348
+ unique_id = (
349
+ unique_id if unique_id is not None else str (self ._unique_id_generator ())
350
+ )
351
+
361
352
call = Call (
362
353
unique_id = unique_id ,
363
354
action = action ,
@@ -371,7 +362,7 @@ async def generic_call(self, action, payload_json, suppress=True, unique_id=None
371
362
async with self ._call_lock :
372
363
await self ._send (call .to_json ())
373
364
try :
374
- return await self ._get_specific_response (
365
+ response = await self ._get_specific_response (
375
366
call .unique_id , self ._response_timeout
376
367
)
377
368
except asyncio .TimeoutError :
@@ -380,6 +371,16 @@ async def generic_call(self, action, payload_json, suppress=True, unique_id=None
380
371
f"{ call .to_json ()} ."
381
372
)
382
373
374
+ if response .message_type_id == MessageType .CallError :
375
+ LOGGER .warning ("Received a CALLError: %s'" , response )
376
+ if suppress :
377
+ return
378
+ raise response .to_exception ()
379
+ else :
380
+ response .action = call .action
381
+ validate_payload (response , self ._ocpp_version )
382
+ return response
383
+
383
384
async def _get_specific_response (self , unique_id , timeout ):
384
385
"""
385
386
Return response with given unique ID or raise an asyncio.TimeoutError.
0 commit comments