Skip to content

Commit

Permalink
trigger status notifications for all connectors (#365)
Browse files Browse the repository at this point in the history
* 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

Co-authored-by: lbbrhzn <@lbbrhzn>
  • Loading branch information
lbbrhzn authored Feb 5, 2022
1 parent 9b9811f commit 76ee686
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
31 changes: 20 additions & 11 deletions custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,18 @@ async def trigger_boot_notification(self):
return False

async def trigger_status_notification(self):
"""Trigger a status notification."""
req = call.TriggerMessagePayload(
requested_message=MessageTrigger.status_notification
)
resp = await self.call(req)
if resp.status == TriggerMessageStatus.accepted:
return True
else:
_LOGGER.warning("Failed with response: %s", resp.status)
return False
"""Trigger status notifications for all connectors."""
return_value = True
for id in range(0, 1):
req = call.TriggerMessagePayload(
requested_message=MessageTrigger.status_notification,
connector_id=id,
)
resp = await self.call(req)
if resp.status != TriggerMessageStatus.accepted:
_LOGGER.warning("Failed with response: %s", resp.status)
return_value = False
return return_value

async def become_operative(self):
"""Become operative."""
Expand Down Expand Up @@ -1103,9 +1105,16 @@ def on_status_notification(self, connector_id, error_code, status, **kwargs):
if connector_id == 0 or connector_id is None:
self._metrics[cstat.status.value].value = status
self._metrics[cstat.error_code.value].value = error_code
else:
elif connector_id == 1:
self._metrics[cstat.status_connector.value].value = status
self._metrics[cstat.error_code_connector.value].value = error_code
if connector_id >= 1:
self._metrics[cstat.status_connector.value].extra_attr[
connector_id
] = status
self._metrics[cstat.error_code_connector.value].extra_attr[
connector_id
] = error_code
if (
status == ChargePointStatus.suspended_ev.value
or status == ChargePointStatus.suspended_evse.value
Expand Down
13 changes: 12 additions & 1 deletion tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ async def send_start_transaction(self):
async def send_status_notification(self):
"""Send a status notification."""
request = call.StatusNotificationPayload(
connector_id=1,
connector_id=0,
error_code=ChargePointErrorCode.no_error,
status=ChargePointStatus.suspended_ev,
timestamp=datetime.now(tz=timezone.utc).isoformat(),
Expand All @@ -483,6 +483,17 @@ async def send_status_notification(self):
vendor_error_code="Test error",
)
resp = await self.call(request)
request = call.StatusNotificationPayload(
connector_id=2,
error_code=ChargePointErrorCode.no_error,
status=ChargePointStatus.available,
timestamp=datetime.now(tz=timezone.utc).isoformat(),
info="Test info",
vendor_id="The Mobility House",
vendor_error_code="Available",
)
resp = await self.call(request)

assert resp is not None

async def send_meter_data(self):
Expand Down

0 comments on commit 76ee686

Please sign in to comment.