Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type annotations to config.py #791

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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