Add Transmission component 'scan_interval' option (#20575)
* Transmission component fix 'scan_interval' option * Fix dict[key] comments * Fix latest messpull/20930/head
parent
b5e40669c9
commit
21583d25e2
|
@ -4,10 +4,12 @@ Support for monitoring the Transmission BitTorrent client API.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.transmission/
|
||||
"""
|
||||
from datetime import timedelta
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.transmission import (
|
||||
DATA_TRANSMISSION, SENSOR_TYPES, SCAN_INTERVAL)
|
||||
DATA_TRANSMISSION, SENSOR_TYPES)
|
||||
from homeassistant.const import STATE_IDLE
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -18,6 +20,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
DEFAULT_NAME = 'Transmission'
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=120)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Transmission sensors."""
|
||||
|
|
|
@ -4,10 +4,12 @@ Support for setting the Transmission BitTorrent client Turtle Mode.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/switch.transmission/
|
||||
"""
|
||||
from datetime import timedelta
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.transmission import (
|
||||
DATA_TRANSMISSION, SCAN_INTERVAL)
|
||||
DATA_TRANSMISSION)
|
||||
from homeassistant.const import (
|
||||
STATE_OFF, STATE_ON)
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
|
@ -19,6 +21,8 @@ _LOGGING = logging.getLogger(__name__)
|
|||
|
||||
DEFAULT_NAME = 'Transmission Turtle Mode'
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=120)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Transmission switch."""
|
||||
|
|
|
@ -15,7 +15,8 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME
|
||||
CONF_USERNAME,
|
||||
CONF_SCAN_INTERVAL
|
||||
)
|
||||
from homeassistant.helpers import discovery, config_validation as cv
|
||||
from homeassistant.helpers.event import track_time_interval
|
||||
|
@ -42,6 +43,8 @@ SENSOR_TYPES = {
|
|||
'started_torrents': ['Started Torrents', None],
|
||||
}
|
||||
|
||||
DEFAULT_SCAN_INTERVAL = timedelta(seconds=120)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
|
@ -50,20 +53,21 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(TURTLE_MODE, default=False): cv.boolean,
|
||||
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL):
|
||||
cv.time_period,
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=['current_status']):
|
||||
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=2)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Transmission Component."""
|
||||
host = config[DOMAIN][CONF_HOST]
|
||||
username = config[DOMAIN][CONF_USERNAME]
|
||||
password = config[DOMAIN][CONF_PASSWORD]
|
||||
username = config[DOMAIN].get(CONF_USERNAME)
|
||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
||||
port = config[DOMAIN][CONF_PORT]
|
||||
scan_interval = config[DOMAIN][CONF_SCAN_INTERVAL]
|
||||
|
||||
import transmissionrpc
|
||||
from transmissionrpc.error import TransmissionError
|
||||
|
@ -85,7 +89,7 @@ def setup(hass, config):
|
|||
"""Get the latest data from Transmission."""
|
||||
tm_data.update()
|
||||
|
||||
track_time_interval(hass, refresh, SCAN_INTERVAL)
|
||||
track_time_interval(hass, refresh, scan_interval)
|
||||
|
||||
sensorconfig = {
|
||||
'sensors': config[DOMAIN][CONF_MONITORED_CONDITIONS],
|
||||
|
|
Loading…
Reference in New Issue