1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-16 23:30:10 -07:00

Improve type information

Most parameters to Client's __init__ are optional.
This matters when adding more types other places.
This commit is contained in:
Frederik Gladhorn 2020-01-12 11:17:31 +01:00
parent a72998386c
commit 2641e44f3e
2 changed files with 11 additions and 8 deletions

View File

@ -25,7 +25,7 @@ class Monitor(object):
makes one `Monitor` object suitable for long-term monitoring. 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.session = session
self.device_id = device_id self.device_id = device_id
@ -75,13 +75,16 @@ class Client(object):
and allows serialization of state. 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, country: str = DEFAULT_COUNTRY,
language: str = DEFAULT_LANGUAGE) -> None: language: str = DEFAULT_LANGUAGE) -> None:
# The three steps required to get access to call the API. # The three steps required to get access to call the API.
self._gateway: core.Gateway = gateway self._gateway: Optional[core.Gateway] = gateway
self._auth: core.Auth = auth self._auth: Optional[core.Auth] = auth
self._session: core.Session = session self._session: Optional[core.Session] = session
# The last list of devices we got from the server. This is the # The last list of devices we got from the server. This is the
# raw JSON list data describing the devices. # raw JSON list data describing the devices.

View File

@ -7,7 +7,7 @@ import hashlib
import hmac import hmac
import datetime import datetime
import requests 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' GATEWAY_URL = 'https://kic.lgthinq.com:46030/api/common/gatewayUriList'
APP_KEY = 'wideq' APP_KEY = 'wideq'
@ -252,7 +252,7 @@ class Gateway(object):
self.language = language self.language = language
@classmethod @classmethod
def discover(cls, country, language): def discover(cls, country, language) -> 'Gateway':
gw = gateway_info(country, language) gw = gateway_info(country, language)
return cls(gw['empUri'], gw['thinqUri'], gw['oauthUri'], return cls(gw['empUri'], gw['thinqUri'], gw['oauthUri'],
country, language) country, language)
@ -275,7 +275,7 @@ class Auth(object):
access_token, refresh_token = parse_oauth_callback(url) access_token, refresh_token = parse_oauth_callback(url)
return cls(gateway, access_token, refresh_token) 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 """Start an API session for the logged-in user. Return the
Session object and a list of the user's devices. Session object and a list of the user's devices.
""" """