Skip to content

Commit 3419a34

Browse files
author
lbbrhzn
authored
Improve trigger status notification (#373)
* trigger status notifications for all connectors * handle status notifications with connector_id>1 * store also status and error for connector_id==1 in extra_attr * add status notification for multiple connects * fix linting * improve trigger_status_notification, using actual number of connectors Co-authored-by: lbbrhzn <@lbbrhzn>
1 parent 7edea1e commit 3419a34

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

custom_components/ocpp/api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ async def handle_data_transfer(call):
390390
self.status = STATE_OK
391391
await asyncio.sleep(2)
392392
await self.get_supported_features()
393+
resp = await self.get_configuration(ckey.number_of_connectors.value)
394+
self._metrics[cdet.connectors.value].value = resp
393395
if prof.REM in self._attr_supported_features:
394396
if self.received_boot_notification is False:
395397
await self.trigger_boot_notification()
@@ -412,8 +414,6 @@ async def handle_data_transfer(call):
412414
# await self.configure(
413415
# "StopTxnSampledData", ",".join(self.entry.data[CONF_MONITORED_VARIABLES])
414416
# )
415-
resp = await self.get_configuration(ckey.number_of_connectors.value)
416-
self._metrics[cdet.connectors.value].value = resp
417417
# await self.start_transaction()
418418

419419
# Register custom services with home assistant
@@ -492,10 +492,12 @@ async def trigger_boot_notification(self):
492492
async def trigger_status_notification(self):
493493
"""Trigger status notifications for all connectors."""
494494
return_value = True
495-
for id in range(0, 1):
495+
nof_connectors = int(self._metrics[cdet.connectors.value].value)
496+
for id in range(0, nof_connectors + 1):
497+
_LOGGER.debug(f"trigger status notification for connector={id}")
496498
req = call.TriggerMessagePayload(
497499
requested_message=MessageTrigger.status_notification,
498-
connector_id=id,
500+
connector_id=int(id),
499501
)
500502
resp = await self.call(req)
501503
if resp.status != TriggerMessageStatus.accepted:

0 commit comments

Comments
 (0)