Skip to content

Commit

Permalink
Merge pull request #47 from mbillow/async-file-handling
Browse files Browse the repository at this point in the history
Call file handling functions via async jobs
  • Loading branch information
mbillow committed Aug 30, 2024
2 parents 62407aa + c024f95 commit 17af3db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ manually include this repository in HACS:
1. If you haven't already installed HACS, follow [their instructions](https://hacs.xyz/docs/setup/prerequisites).
2. Navigate to HACS.
3. Choose "Integrations"
4. Add this repository to your configuration.
1. Click the three dots in the upper right-hand corner.
2. Select "Custom repositories"
3. Enter `mbillow/ha-chargepoint` into the repository box.
4. Select the "Integration" type.
5. Click `Add`.
5. Install the integration like you would [any other HACS addon](https://hacs.xyz/docs/navigation/overview).
4. Install the integration like you would [any other HACS addon](https://hacs.xyz/docs/navigation/overview).

## Usage

Expand Down
11 changes: 8 additions & 3 deletions custom_components/chargepoint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
)
username = entry.data[CONF_USERNAME]
password = entry.data[CONF_PASSWORD]
original_session_token = entry.data[CONF_ACCESS_TOKEN]
session_token = retrieve_session_token(hass, entry) or original_session_token
current_token = entry.data[CONF_ACCESS_TOKEN]
token_from_disk = await hass.async_add_executor_job(
retrieve_session_token, hass, entry
)
session_token = token_from_disk or current_token

try:
client: ChargePoint = await hass.async_add_executor_job(
ChargePoint, username, password, session_token
)
persist_session_token(hass, entry, client.session_token)
await hass.async_add_executor_job(
persist_session_token, hass, entry, client.session_token
)
except ChargePointLoginError as exc:
_LOGGER.error("Failed to authenticate to ChargePoint")
raise ConfigEntryAuthFailed from exc
Expand Down
2 changes: 1 addition & 1 deletion custom_components/chargepoint/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"requirements": [
"python-chargepoint==1.9.2"
],
"version": "0.7.0"
"version": "0.8.0"
}

0 comments on commit 17af3db

Please sign in to comment.