Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate random tagId used to start transaction from UI #1302

Merged
merged 1 commit into from
Sep 8, 2024
Merged
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
21 changes: 10 additions & 11 deletions custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import json
import logging
from math import sqrt
import secrets
import ssl
import string
import time

from homeassistant.components.persistent_notification import DOMAIN as PN_DOMAIN
Expand Down Expand Up @@ -378,6 +380,8 @@ def __init__(
self._metrics[csess.meter_start.value].unit = UnitOfMeasure.kwh.value
self._attr_supported_features = prof.NONE
self._metrics[cstat.reconnects.value].value: int = 0
alphabet = string.ascii_uppercase + string.digits
self._remote_id_tag = "".join(secrets.choice(alphabet) for i in range(20))

async def post_connect(self):
"""Logic to be executed right after a charger connects."""
Expand Down Expand Up @@ -763,17 +767,9 @@ async def set_availability(self, state: bool = True):
return False

async def start_transaction(self):
"""
Remote start a transaction.

Check if authorisation enabled, if it is disable it before remote start
"""
resp = await self.get_configuration(ckey.authorize_remote_tx_requests.value)
if resp is True:
await self.configure(ckey.authorize_remote_tx_requests.value, "false")
req = call.RemoteStartTransaction(
connector_id=1, id_tag=self._metrics[cdet.identifier.value].value[:20]
)
"""Remote start a transaction."""
_LOGGER.info("Start transaction with remote ID tag: %s", self._remote_id_tag)
req = call.RemoteStartTransaction(connector_id=1, id_tag=self._remote_id_tag)
resp = await self.call(req)
if resp.status == RemoteStartStopStatus.accepted:
return True
Expand Down Expand Up @@ -1392,6 +1388,9 @@ def on_security_event(self, type, timestamp, **kwargs):

def get_authorization_status(self, id_tag):
"""Get the authorization status for an id_tag."""
# authorize if its the tag of this charger used for remote start_transaction
if id_tag == self._remote_id_tag:
return AuthorizationStatus.accepted.value
# get the domain wide configuration
config = self.hass.data[DOMAIN].get(CONFIG, {})
# get the default authorization status. Use accept if not configured
Expand Down