mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 07:05:48 +01:00
Add labels to Transmission add_torrent service and events (#159781)
This commit is contained in:
@@ -39,6 +39,7 @@ DEFAULT_SCAN_INTERVAL = 120
|
||||
STATE_ATTR_TORRENT_INFO = "torrent_info"
|
||||
|
||||
ATTR_DELETE_DATA = "delete_data"
|
||||
ATTR_LABELS = "labels"
|
||||
ATTR_TORRENT = "torrent"
|
||||
ATTR_TORRENTS = "torrents"
|
||||
ATTR_DOWNLOAD_PATH = "download_path"
|
||||
|
||||
@@ -112,6 +112,7 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]):
|
||||
"name": torrent.name,
|
||||
"id": torrent.id,
|
||||
"download_path": torrent.download_dir,
|
||||
"labels": torrent.labels,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -133,6 +134,7 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]):
|
||||
"name": torrent.name,
|
||||
"id": torrent.id,
|
||||
"download_path": torrent.download_dir,
|
||||
"labels": torrent.labels,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -150,6 +152,7 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]):
|
||||
"name": torrent.name,
|
||||
"id": torrent.id,
|
||||
"download_path": torrent.download_dir,
|
||||
"labels": torrent.labels,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from homeassistant.helpers import config_validation as cv, selector
|
||||
from .const import (
|
||||
ATTR_DELETE_DATA,
|
||||
ATTR_DOWNLOAD_PATH,
|
||||
ATTR_LABELS,
|
||||
ATTR_TORRENT,
|
||||
ATTR_TORRENT_FILTER,
|
||||
ATTR_TORRENTS,
|
||||
@@ -59,6 +60,7 @@ SERVICE_ADD_TORRENT_SCHEMA = vol.All(
|
||||
{
|
||||
vol.Required(ATTR_TORRENT): cv.string,
|
||||
vol.Optional(ATTR_DOWNLOAD_PATH): cv.string,
|
||||
vol.Optional(ATTR_LABELS): cv.string,
|
||||
}
|
||||
),
|
||||
)
|
||||
@@ -120,6 +122,9 @@ async def _async_add_torrent(service: ServiceCall) -> None:
|
||||
coordinator = _get_coordinator_from_service_data(service)
|
||||
torrent: str = service.data[ATTR_TORRENT]
|
||||
download_path: str | None = service.data.get(ATTR_DOWNLOAD_PATH)
|
||||
labels: list[str] | None = (
|
||||
service.data[ATTR_LABELS].split(",") if ATTR_LABELS in service.data else None
|
||||
)
|
||||
|
||||
if not (
|
||||
torrent.startswith(("http", "ftp:", "magnet:"))
|
||||
@@ -130,12 +135,14 @@ async def _async_add_torrent(service: ServiceCall) -> None:
|
||||
translation_key="could_not_add_torrent",
|
||||
)
|
||||
|
||||
if download_path:
|
||||
await service.hass.async_add_executor_job(
|
||||
partial(coordinator.api.add_torrent, torrent, download_dir=download_path)
|
||||
await service.hass.async_add_executor_job(
|
||||
partial(
|
||||
coordinator.api.add_torrent,
|
||||
torrent,
|
||||
labels=labels,
|
||||
download_dir=download_path,
|
||||
)
|
||||
else:
|
||||
await service.hass.async_add_executor_job(coordinator.api.add_torrent, torrent)
|
||||
)
|
||||
await coordinator.async_request_refresh()
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ add_torrent:
|
||||
example: "/path/to/download/directory"
|
||||
selector:
|
||||
text:
|
||||
labels:
|
||||
required: false
|
||||
example: "Notify,Remove"
|
||||
selector:
|
||||
text:
|
||||
|
||||
get_torrents:
|
||||
fields:
|
||||
|
||||
@@ -143,6 +143,10 @@
|
||||
"description": "ID of the config entry to use.",
|
||||
"name": "Transmission entry"
|
||||
},
|
||||
"labels": {
|
||||
"description": "Optional comma-separated list of labels to assign to the torrent.",
|
||||
"name": "Labels"
|
||||
},
|
||||
"torrent": {
|
||||
"description": "URL, magnet link or Base64 encoded file.",
|
||||
"name": "Torrent"
|
||||
|
||||
@@ -7,6 +7,7 @@ import pytest
|
||||
from homeassistant.components.transmission.const import (
|
||||
ATTR_DELETE_DATA,
|
||||
ATTR_DOWNLOAD_PATH,
|
||||
ATTR_LABELS,
|
||||
ATTR_TORRENT,
|
||||
ATTR_TORRENT_FILTER,
|
||||
ATTR_TORRENTS,
|
||||
@@ -76,32 +77,48 @@ async def test_service_integration_not_found(
|
||||
("payload", "expected_torrent", "kwargs"),
|
||||
[
|
||||
(
|
||||
{ATTR_TORRENT: "magnet:?xt=urn:btih:test"},
|
||||
{ATTR_TORRENT: "magnet:?xt=urn:btih:test", ATTR_LABELS: "Notify"},
|
||||
"magnet:?xt=urn:btih:test",
|
||||
{},
|
||||
{
|
||||
"labels": ["Notify"],
|
||||
"download_dir": None,
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
ATTR_TORRENT: "magnet:?xt=urn:btih:test",
|
||||
ATTR_LABELS: "Movies,Notify",
|
||||
ATTR_DOWNLOAD_PATH: "/custom/path",
|
||||
},
|
||||
"magnet:?xt=urn:btih:test",
|
||||
{"download_dir": "/custom/path"},
|
||||
{
|
||||
"labels": ["Movies", "Notify"],
|
||||
"download_dir": "/custom/path",
|
||||
},
|
||||
),
|
||||
(
|
||||
{ATTR_TORRENT: "http://example.com/test.torrent"},
|
||||
"http://example.com/test.torrent",
|
||||
{},
|
||||
{
|
||||
"labels": None,
|
||||
"download_dir": None,
|
||||
},
|
||||
),
|
||||
(
|
||||
{ATTR_TORRENT: "ftp://example.com/test.torrent"},
|
||||
"ftp://example.com/test.torrent",
|
||||
{},
|
||||
{
|
||||
"labels": None,
|
||||
"download_dir": None,
|
||||
},
|
||||
),
|
||||
(
|
||||
{ATTR_TORRENT: "/config/test.torrent"},
|
||||
"/config/test.torrent",
|
||||
{},
|
||||
{
|
||||
"labels": None,
|
||||
"download_dir": None,
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user