@@ -327,8 +327,7 @@ async def post_connect(self):
327
327
try :
328
328
self .status = STATE_OK
329
329
await self .fetch_supported_features ()
330
- num_connectors : int = await self .get_number_of_connectors ()
331
- self .num_connectors = num_connectors
330
+ self .num_connectors = await self .get_number_of_connectors ()
332
331
for conn in range (1 , self .num_connectors + 1 ):
333
332
self ._init_connector_slots (conn )
334
333
self ._metrics [(0 , cdet .connectors .value )].value = self .num_connectors
@@ -355,13 +354,20 @@ async def post_connect(self):
355
354
356
355
# nice to have, but not needed for integration to function
357
356
# and can cause issues with some chargers
358
- await self .set_availability ()
357
+ try :
358
+ await self .set_availability ()
359
+ except asyncio .CancelledError :
360
+ raise
361
+ except Exception as ex :
362
+ _LOGGER .debug ("post_connect: set_availability ignored error: %s" , ex )
363
+
359
364
if prof .REM in self ._attr_supported_features :
360
365
if self .received_boot_notification is False :
361
366
await self .trigger_boot_notification ()
362
367
await self .trigger_status_notification ()
363
- except NotImplementedError as e :
364
- _LOGGER .error ("Configuration of the charger failed: %s" , e )
368
+
369
+ except Exception as e :
370
+ _LOGGER .debug ("post_connect aborted non-fatally: %s" , e )
365
371
366
372
async def trigger_boot_notification (self ):
367
373
"""Trigger a boot notification."""
@@ -640,8 +646,17 @@ def get_authorization_status(self, id_tag):
640
646
)
641
647
return auth_status
642
648
643
- def process_phases (self , data : list [MeasurandValue ], connector_id : int = 0 ):
649
+ def process_phases (self , data : list [MeasurandValue ], connector_id : int | None = 0 ):
644
650
"""Process phase data from meter values."""
651
+ # For single-connector chargers, use connector 1.
652
+ n_connectors = getattr (self , CONF_NUM_CONNECTORS , DEFAULT_NUM_CONNECTORS ) or 1
653
+ if connector_id in (None , 0 ):
654
+ target_cid = 1 if n_connectors == 1 else 0
655
+ else :
656
+ try :
657
+ target_cid = int (connector_id )
658
+ except Exception :
659
+ target_cid = 1 if n_connectors == 1 else 0
645
660
646
661
def average_of_nonzero (values ):
647
662
nonzero_values : list = [v for v in values if v != 0.0 ]
@@ -662,14 +677,12 @@ def average_of_nonzero(values):
662
677
measurand_data [measurand ] = {}
663
678
measurand_data [measurand ][om .unit .value ] = unit
664
679
measurand_data [measurand ][phase ] = value
665
- self ._metrics [(connector_id , measurand )].unit = unit
666
- self ._metrics [(connector_id , measurand )].extra_attr [om .unit .value ] = (
667
- unit
680
+ self ._metrics [(target_cid , measurand )].unit = unit
681
+ self ._metrics [(target_cid , measurand )].extra_attr [om .unit .value ] = unit
682
+ self ._metrics [(target_cid , measurand )].extra_attr [phase ] = value
683
+ self ._metrics [(target_cid , measurand )].extra_attr [om .context .value ] = (
684
+ context
668
685
)
669
- self ._metrics [(connector_id , measurand )].extra_attr [phase ] = value
670
- self ._metrics [(connector_id , measurand )].extra_attr [
671
- om .context .value
672
- ] = context
673
686
674
687
line_phases = [Phase .l1 .value , Phase .l2 .value , Phase .l3 .value , Phase .n .value ]
675
688
line_to_neutral_phases = [Phase .l1_n .value , Phase .l2_n .value , Phase .l3_n .value ]
@@ -707,15 +720,16 @@ def average_of_nonzero(values):
707
720
708
721
if metric_value is not None :
709
722
metric_unit = phase_info .get (om .unit .value )
723
+ m = self ._metrics [(target_cid , metric )]
710
724
if metric_unit == DEFAULT_POWER_UNIT :
711
- self . _metrics [( connector_id , metric )] .value = metric_value / 1000
712
- self . _metrics [( connector_id , metric )] .unit = HA_POWER_UNIT
725
+ m .value = metric_value / 1000
726
+ m .unit = HA_POWER_UNIT
713
727
elif metric_unit == DEFAULT_ENERGY_UNIT :
714
- self . _metrics [( connector_id , metric )] .value = metric_value / 1000
715
- self . _metrics [( connector_id , metric )] .unit = HA_ENERGY_UNIT
728
+ m .value = metric_value / 1000
729
+ m .unit = HA_ENERGY_UNIT
716
730
else :
717
- self . _metrics [( connector_id , metric )] .value = metric_value
718
- self . _metrics [( connector_id , metric )] .unit = metric_unit
731
+ m .value = metric_value
732
+ m .unit = metric_unit
719
733
720
734
@staticmethod
721
735
def get_energy_kwh (measurand_value : MeasurandValue ) -> float :
0 commit comments