@@ -381,10 +381,6 @@ async def call(self, payload, suppress=True, unique_id=None):
381
381
"""
382
382
camel_case_payload = snake_to_camel_case (serialize_as_dict (payload ))
383
383
384
- unique_id = (
385
- unique_id if unique_id is not None else str (self ._unique_id_generator ())
386
- )
387
-
388
384
action_name = payload .__class__ .__name__
389
385
# Due to deprecated call and callresults, remove in the future.
390
386
if "Payload" in payload .__class__ .__name__ :
@@ -397,15 +393,6 @@ async def call(self, payload, suppress=True, unique_id=None):
397
393
unique_id = unique_id
398
394
)
399
395
400
- if response .message_type_id == MessageType .CallError :
401
- LOGGER .warning ("Received a CALLError: %s'" , response )
402
- if suppress :
403
- return
404
- raise response .to_exception ()
405
- else :
406
- response .action = action_name
407
- validate_payload (response , self ._ocpp_version )
408
-
409
396
snake_case_payload = camel_to_snake_case (response .payload )
410
397
# Create the correct Payload instance based on the received payload. If
411
398
# this method is called with a call.BootNotificationPayload, then it
@@ -437,6 +424,10 @@ async def generic_call(self, action, payload_json, suppress=True, unique_id=None
437
424
CallError.
438
425
"""
439
426
427
+ unique_id = (
428
+ unique_id if unique_id is not None else str (self ._unique_id_generator ())
429
+ )
430
+
440
431
call = Call (
441
432
unique_id = unique_id ,
442
433
action = action ,
@@ -450,7 +441,7 @@ async def generic_call(self, action, payload_json, suppress=True, unique_id=None
450
441
async with self ._call_lock :
451
442
await self ._send (call .to_json ())
452
443
try :
453
- return await self ._get_specific_response (
444
+ response = await self ._get_specific_response (
454
445
call .unique_id , self ._response_timeout
455
446
)
456
447
except asyncio .TimeoutError :
@@ -459,6 +450,16 @@ async def generic_call(self, action, payload_json, suppress=True, unique_id=None
459
450
f"{ call .to_json ()} ."
460
451
)
461
452
453
+ if response .message_type_id == MessageType .CallError :
454
+ LOGGER .warning ("Received a CALLError: %s'" , response )
455
+ if suppress :
456
+ return
457
+ raise response .to_exception ()
458
+ else :
459
+ response .action = call .action
460
+ validate_payload (response , self ._ocpp_version )
461
+ return response
462
+
462
463
async def _get_specific_response (self , unique_id , timeout ):
463
464
"""
464
465
Return response with given unique ID or raise an asyncio.TimeoutError.
0 commit comments