From 97166fddb326686fc50d4c44d4495cbe563f9acb Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Sun, 6 Oct 2024 17:47:53 -0600 Subject: [PATCH 1/2] Fix mypy errors --- vivintpy/vivintskyapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vivintpy/vivintskyapi.py b/vivintpy/vivintskyapi.py index 79012a2..8cce5d9 100644 --- a/vivintpy/vivintskyapi.py +++ b/vivintpy/vivintskyapi.py @@ -91,7 +91,7 @@ async def disconnect(self) -> None: async def verify_mfa(self, code: str) -> None: """Verify multi-factor authentication code.""" self.__mfa_pending = False - endpoint = f"{AUTH_ENDPOINT}/idp/api/{"validate" if self.__mfa_type == "code" else "submit"}" + endpoint = f'{AUTH_ENDPOINT}/idp/api/{"validate" if self.__mfa_type == "code" else "submit"}' resp = await self.__post( endpoint, params={"client_id": "ios"}, From 5cfc85027882cb27e6bfe1aae54c644a70b8b3ae Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Sun, 6 Oct 2024 17:59:40 -0600 Subject: [PATCH 2/2] More fixes --- vivintpy/entity.py | 4 ---- vivintpy/utils.py | 4 ++-- vivintpy/vivintskyapi.py | 5 +++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/vivintpy/entity.py b/vivintpy/entity.py index aaf80b5..5e3974d 100644 --- a/vivintpy/entity.py +++ b/vivintpy/entity.py @@ -2,11 +2,8 @@ from __future__ import annotations -import logging from collections.abc import Callable -_LOGGER = logging.getLogger(__name__) - UPDATE = "update" @@ -34,7 +31,6 @@ def update_data(self, new_val: dict, override: bool = False) -> None: def handle_pubnub_message(self, message: dict) -> None: """Handle a pubnub message directed to this entity.""" - _LOGGER.debug("Message received by %s: %s", self.name, message) self.update_data(message) def on( # pylint: disable=invalid-name diff --git a/vivintpy/utils.py b/vivintpy/utils.py index e431456..06ad183 100644 --- a/vivintpy/utils.py +++ b/vivintpy/utils.py @@ -55,8 +55,8 @@ def generate_code_challenge() -> tuple[str, str]: code_verifier = base64.urlsafe_b64encode(os.urandom(40)).decode("utf-8") code_verifier = re.sub("[^a-zA-Z0-9]+", "", code_verifier) - code_challenge = hashlib.sha256(code_verifier.encode("utf-8")).digest() - code_challenge = base64.urlsafe_b64encode(code_challenge).decode("utf-8") + code_hash = hashlib.sha256(code_verifier.encode("utf-8")).digest() + code_challenge = base64.urlsafe_b64encode(code_hash).decode("utf-8") code_challenge = code_challenge.replace("=", "") return (code_verifier, code_challenge) diff --git a/vivintpy/vivintskyapi.py b/vivintpy/vivintskyapi.py index 8cce5d9..7d1d24d 100644 --- a/vivintpy/vivintskyapi.py +++ b/vivintpy/vivintskyapi.py @@ -77,6 +77,7 @@ def is_session_valid(self) -> bool: async def connect(self) -> dict: """Connect to VivintSky Cloud Service.""" if not (self.__has_custom_client_session and self.is_session_valid()): + assert self.__password await self.__get_vivintsky_session(self.__username, self.__password) authuser_data = await self.get_authuser_data() if not authuser_data: @@ -105,6 +106,7 @@ async def verify_mfa(self, code: str) -> None: ) if resp and "url" in resp: resp = await self.__get(path=f"{AUTH_ENDPOINT}{resp['url']}") + assert resp if "location" in resp: query = urllib.parse.urlparse(resp["location"]).query @@ -501,6 +503,7 @@ async def __get_vivintsky_session(self, username: str, password: str) -> None: }, allow_redirects=False, ) + assert resp if "location" in resp and redirect_uri in resp["location"]: query = urllib.parse.urlparse(resp["location"]).query @@ -517,6 +520,7 @@ async def __get_vivintsky_session(self, username: str, password: str) -> None: }, data=json.dumps({"username": username, "password": password}), ) + assert resp # Check for TOTP/MFA requirement if "validate" in resp: @@ -648,6 +652,7 @@ async def _send_grpc( ) -> None: """Send gRPC.""" assert self.is_session_valid() + assert self.__token creds = grpc.ssl_channel_credentials() async with grpc.aio.secure_channel(GRPC_ENDPOINT, credentials=creds) as channel: