From 6fa9a919755184b0ba0e1553de45c6181875c136 Mon Sep 17 00:00:00 2001 From: Arjen Bos <1064589+arjenbos@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:24:16 +0100 Subject: [PATCH] Clean up some code --- custom_components/postnl/__init__.py | 6 +++--- custom_components/postnl/application_credentials.py | 2 -- custom_components/postnl/coordinator.py | 7 +++++-- custom_components/postnl/graphql.py | 2 -- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/custom_components/postnl/__init__.py b/custom_components/postnl/__init__.py index 225abd0..a0e914c 100644 --- a/custom_components/postnl/__init__.py +++ b/custom_components/postnl/__init__.py @@ -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 @@ -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) diff --git a/custom_components/postnl/application_credentials.py b/custom_components/postnl/application_credentials.py index 86cfa77..d751a5b 100644 --- a/custom_components/postnl/application_credentials.py +++ b/custom_components/postnl/application_credentials.py @@ -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, diff --git a/custom_components/postnl/coordinator.py b/custom_components/postnl/coordinator.py index 9a6fa8f..0c6076d 100644 --- a/custom_components/postnl/coordinator.py +++ b/custom_components/postnl/coordinator.py @@ -16,6 +16,9 @@ class PostNLCoordinator(DataUpdateCoordinator): + graphq_api: PostNLGraphql + jouw_api: PostNLJouwAPI + data: dict[str, list[Package]] def __init__(self, hass: HomeAssistant) -> None: @@ -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')) @@ -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 diff --git a/custom_components/postnl/graphql.py b/custom_components/postnl/graphql.py index 28395b7..533cb1a 100644 --- a/custom_components/postnl/graphql.py +++ b/custom_components/postnl/graphql.py @@ -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__)