@@ -283,17 +283,10 @@ async def clear_profile(
283
283
purpose : ChargingProfilePurposeType | None = None ,
284
284
) -> bool :
285
285
"""Clear charging profiles (per connector and/or purpose)."""
286
- criteria = {}
287
- if purpose is not None :
288
- criteria ["charging_profile_purpose" ] = purpose .value
289
-
290
- target_connector = None
291
- if conn_id is not None :
292
- target_connector = int (conn_id )
293
-
286
+ target_connector = int (conn_id ) if conn_id is not None else None
294
287
req = call .ClearChargingProfile (
295
288
connector_id = target_connector ,
296
- charging_profile_purpose = criteria if criteria else None ,
289
+ charging_profile_purpose = purpose . value if purpose is not None else None ,
297
290
)
298
291
resp = await self .call (req )
299
292
if resp .status in (
@@ -492,40 +485,58 @@ async def unlock(self, connector_id: int = 1):
492
485
return False
493
486
494
487
async def update_firmware (self , firmware_url : str , wait_time : int = 0 ):
495
- """Update charger with new firmware if available."""
496
- """where firmware_url is the http or https url of the new firmware"""
497
- """and wait_time is hours from now to wait before install"""
498
- if prof .FW in self ._attr_supported_features :
499
- schema = vol .Schema (vol .Url ())
500
- try :
501
- url = schema (firmware_url )
502
- except vol .MultipleInvalid as e :
503
- _LOGGER .debug ("Failed to parse url: %s" , e )
504
- update_time = (datetime .now (tz = UTC ) + timedelta (hours = wait_time )).strftime (
505
- "%Y-%m-%dT%H:%M:%SZ"
506
- )
507
- req = call .UpdateFirmware (location = url , retrieve_date = update_time )
488
+ """Update charger with new firmware if available.
489
+
490
+ - firmware_url: http/https URL of the new firmware
491
+ - wait_time: hours from now to wait before install
492
+ """
493
+ features = int (self ._attr_supported_features or 0 )
494
+ if not (features & prof .FW ):
495
+ _LOGGER .warning ("Charger does not support OCPP firmware updating" )
496
+ return False
497
+
498
+ schema = vol .Schema (vol .Url ())
499
+ try :
500
+ url = schema (firmware_url )
501
+ except vol .MultipleInvalid as e :
502
+ _LOGGER .warning ("Failed to parse url: %s" , e )
503
+ return False
504
+
505
+ try :
506
+ retrieve_time = (
507
+ datetime .now (tz = UTC ) + timedelta (hours = max (0 , int (wait_time or 0 )))
508
+ ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
509
+ except Exception :
510
+ retrieve_time = datetime .now (tz = UTC ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
511
+
512
+ try :
513
+ req = call .UpdateFirmware (location = str (url ), retrieve_date = retrieve_time )
508
514
resp = await self .call (req )
509
- _LOGGER .info ("Response : %s" , resp )
515
+ _LOGGER .info ("UpdateFirmware response : %s" , resp )
510
516
return True
511
- else :
512
- _LOGGER .warning ( "Charger does not support ocpp firmware updating" )
517
+ except Exception as e :
518
+ _LOGGER .error ( "UpdateFirmware failed: %s" , e )
513
519
return False
514
520
515
521
async def get_diagnostics (self , upload_url : str ):
516
522
"""Upload diagnostic data to server from charger."""
517
- if prof .FW in self ._attr_supported_features :
523
+ features = int (self ._attr_supported_features or 0 )
524
+ if features & prof .FW :
518
525
schema = vol .Schema (vol .Url ())
519
526
try :
520
527
url = schema (upload_url )
521
528
except vol .MultipleInvalid as e :
522
529
_LOGGER .warning ("Failed to parse url: %s" , e )
523
- req = call .GetDiagnostics (location = url )
530
+ return
531
+ req = call .GetDiagnostics (location = str (url ))
524
532
resp = await self .call (req )
525
533
_LOGGER .info ("Response: %s" , resp )
526
534
return True
527
535
else :
528
- _LOGGER .warning ("Charger does not support ocpp diagnostics uploading" )
536
+ _LOGGER .debug (
537
+ "Charger %s does not support ocpp diagnostics uploading" ,
538
+ self .id ,
539
+ )
529
540
return False
530
541
531
542
async def data_transfer (self , vendor_id : str , message_id : str = "" , data : str = "" ):
0 commit comments