Skip to content

Commit

Permalink
Authorization list (#447)
Browse files Browse the repository at this point in the history
* add autorization list

* fix linting errors

* fix auth list prcessing

* fix authorization list processing

Co-authored-by: lbbrhzn <lbbrhzn>
  • Loading branch information
lbbrhzn authored Mar 18, 2022
1 parent 5036e0a commit 937618d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion custom_components/ocpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
14 changes: 12 additions & 2 deletions custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 937618d

Please sign in to comment.