-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add Transmission get_torrents service and codeowner #159211
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
joostlek
merged 5 commits into
home-assistant:dev
from
andrew-codechimp:transmission-get-torrents
Dec 23, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4354c09
Add get_torrents service and me as codeowner
andrew-codechimp 7b30af8
Remove if from test
andrew-codechimp b9ceb23
Remove misleading explanations
andrew-codechimp 4ddf309
Update homeassistant/components/transmission/strings.json
andrew-codechimp 29c2580
Add assert that torrents are in filter
andrew-codechimp 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Helper functions for Transmission.""" | ||
|
|
||
| from typing import Any | ||
|
|
||
| from transmission_rpc.torrent import Torrent | ||
|
|
||
|
|
||
| def format_torrent(torrent: Torrent) -> dict[str, Any]: | ||
| """Format a single torrent.""" | ||
| value: dict[str, Any] = {} | ||
|
|
||
| value["id"] = torrent.id | ||
| value["name"] = torrent.name | ||
| value["status"] = torrent.status.value | ||
| value["percent_done"] = f"{torrent.percent_done * 100:.2f}%" | ||
| value["ratio"] = f"{torrent.ratio:.2f}" | ||
| value["eta"] = str(torrent.eta) if torrent.eta else None | ||
| value["added_date"] = torrent.added_date.isoformat() | ||
| value["done_date"] = torrent.done_date.isoformat() if torrent.done_date else None | ||
| value["download_dir"] = torrent.download_dir | ||
| value["labels"] = torrent.labels | ||
|
|
||
| return value | ||
|
|
||
|
|
||
| def filter_torrents( | ||
| torrents: list[Torrent], statuses: list[str] | None = None | ||
| ) -> list[Torrent]: | ||
| """Filter torrents based on the statuses provided.""" | ||
| return [ | ||
| torrent | ||
| for torrent in torrents | ||
| if statuses is None or torrent.status in statuses | ||
| ] | ||
|
|
||
|
|
||
| def format_torrents( | ||
| torrents: list[Torrent], | ||
| ) -> dict[str, dict[str, Any]]: | ||
| """Format a list of torrents.""" | ||
| value = {} | ||
| for torrent in torrents: | ||
| value[torrent.name] = format_torrent(torrent) | ||
|
|
||
| return value | ||
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
This function lacks a docstring explaining the purpose of formatting, the structure of the returned dictionary, or the meaning of fields like 'status.value'. Consider adding a detailed docstring that describes the returned data structure and field types.
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm not sure a docstring would add much.