Пример #1
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """ Sets up the SABnzbd sensors. """
    from pysabnzbd import SabnzbdApi, SabnzbdApiException

    api_key = config.get("api_key")
    base_url = config.get("base_url")
    name = config.get("name", "SABnzbd")
    if not base_url:
        _LOGGER.error('Missing config variable base_url')
        return False
    if not api_key:
        _LOGGER.error('Missing config variable api_key')
        return False

    sab_api = SabnzbdApi(base_url, api_key)

    try:
        sab_api.check_available()
    except SabnzbdApiException:
        _LOGGER.exception("Connection to SABnzbd API failed.")
        return False

    # pylint: disable=global-statement
    global _THROTTLED_REFRESH
    _THROTTLED_REFRESH = Throttle(timedelta(seconds=1))(sab_api.refresh_queue)

    dev = []
    for variable in config['monitored_variables']:
        if variable['type'] not in SENSOR_TYPES:
            _LOGGER.error('Sensor type: "%s" does not exist', variable['type'])
        else:
            dev.append(SabnzbdSensor(variable['type'], sab_api, name))

    add_devices(dev)
Пример #2
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the SABnzbd sensors."""
    from pysabnzbd import SabnzbdApi, SabnzbdApiException

    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)
    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)

    sab_api = SabnzbdApi(base_url, api_key)

    try:
        sab_api.check_available()
    except SabnzbdApiException:
        _LOGGER.exception("Connection to SABnzbd API failed")
        return False

    # pylint: disable=global-statement
    global _THROTTLED_REFRESH
    _THROTTLED_REFRESH = Throttle(MIN_TIME_BETWEEN_UPDATES)(
        sab_api.refresh_queue)

    devices = []
    for variable in monitored_types:
        devices.append(SabnzbdSensor(variable, sab_api, name))

    add_devices(devices)
Пример #3
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the SABnzbd sensors."""
    from pysabnzbd import SabnzbdApi, SabnzbdApiException

    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)
    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)

    sab_api = SabnzbdApi(base_url, api_key)

    try:
        sab_api.check_available()
    except SabnzbdApiException:
        _LOGGER.exception("Connection to SABnzbd API failed")
        return False

    # pylint: disable=global-statement
    global _THROTTLED_REFRESH
    _THROTTLED_REFRESH = Throttle(
        MIN_TIME_BETWEEN_UPDATES)(sab_api.refresh_queue)

    devices = []
    for variable in monitored_types:
        devices.append(SabnzbdSensor(variable, sab_api, name))

    add_devices(devices)