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)