Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def __init__(
self.active_transaction_id: int = 0
self.triggered_boot_notification = False
self.received_boot_notification = False
self.post_connect_success = False
self.tasks = None
self._metrics = defaultdict(lambda: Metric(None, None))
self._metrics[cdet.identifier.value].value = id
Expand Down Expand Up @@ -393,11 +394,7 @@ async def handle_data_transfer(call):
await self.get_supported_features()
resp = await self.get_configuration(ckey.number_of_connectors.value)
self._metrics[cdet.connectors.value].value = resp
if prof.REM in self._attr_supported_features:
if self.received_boot_notification is False:
await self.trigger_boot_notification()
await self.trigger_status_notification()
await self.become_operative()
await self.set_availability()
await self.get_configuration(ckey.heartbeat_interval.value)
await self.configure(ckey.web_socket_ping_interval.value, "60")
await self.configure(
Expand Down Expand Up @@ -453,6 +450,15 @@ async def handle_data_transfer(call):
handle_get_diagnostics,
GDIAG_SERVICE_DATA_SCHEMA,
)
self.post_connect_success = True
_LOGGER.debug(f"'{self.id}' post connection setup completed successfully")

# nice to have, but not needed for integration to function
# and can cause issues with some chargers
if prof.REM in self._attr_supported_features:
if self.received_boot_notification is False:
await self.trigger_boot_notification()
await self.trigger_status_notification()
except (NotImplementedError) as e:
_LOGGER.error("Configuration of the charger failed: %s", e)

Expand Down Expand Up @@ -506,11 +512,6 @@ async def trigger_status_notification(self):
return_value = False
return return_value

async def become_operative(self):
"""Become operative."""
resp = await self.set_availability()
return resp

async def clear_profile(self):
"""Clear all charging profiles."""
req = call.ClearChargingProfilePayload()
Expand Down Expand Up @@ -907,7 +908,12 @@ async def reconnect(self, connection: websockets.server.WebSocketServerProtocol)
self.status = STATE_OK
self._connection = connection
self._metrics[cstat.reconnects.value].value += 1
await self.run([super().start(), self.monitor_connection()])
if self.post_connect_success is True:
await self.run([super().start(), self.monitor_connection()])
else:
await self.run(
[super().start(), self.post_connect(), self.monitor_connection()]
)

async def async_update_device_info(self, boot_info: dict):
"""Update device info asynchronuously."""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ async def test_services(hass, socket_enabled):
# use same id to ensure metrics populated
cp = ChargePoint("CP_1_test", ws)
cp.accept = False
cs.charge_points[cs.cpid].received_boot_notification = False
cs.charge_points[cs.cpid].post_connect_success = False
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lbbrhzn, not sure why these statements do not fully test the if statements above, any ideas?

Copy link
Owner

@lbbrhzn lbbrhzn Feb 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the NotImplementedError is never thrown. Are you expecting that when not accepted?
The ifs are not fully covered because the first if is always true (smart profile) and the second if is always false.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how the NotImplementedError should work, there is also the exceptions.py code which is not called during testing but references throwing an error configuring the charger.

try:
await asyncio.wait_for(
asyncio.gather(
Expand Down