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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type hints in apple_tv media player #77940

Merged
merged 8 commits into from Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -64,6 +64,7 @@ omit =
homeassistant/components/anthemav/media_player.py
homeassistant/components/apcupsd/*
homeassistant/components/apple_tv/__init__.py
homeassistant/components/apple_tv/browse_media.py
homeassistant/components/apple_tv/media_player.py
homeassistant/components/apple_tv/remote.py
homeassistant/components/aqualogic/*
Expand Down
29 changes: 12 additions & 17 deletions homeassistant/components/apple_tv/browse_media.py
@@ -1,43 +1,38 @@
"""Support for media browsing."""
from typing import Any

from homeassistant.components.media_player import BrowseMedia
from homeassistant.components.media_player.const import (
MEDIA_CLASS_APP,
MEDIA_CLASS_DIRECTORY,
MEDIA_TYPE_APP,
MEDIA_TYPE_APPS,
)
from homeassistant.components.media_player import BrowseMedia, MediaClass, MediaType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like MediaClass isn't imported in media_player.__init__.

Copy link
Contributor Author

@epenet epenet Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to rebase over the cast PR. Since that PR is delayed I have added it here (shouldn't cause a conflict).



def build_app_list(app_list):
def build_app_list(app_list: dict[str, str]) -> BrowseMedia:
"""Create response payload for app list."""
app_list = [
{"app_id": app_id, "title": app_name, "type": MEDIA_TYPE_APP}
media_list = [
{"app_id": app_id, "title": app_name, "type": MediaType.APP}
for app_name, app_id in app_list.items()
]

return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_class=MediaClass.DIRECTORY,
media_content_id="apps",
media_content_type=MEDIA_TYPE_APPS,
media_content_type=MediaType.APPS,
title="Apps",
can_play=False,
can_expand=True,
children=[item_payload(item) for item in app_list],
children_media_class=MEDIA_CLASS_APP,
children=[item_payload(item) for item in media_list],
children_media_class=MediaClass.APP,
)


def item_payload(item):
def item_payload(item: dict[str, Any]) -> BrowseMedia:
"""
Create response payload for a single media item.

Used by async_browse_media.
"""
return BrowseMedia(
title=item["title"],
media_class=MEDIA_CLASS_APP,
media_content_type=MEDIA_TYPE_APP,
media_class=MediaClass.APP,
media_content_type=MediaType.APP,
media_content_id=item["app_id"],
can_play=False,
can_expand=False,
Expand Down