Skip to content

Commit 3aa3b10

Browse files
drc38lbbrhzn
andauthored
remove extra post_connect calls (lbbrhzn#1527)
* remove extra post_connect calls * fix tests --------- Co-authored-by: lbbrhzn <[email protected]>
1 parent e8e34ce commit 3aa3b10

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

.devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lbbrhzn/ocpp",
3-
"image": "mcr.microsoft.com/devcontainers/python:3.12",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.13",
44
"postCreateCommand": "scripts/setup",
55
"forwardPorts": [
66
8123

custom_components/ocpp/chargepoint.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ async def post_connect(self):
224224

225225
try:
226226
self.status = STATE_OK
227-
await asyncio.sleep(2)
228227
await self.fetch_supported_features()
229228
num_connectors: int = await self.get_number_of_connectors()
230229
self._metrics[cdet.connectors.value].value = num_connectors
@@ -389,9 +388,7 @@ async def _handle_call(self, msg):
389388

390389
async def start(self):
391390
"""Start charge point."""
392-
await self.run(
393-
[super().start(), self.post_connect(), self.monitor_connection()]
394-
)
391+
await self.run([super().start(), self.monitor_connection()])
395392

396393
async def run(self, tasks):
397394
"""Run a specified list of tasks."""
@@ -430,9 +427,7 @@ async def reconnect(self, connection: ServerConnection):
430427
if self.post_connect_success is True:
431428
await self.run([super().start(), self.monitor_connection()])
432429
else:
433-
await self.run(
434-
[super().start(), self.post_connect(), self.monitor_connection()]
435-
)
430+
await self.run([super().start(), self.monitor_connection()])
436431

437432
async def async_update_device_info(
438433
self, serial: str, vendor: str, model: str, firmware_version: str

tests/test_charge_point_v16.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
set_number,
5252
create_configuration,
5353
remove_configuration,
54+
wait_ready,
5455
)
5556

5657
SERVICES = [
@@ -307,6 +308,7 @@ async def test_cms_responses_restore_v16(
307308
await asyncio.wait_for(
308309
asyncio.gather(
309310
cp.start(),
311+
cp.send_boot_notification(),
310312
cp.send_start_transaction(12344),
311313
cp.send_meter_periodic_data(),
312314
),
@@ -325,6 +327,7 @@ async def test_cms_responses_restore_v16(
325327
await asyncio.wait_for(
326328
asyncio.gather(
327329
cp.start(),
330+
cp.send_boot_notification(),
328331
cp.send_meter_periodic_data(),
329332
),
330333
timeout=3,
@@ -436,8 +439,9 @@ async def test_cms_responses_actions_v16(
436439
cp = ChargePoint(f"{cp_id}_client", ws)
437440
with contextlib.suppress(asyncio.TimeoutError):
438441
cp_task = asyncio.create_task(cp.start())
439-
await asyncio.sleep(5)
440-
# Allow charger time to connect bfore running services
442+
await cp.send_boot_notification()
443+
await wait_ready(cs.charge_points[cp_id])
444+
# Confirm charger completed post_connect before running services
441445
await asyncio.wait_for(
442446
asyncio.gather(
443447
cp.send_meter_clock_data(),
@@ -494,6 +498,7 @@ async def test_cms_responses_actions_v16(
494498
await asyncio.wait_for(
495499
asyncio.gather(
496500
cp.start(),
501+
cp.send_boot_notification(),
497502
cp.send_start_transaction(0),
498503
cp.send_meter_periodic_data(),
499504
cp.send_main_meter_clock_data(),
@@ -526,6 +531,7 @@ async def test_cms_responses_actions_v16(
526531
await asyncio.wait_for(
527532
asyncio.gather(
528533
cp.start(),
534+
cp.send_boot_notification(),
529535
cp.send_start_transaction(0),
530536
cp.send_meter_energy_kwh(),
531537
cp.send_meter_clock_data(),
@@ -585,8 +591,9 @@ async def test_cms_responses_errors_v16(
585591
cp = ChargePoint(f"{cp_id}_client", ws)
586592
cp.accept = False
587593
cp_task = asyncio.create_task(cp.start())
588-
await asyncio.sleep(5)
589-
# Allow charger time to reconnect bfore running services
594+
await cp.send_boot_notification()
595+
await wait_ready(cs.charge_points[cp_id])
596+
# Confirm charger completed post_connect before running services
590597
await asyncio.wait_for(
591598
asyncio.gather(
592599
cs.charge_points[cp_id].trigger_boot_notification(),

0 commit comments

Comments
 (0)