Skip to content

Commit

Permalink
Add type annotations to config.py (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Jan 17, 2024
1 parent 6eb17e9 commit 49b8ef6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
files = pychromecast/const.py, pychromecast/error.py, pychromecast/models.py, pychromecast/response_handler.py
files = pychromecast/config.py, pychromecast/const.py, pychromecast/error.py, pychromecast/models.py, pychromecast/response_handler.py
12 changes: 8 additions & 4 deletions pychromecast/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Data and methods to retrieve app specific configuration
"""
import json
from typing import cast

import requests

Expand All @@ -22,7 +23,7 @@
APP_NRKRADIO = "A49874B1"


def get_possible_app_ids():
def get_possible_app_ids() -> list[str]:
"""Returns all possible app ids."""

try:
Expand All @@ -32,22 +33,25 @@ def get_possible_app_ids():
)
data = json.loads(req.text[4:])

return [app["app_id"] for app in data["applications"]] + data["enabled_app_ids"]
return cast(
list[str],
[app["app_id"] for app in data["applications"]] + data["enabled_app_ids"],
)

except ValueError:
# If json fails to parse
return []


def get_app_config(app_id):
def get_app_config(app_id: str) -> dict:
"""Get specific configuration for 'app_id'."""
try:
req = requests.get(
f"https://clients3.google.com/cast/chromecast/device/app?a={app_id}",
timeout=10,
)

return json.loads(req.text[4:]) if req.status_code == 200 else {}
return cast(dict, json.loads(req.text[4:])) if req.status_code == 200 else {}

except ValueError:
# If json fails to parse
Expand Down

0 comments on commit 49b8ef6

Please sign in to comment.