-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Improve typing in plex services #87078
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
Merged
+16
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| ) | ||
| from .errors import MediaNotFound | ||
| from .models import PlexMediaSearchResult | ||
| from .server import PlexServer | ||
|
|
||
| REFRESH_LIBRARY_SCHEMA = vol.Schema( | ||
| {vol.Optional("server_name"): str, vol.Required("library_name"): str} | ||
|
|
@@ -28,7 +29,7 @@ | |
| _LOGGER = logging.getLogger(__package__) | ||
|
|
||
|
|
||
| async def async_setup_services(hass): | ||
| async def async_setup_services(hass: HomeAssistant) -> None: | ||
| """Set up services for the Plex component.""" | ||
|
|
||
| async def async_refresh_library_service(service_call: ServiceCall) -> None: | ||
|
|
@@ -53,8 +54,6 @@ async def async_scan_clients_service(_: ServiceCall) -> None: | |
| DOMAIN, SERVICE_SCAN_CLIENTS, async_scan_clients_service | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| def refresh_library(hass: HomeAssistant, service_call: ServiceCall) -> None: | ||
| """Scan a Plex library for new and updated media.""" | ||
|
|
@@ -77,17 +76,22 @@ def refresh_library(hass: HomeAssistant, service_call: ServiceCall) -> None: | |
| library.update() | ||
|
|
||
|
|
||
| def get_plex_server(hass, plex_server_name=None, plex_server_id=None): | ||
| def get_plex_server( | ||
| hass: HomeAssistant, | ||
| plex_server_name: str | None = None, | ||
| plex_server_id: str | None = None, | ||
| ) -> PlexServer: | ||
| """Retrieve a configured Plex server by name.""" | ||
| if DOMAIN not in hass.data: | ||
| raise HomeAssistantError("Plex integration not configured") | ||
| plex_servers = hass.data[DOMAIN][SERVERS].values() | ||
| if not plex_servers: | ||
| servers: dict[str, PlexServer] = hass.data[DOMAIN][SERVERS] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small change here to first get the full dict, and only get the |
||
| if not servers: | ||
| raise HomeAssistantError("No Plex servers available") | ||
|
|
||
| if plex_server_id: | ||
| return hass.data[DOMAIN][SERVERS][plex_server_id] | ||
| return servers[plex_server_id] | ||
|
|
||
| plex_servers = servers.values() | ||
| if plex_server_name: | ||
| plex_server = next( | ||
| (x for x in plex_servers if x.friendly_name == plex_server_name), None | ||
|
|
@@ -110,7 +114,11 @@ def get_plex_server(hass, plex_server_name=None, plex_server_id=None): | |
|
|
||
|
|
||
| def process_plex_payload( | ||
| hass, content_type, content_id, default_plex_server=None, supports_playqueues=True | ||
| hass: HomeAssistant, | ||
| content_type: str, | ||
| content_id: str, | ||
| default_plex_server: PlexServer | None = None, | ||
| supports_playqueues: bool = True, | ||
| ) -> PlexMediaSearchResult: | ||
| """Look up Plex media using media_player.play_media service payloads.""" | ||
| plex_server = default_plex_server | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value was always
True, and never checked.I think it is cleaner to drop the return value.