From 2641e44f3ea567df2802e8bc67d4e4098e4e76df Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Sun, 12 Jan 2020 11:17:31 +0100 Subject: [PATCH] Improve type information Most parameters to Client's __init__ are optional. This matters when adding more types other places. --- wideq/client.py | 13 ++++++++----- wideq/core.py | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/wideq/client.py b/wideq/client.py index 2702808..31e43d0 100644 --- a/wideq/client.py +++ b/wideq/client.py @@ -25,7 +25,7 @@ class Monitor(object): makes one `Monitor` object suitable for long-term monitoring. """ - def __init__(self, session, device_id) -> None: + def __init__(self, session: core.Session, device_id: str) -> None: self.session = session self.device_id = device_id @@ -75,13 +75,16 @@ class Client(object): and allows serialization of state. """ - def __init__(self, gateway=None, auth=None, session=None, + def __init__(self, + gateway: Optional[core.Gateway] = None, + auth: Optional[core.Auth] = None, + session: Optional[core.Session] = None, country: str = DEFAULT_COUNTRY, language: str = DEFAULT_LANGUAGE) -> None: # The three steps required to get access to call the API. - self._gateway: core.Gateway = gateway - self._auth: core.Auth = auth - self._session: core.Session = session + self._gateway: Optional[core.Gateway] = gateway + self._auth: Optional[core.Auth] = auth + self._session: Optional[core.Session] = session # The last list of devices we got from the server. This is the # raw JSON list data describing the devices. diff --git a/wideq/core.py b/wideq/core.py index 2151935..5f2ed1c 100644 --- a/wideq/core.py +++ b/wideq/core.py @@ -7,7 +7,7 @@ import hashlib import hmac import datetime import requests -from typing import Any, Dict, List +from typing import Any, Dict, List, Tuple GATEWAY_URL = 'https://kic.lgthinq.com:46030/api/common/gatewayUriList' APP_KEY = 'wideq' @@ -252,7 +252,7 @@ class Gateway(object): self.language = language @classmethod - def discover(cls, country, language): + def discover(cls, country, language) -> 'Gateway': gw = gateway_info(country, language) return cls(gw['empUri'], gw['thinqUri'], gw['oauthUri'], country, language) @@ -275,7 +275,7 @@ class Auth(object): access_token, refresh_token = parse_oauth_callback(url) return cls(gateway, access_token, refresh_token) - def start_session(self): + def start_session(self) -> Tuple['Session', List[Dict[str, Any]]]: """Start an API session for the logged-in user. Return the Session object and a list of the user's devices. """