Skip to content

Commit

Permalink
Clean up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
arjenbos committed Jan 18, 2024
1 parent 46c4b1d commit 6fa9a91
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions custom_components/postnl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> True:
try:
await auth.check_and_refresh_token()
except requests.exceptions.ConnectionError as exception:
raise ConfigEntryNotReady(f"Unable to retrieve oauth data from PostNL") from exception
raise ConfigEntryNotReady("Unable to retrieve oauth data from PostNL") from exception

hass.data[DOMAIN][entry.entry_id] = auth

Expand All @@ -44,10 +44,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> True:
try:
userinfo = await hass.async_add_executor_job(postnl_login_api.userinfo)
except (requests.exceptions.RequestException, urllib3.exceptions.MaxRetryError) as exception:
raise ConfigEntryNotReady(f"Unable to retrieve user information from PostNL.") from exception
raise ConfigEntryNotReady("Unable to retrieve user information from PostNL.") from exception

if "error" in userinfo:
raise ConfigEntryNotReady(f"Error in retrieving user information from PostNL.")
raise ConfigEntryNotReady("Error in retrieving user information from PostNL.")

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

Expand Down
2 changes: 0 additions & 2 deletions custom_components/postnl/application_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ async def async_get_auth_implementation(

code_verifier = base64.urlsafe_b64encode(os.urandom(40)).decode('utf-8')
code_verifier = re.sub('[^a-zA-Z0-9]+', '', code_verifier)
code_verifier, len(code_verifier)

code_challenge = hashlib.sha256(code_verifier.encode('utf-8')).digest()
code_challenge = base64.urlsafe_b64encode(code_challenge).decode('utf-8')
code_challenge = code_challenge.replace('=', '')
code_challenge, len(code_challenge)

return OAuth2Impl(
hass,
Expand Down
7 changes: 5 additions & 2 deletions custom_components/postnl/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@


class PostNLCoordinator(DataUpdateCoordinator):
graphq_api: PostNLGraphql
jouw_api: PostNLJouwAPI

data: dict[str, list[Package]]

def __init__(self, hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -55,7 +58,7 @@ async def _async_update_data(self) -> dict[str, tuple[Package]]:

return data
except requests.exceptions.RequestException as exception:
raise UpdateFailed(f"Unable to update PostNL data") from exception
raise UpdateFailed("Unable to update PostNL data") from exception

async def transform_shipment(self, shipment) -> Package:
_LOGGER.debug('Updating %s', shipment.get('key'))
Expand Down Expand Up @@ -120,4 +123,4 @@ async def transform_shipment(self, shipment) -> Package:
expected_datetime=expected_datetime
)
except requests.exceptions.RequestException as exception:
raise UpdateFailed(f"Unable to update PostNL data") from exception
raise UpdateFailed("Unable to update PostNL data") from exception
2 changes: 0 additions & 2 deletions custom_components/postnl/graphql.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logging

import requests
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
from graphql import DocumentNode

_LOGGER = logging.getLogger(__name__)

Expand Down

0 comments on commit 6fa9a91

Please sign in to comment.