diff --git a/config/configuration.yaml b/config/configuration.yaml index 7a99ba9e..b8c20681 100644 --- a/config/configuration.yaml +++ b/config/configuration.yaml @@ -47,6 +47,7 @@ frontend: #scene: !include scenes.yaml ocpp: + remote_id_tag: "TESTRFIDTAG123456789" default_authorization_status: 'Invalid' authorization_list: - id_tag: 'pulsar' diff --git a/custom_components/ocpp/chargepoint.py b/custom_components/ocpp/chargepoint.py index ad67edba..ea04ea79 100644 --- a/custom_components/ocpp/chargepoint.py +++ b/custom_components/ocpp/chargepoint.py @@ -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, @@ -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: @@ -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 diff --git a/custom_components/ocpp/const.py b/custom_components/ocpp/const.py index fbb5b2ad..7320b4e8 100644 --- a/custom_components/ocpp/const.py +++ b/custom_components/ocpp/const.py @@ -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" diff --git a/custom_components/ocpp/ocppv16.py b/custom_components/ocpp/ocppv16.py index b80a8a76..722f6286 100644 --- a/custom_components/ocpp/ocppv16.py +++ b/custom_components/ocpp/ocppv16.py @@ -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)