Add add_torrent service to Transmission (#25144)
* 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:
parent
0be2dad651
commit
797196dce9
2 changed files with 27 additions and 0 deletions
homeassistant/components/transmission
|
@ -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]}
|
||||
|
|
6
homeassistant/components/transmission/services.yaml
Normal file
6
homeassistant/components/transmission/services.yaml
Normal 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}
|
Loading…
Add table
Reference in a new issue