From 937618d6ff821bf5dd9efd18cc8a69fb0d2f64a4 Mon Sep 17 00:00:00 2001 From: lbbrhzn Date: Fri, 18 Mar 2022 22:27:15 +0100 Subject: [PATCH] Authorization list (#447) * add autorization list * fix linting errors * fix auth list prcessing * fix authorization list processing Co-authored-by: lbbrhzn --- .devcontainer/configuration.yaml | 2 +- custom_components/ocpp/__init__.py | 5 ++++- custom_components/ocpp/api.py | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.devcontainer/configuration.yaml b/.devcontainer/configuration.yaml index 151020ad..531e7372 100644 --- a/.devcontainer/configuration.yaml +++ b/.devcontainer/configuration.yaml @@ -3,7 +3,7 @@ default_config: ocpp: default_authorization_status: 'Invalid' authorization_list: - - id_tag: '12345678' + - id_tag: 'pulsar' name: 'My tag' authorization_status : Accepted - id_tag: 'CAFEBABE' diff --git a/custom_components/ocpp/__init__.py b/custom_components/ocpp/__init__.py index a27638bc..7554608e 100644 --- a/custom_components/ocpp/__init__.py +++ b/custom_components/ocpp/__init__.py @@ -53,9 +53,12 @@ async def async_setup(hass: HomeAssistant, config: Config): """Read configuration from yaml.""" + + ocpp_config = config.get(DOMAIN, {}) if DOMAIN not in hass.data: hass.data[DOMAIN] = {} - hass.data[DOMAIN][CONFIG] = config + hass.data[DOMAIN][CONFIG] = ocpp_config + _LOGGER.info(f"config = {ocpp_config}") return True diff --git a/custom_components/ocpp/api.py b/custom_components/ocpp/api.py index 35b72a91..e3164e10 100644 --- a/custom_components/ocpp/api.py +++ b/custom_components/ocpp/api.py @@ -1214,13 +1214,23 @@ def on_start_transaction(self, connector_id, id_tag, meter_start, **kwargs): # get the authorization list auth_list = config.get(CONF_AUTH_LIST, {}) # search for the entry, based on the id_tag - auth_status = default_auth_status + auth_status = None for auth_entry in auth_list: - if id_tag is auth_entry.get(CONF_ID_TAG, None): + id_entry = auth_entry.get(CONF_ID_TAG, None) + if id_tag == id_entry: # get the authorization status, use the default if not configured auth_status = auth_entry.get(CONF_AUTH_STATUS, default_auth_status) + _LOGGER.debug( + f"id_tag='{id_tag}' found in auth_list, authorization_status='{auth_status}'" + ) break + if auth_status is None: + auth_status = default_auth_status + _LOGGER.debug( + f"id_tag='{id_tag}' not found in auth_list, default authorization_status='{auth_status}'" + ) + if auth_status is AuthorizationStatus.accepted.value: self.active_transaction_id = int(time.time()) self._metrics[cstat.id_tag.value].value = id_tag