Add add_torrent service to Transmission ()

* Add add_torrent service to Transmission

* Fix services.yaml format

* Verify that torrent is whitelisted

* Add logging if adding failed

* Change warn to warning
This commit is contained in:
Pierre Ståhl 2019-07-21 22:31:11 +02:00 committed by Pascal Vizeli
parent 0be2dad651
commit 797196dce9
2 changed files with 27 additions and 0 deletions
homeassistant/components/transmission

View file

@ -34,6 +34,14 @@ SENSOR_TYPES = {
DEFAULT_SCAN_INTERVAL = timedelta(seconds=120)
ATTR_TORRENT = 'torrent'
SERVICE_ADD_TORRENT = 'add_torrent'
SERVICE_ADD_TORRENT_SCHEMA = vol.Schema({
vol.Required(ATTR_TORRENT): cv.string,
})
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
@ -82,6 +90,19 @@ def setup(hass, config):
track_time_interval(hass, refresh, scan_interval)
def add_torrent(service):
"""Add new torrent to download."""
torrent = service.data[ATTR_TORRENT]
if torrent.startswith(('http', 'ftp:', 'magnet:')) or \
hass.config.is_allowed_path(torrent):
api.add_torrent(torrent)
else:
_LOGGER.warning('Could not add torrent: '
'unsupported type or no permission')
hass.services.register(DOMAIN, SERVICE_ADD_TORRENT, add_torrent,
schema=SERVICE_ADD_TORRENT_SCHEMA)
sensorconfig = {
'sensors': config[DOMAIN][CONF_MONITORED_CONDITIONS],
'client_name': config[DOMAIN][CONF_NAME]}

View file

@ -0,0 +1,6 @@
add_torrent:
description: Add a new torrent to download (URL, magnet link or Base64 encoded).
fields:
torrent:
description: URL, magnet link or Base64 encoded file.
example: http://releases.ubuntu.com/19.04/ubuntu-19.04-desktop-amd64.iso.torrent}