parent
09b53a0d55
commit
0198ba4eac
1 changed files with 14 additions and 4 deletions
|
@ -11,7 +11,8 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_API_KEY, CONF_NAME, CONF_PORT, CONF_MONITORED_VARIABLES)
|
||||
CONF_HOST, CONF_API_KEY, CONF_NAME, CONF_PORT, CONF_MONITORED_VARIABLES,
|
||||
CONF_SSL)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -25,6 +26,7 @@ _THROTTLED_REFRESH = None
|
|||
|
||||
DEFAULT_NAME = 'SABnzbd'
|
||||
DEFAULT_PORT = 8080
|
||||
DEFAULT_SSL = False
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=1)
|
||||
|
||||
|
@ -44,10 +46,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
|
||||
})
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
# pylint: disable=unused-argument, too-many-locals
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the SABnzbd sensors."""
|
||||
from pysabnzbd import SabnzbdApi, SabnzbdApiException
|
||||
|
@ -57,14 +60,21 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
name = config.get(CONF_NAME)
|
||||
api_key = config.get(CONF_API_KEY)
|
||||
monitored_types = config.get(CONF_MONITORED_VARIABLES)
|
||||
base_url = "http://{}:{}/".format(host, port)
|
||||
use_ssl = config.get(CONF_SSL)
|
||||
|
||||
if use_ssl:
|
||||
uri_scheme = 'https://'
|
||||
else:
|
||||
uri_scheme = 'http://'
|
||||
|
||||
base_url = "{}{}:{}/".format(uri_scheme, host, port)
|
||||
|
||||
sab_api = SabnzbdApi(base_url, api_key)
|
||||
|
||||
try:
|
||||
sab_api.check_available()
|
||||
except SabnzbdApiException:
|
||||
_LOGGER.exception("Connection to SABnzbd API failed")
|
||||
_LOGGER.error("Connection to SABnzbd API failed")
|
||||
return False
|
||||
|
||||
# pylint: disable=global-statement
|
||||
|
|
Loading…
Add table
Reference in a new issue