Skip to content

Conversation

@andrew-codechimp
Copy link
Contributor

@andrew-codechimp andrew-codechimp commented Dec 16, 2025

Proposed change

Add myself as codeowner to support new functionality.
Implement helper function to filter torrents for use in new service and also sensor entities.
Add a new get_torrents service with filters for types of torrent.
Modify sensors to use new filter function, consolidating filtering.
Add tests for new service.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @engrbm87, @JPHutchins, mind taking a look at this pull request as it has been labeled with an integration (transmission) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of transmission can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign transmission Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Comment on lines 126 to 130
"active": "Active",
"all": "All",
"completed": "Completed (Seeding)",
"paused": "Paused",
"started": "Started (Downloading)"
Copy link
Member

Choose a reason for hiding this comment

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

So I am a Qbittorrent user, but you can also have torrents where you stop seeding, but don't delete it, that would turn Completed, is that something here as well?

Copy link
Member

Choose a reason for hiding this comment

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

What does the transmission UI call it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took this from the existing sensor code so have not checked on that scenario. I'll have a look and see if this was correct.

MODES: dict[str, list[str] | None] = {
    "started_torrents": ["downloading"],
    "completed_torrents": ["seeding"],
    "paused_torrents": ["stopped"],
    "active_torrents": [
        "seeding",
        "downloading",
    ],
    "total_torrents": None,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Completed but not seeding torrents currently go into Paused torrents
The current sensors do not total in the same categories as the latest Transmission Flood UI.
Whether historically they did match I'm not sure.
I would prefer to keep the service the same as the sensors, so I have removed the misleading explanations in brackets.
Changing the sensor total methods would introduce a potential breaking change to automations.

CleanShot 2025-12-16 at 16 08 34@2x CleanShot 2025-12-16 at 16 08 46@2x

Copy link
Member

Choose a reason for hiding this comment

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

I would expect the 2 also to show in the seeding category lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 2 here are completed but not seeding, hence stopped/paused depending on transmission/integration terminology.
The totals have always been confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've compared two of the UI's (there's 4 at least) and they all seem to take a different view on how to total things, the API doesn't give totals and it's left to UI implementation to decide what's right, some UI's give more granular totals than others.

This integration is consistent between the sensors and the new action, I don't think there's a right/wrong way to implement this so think this is resolved.

@andrew-codechimp andrew-codechimp marked this pull request as ready for review December 16, 2025 16:22
Copilot AI review requested due to automatic review settings December 16, 2025 16:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new get_torrents service to the Transmission integration and adds @andrew-codechimp as a codeowner. The service allows users to retrieve current torrents with various filtering options (all, active, started, completed, paused). The changes also refactor torrent filtering logic into a shared helper module.

  • Implements a new get_torrents service with filter options
  • Refactors torrent filtering logic into reusable helper functions
  • Updates sensor entities to use the new shared filtering helpers

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/components/transmission/test_services.py Adds comprehensive tests for the new get_torrents service with various filter modes
tests/components/transmission/conftest.py Updates mock_torrent fixture to include additional fields required for new service
homeassistant/components/transmission/strings.json Adds UI strings for torrent filter options and get_torrents service description
homeassistant/components/transmission/services.yaml Defines service schema for get_torrents with filter selector
homeassistant/components/transmission/services.py Implements get_torrents service logic and registers it with Home Assistant
homeassistant/components/transmission/sensor.py Refactors sensor entities to use new shared filter_torrents helper function
homeassistant/components/transmission/manifest.json Adds @andrew-codechimp to codeowners list
homeassistant/components/transmission/icons.json Adds icon for get_torrents service
homeassistant/components/transmission/helpers.py New module containing shared helper functions for filtering and formatting torrents
homeassistant/components/transmission/const.py Adds constants for new service and moves FILTER_MODES to shared location
CODEOWNERS Updates Transmission component codeowner entries

Comment on lines +8 to +23
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
Copy link

Copilot AI Dec 16, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@andrew-codechimp andrew-codechimp Dec 16, 2025

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.

andrew-codechimp and others added 2 commits December 16, 2025 16:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@joostlek joostlek merged commit af12188 into home-assistant:dev Dec 23, 2025
36 checks passed
@andrew-codechimp andrew-codechimp deleted the transmission-get-torrents branch December 24, 2025 14:26
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants