Skip to content
Open
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
1 change: 1 addition & 0 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ frontend:
#scene: !include scenes.yaml

ocpp:
remote_id_tag: "TESTRFIDTAG123456789"
default_authorization_status: 'Invalid'
authorization_list:
- id_tag: 'pulsar'
Expand Down
24 changes: 22 additions & 2 deletions custom_components/ocpp/chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
CONF_AUTH_STATUS,
CONF_DEFAULT_AUTH_STATUS,
CONF_ID_TAG,
CONF_REMOTE_ID_TAG,
CONF_MONITORED_VARIABLES,
CONF_NUM_CONNECTORS,
CONF_CPIDS,
Expand Down Expand Up @@ -279,8 +280,7 @@ def __init__(
self._metrics[(0, cstat.reconnects.value)].value = 0

self._attr_supported_features = prof.NONE
alphabet = string.ascii_uppercase + string.digits
self._remote_id_tag = "".join(secrets.choice(alphabet) for i in range(20))
self._remote_id_tag = self.get_remote_id_tag()
self.num_connectors: int = DEFAULT_NUM_CONNECTORS

def _init_connector_slots(self, conn_id: int) -> None:
Expand All @@ -293,6 +293,26 @@ def _init_connector_slots(self, conn_id: int) -> None:
self._metrics[(conn_id, csess.session_energy.value)].unit = HA_ENERGY_UNIT
self._metrics[(conn_id, csess.meter_start.value)].unit = HA_ENERGY_UNIT

def get_remote_id_tag(self) -> str:
"""Get remote id tag from configuration.yaml or generate a random 20 char one."""
config = self.hass.data[DOMAIN].get(CONFIG, {})
alphabet = string.ascii_uppercase + string.digits
fallback = "".join(secrets.choice(alphabet) for _ in range(20))
remote_id_tag = config.get(CONF_REMOTE_ID_TAG)

if isinstance(remote_id_tag, str):
remote_id_tag = remote_id_tag.strip()
if 0 < len(remote_id_tag) <= 20:
return remote_id_tag

if remote_id_tag is not None:
_LOGGER.warning(
"Invalid %s configured for charge point %s; using generated fallback tag",
CONF_REMOTE_ID_TAG,
self.id,
)

return fallback
async def get_number_of_connectors(self) -> int:
"""Return number of connectors on this charger."""
return self.num_connectors
Expand Down
1 change: 1 addition & 0 deletions custom_components/ocpp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CONF_NUM_CONNECTORS = "num_connectors"
CONF_PASSWORD = ha.CONF_PASSWORD
CONF_PORT = ha.CONF_PORT
CONF_REMOTE_ID_TAG = "remote_id_tag"
CONF_SKIP_SCHEMA_VALIDATION = "skip_schema_validation"
CONF_FORCE_SMART_CHARGING = "force_smart_charging"
CONF_SSL = "ssl"
Expand Down
2 changes: 2 additions & 0 deletions custom_components/ocpp/ocppv16.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ async def start_transaction(self, connector_id: int = 1):
)
resp = await self.call(req)
if resp.status == RemoteStartStopStatus.accepted:
# Reset id tag if set by on authorize (RFID)
self._metrics[0][cstat.id_tag.value].value = self._remote_id_tag
return True
else:
_LOGGER.warning("Failed with response: %s", resp.status)
Expand Down