70
70
HAChargerSession as csess ,
71
71
HAChargerStatuses as cstat ,
72
72
OcppMisc as om ,
73
+ Profiles as prof ,
73
74
)
74
75
75
76
_LOGGER : logging .Logger = logging .getLogger (__package__ )
@@ -259,14 +260,14 @@ def __init__(
259
260
# Indicates if the charger requires a reboot to apply new
260
261
# configuration.
261
262
self ._requires_reboot = False
262
- self ._features_supported = {}
263
263
self .preparing = asyncio .Event ()
264
264
self ._transactionId = 0
265
265
self ._metrics = defaultdict (lambda : Metric (None , None ))
266
266
self ._metrics [cdet .identifier .value ].value = id
267
267
self ._metrics [csess .session_time .value ].unit = TIME_MINUTES
268
268
self ._metrics [csess .session_energy .value ].unit = UnitOfMeasure .kwh .value
269
269
self ._metrics [csess .meter_start .value ].unit = UnitOfMeasure .kwh .value
270
+ self ._attr_supported_features : int = 0
270
271
271
272
async def post_connect (self ):
272
273
"""Logic to be executed right after a charger connects."""
@@ -331,7 +332,7 @@ async def handle_get_diagnostics(call):
331
332
try :
332
333
self .status = STATE_OK
333
334
await self .get_supported_features ()
334
- if om . feature_profile_remote . value in self ._features_supported :
335
+ if prof . REM in self ._attr_supported_features :
335
336
await self .trigger_boot_notification ()
336
337
await self .trigger_status_notification ()
337
338
await self .become_operative ()
@@ -365,7 +366,7 @@ async def handle_get_diagnostics(call):
365
366
handle_get_configuration ,
366
367
GCONF_SERVICE_DATA_SCHEMA ,
367
368
)
368
- if om . feature_profile_smart . value in self ._features_supported :
369
+ if prof . SMART in self ._attr_supported_features :
369
370
self .hass .services .async_register (
370
371
DOMAIN , csvcs .service_clear_profile .value , handle_clear_profile
371
372
)
@@ -375,7 +376,7 @@ async def handle_get_diagnostics(call):
375
376
handle_set_charge_rate ,
376
377
SCR_SERVICE_DATA_SCHEMA ,
377
378
)
378
- if om . feature_profile_firmware . value in self ._features_supported :
379
+ if prof . FW in self ._attr_supported_features :
379
380
self .hass .services .async_register (
380
381
DOMAIN ,
381
382
csvcs .service_update_firmware .value ,
@@ -396,9 +397,20 @@ async def get_supported_features(self):
396
397
req = call .GetConfigurationPayload (key = [ckey .supported_feature_profiles .value ])
397
398
resp = await self .call (req )
398
399
for key_value in resp .configuration_key :
399
- self ._features_supported = key_value [om .value .value ]
400
- self ._metrics [cdet .features .value ].value = self ._features_supported
401
- _LOGGER .debug ("Supported feature profiles: %s" , self ._features_supported )
400
+ if om .feature_profile_core .value in key_value [om .value .value ]:
401
+ self ._attr_supported_features |= prof .CORE
402
+ if om .feature_profile_firmware .value in key_value [om .value .value ]:
403
+ self ._attr_supported_features |= prof .FW
404
+ if om .feature_profile_smart .value in key_value [om .value .value ]:
405
+ self ._attr_supported_features |= prof .SMART
406
+ if om .feature_profile_reservation .value in key_value [om .value .value ]:
407
+ self ._attr_supported_features |= prof .RES
408
+ if om .feature_profile_remote .value in key_value [om .value .value ]:
409
+ self ._attr_supported_features |= prof .REM
410
+ if om .feature_profile_auth .value in key_value [om .value .value ]:
411
+ self ._attr_supported_features |= prof .AUTH
412
+ self ._metrics [cdet .features .value ].value = self ._attr_supported_features
413
+ _LOGGER .debug ("Supported feature profiles: %s" , key_value [om .value .value ])
402
414
403
415
async def trigger_boot_notification (self ):
404
416
"""Trigger a boot notification."""
@@ -441,7 +453,7 @@ async def clear_profile(self):
441
453
442
454
async def set_charge_rate (self , limit_amps : int = 32 , limit_watts : int = 22000 ):
443
455
"""Set a charging profile with defined limit."""
444
- if om . feature_profile_smart . value in self ._features_supported :
456
+ if prof . SMART in self ._attr_supported_features :
445
457
resp = await self .get_configuration (
446
458
ckey .charging_schedule_allowed_charging_rate_unit .value
447
459
)
@@ -511,7 +523,7 @@ async def start_transaction(self, limit_amps: int = 32, limit_watts: int = 22000
511
523
resp = await self .get_configuration (ckey .authorize_remote_tx_requests .value )
512
524
if resp .lower () == "true" :
513
525
await self .configure (ckey .authorize_remote_tx_requests .value , "false" )
514
- if om . feature_profile_smart . value in self ._features_supported :
526
+ if prof . SMART in self ._attr_supported_features :
515
527
resp = await self .get_configuration (
516
528
ckey .charging_schedule_allowed_charging_rate_unit .value
517
529
)
@@ -593,7 +605,7 @@ async def update_firmware(self, firmware_url: str, wait_time: int = 0):
593
605
"""Update charger with new firmware if available."""
594
606
"""where firmware_url is the http or https url of the new firmware"""
595
607
"""and wait_time is hours from now to wait before install"""
596
- if om . feature_profile_firmware . value in self ._features_supported :
608
+ if prof . FW in self ._attr_supported_features :
597
609
schema = vol .Schema (vol .Url ())
598
610
try :
599
611
url = schema (firmware_url )
@@ -612,7 +624,7 @@ async def update_firmware(self, firmware_url: str, wait_time: int = 0):
612
624
613
625
async def get_diagnostics (self , upload_url : str ):
614
626
"""Upload diagnostic data to server from charger."""
615
- if om . feature_profile_firmware . value in self ._features_supported :
627
+ if prof . FW in self ._attr_supported_features :
616
628
schema = vol .Schema (vol .Url ())
617
629
try :
618
630
url = schema (upload_url )
@@ -963,6 +975,11 @@ def on_heartbeat(self, **kwargs):
963
975
self .hass .async_create_task (self .central .update (self .central .cpid ))
964
976
return call_result .HeartbeatPayload (current_time = now )
965
977
978
+ @property
979
+ def supported_features (self ) -> int :
980
+ """Flag of Ocpp features that are supported."""
981
+ return self ._attr_supported_features
982
+
966
983
def get_metric (self , measurand : str ):
967
984
"""Return last known value for given measurand."""
968
985
return self ._metrics [measurand ].value
0 commit comments