Skip to content

Commit

Permalink
Merge pull request #199 from natekspencer/dev
Browse files Browse the repository at this point in the history
Fix mypy errors
  • Loading branch information
natekspencer authored Oct 7, 2024
2 parents 465e51b + 5cfc850 commit cd25fdc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 0 additions & 4 deletions vivintpy/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

from __future__ import annotations

import logging
from collections.abc import Callable

_LOGGER = logging.getLogger(__name__)

UPDATE = "update"


Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vivintpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion vivintpy/vivintskyapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -91,7 +92,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"},
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit cd25fdc

Please sign in to comment.