From c5ca43189402adb78709631f1dd37e48b020edd1 Mon Sep 17 00:00:00 2001 From: Chris Thornton <54046872+cj-thornton@users.noreply.github.com> Date: Tue, 20 Aug 2019 10:01:19 +0000 Subject: [PATCH] Add path option to SABnzbd component (#25908) * Add path option to SABnzbd component Adds an optional `path` setting to the SABnzbd component. This allows support for SABnzbd installs that use a different `url_base` (typically a reverse proxied configuration; see https://sabnzbd.org/wiki/configuration/2.3/special). This change passes the `path` along to pysabnzbd as its `web_root`, which in turn uses the path to build up it's api URLs. * Use dict.get for Sabnzbd web_root path config --- homeassistant/components/sabnzbd/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sabnzbd/__init__.py b/homeassistant/components/sabnzbd/__init__.py index f5870e42490..bf5e90e21f1 100644 --- a/homeassistant/components/sabnzbd/__init__.py +++ b/homeassistant/components/sabnzbd/__init__.py @@ -10,6 +10,7 @@ from homeassistant.const import ( CONF_HOST, CONF_API_KEY, CONF_NAME, + CONF_PATH, CONF_PORT, CONF_SENSORS, CONF_SSL, @@ -69,6 +70,7 @@ CONFIG_SCHEMA = vol.Schema( { vol.Required(CONF_API_KEY): cv.string, vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string, + vol.Optional(CONF_PATH): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Optional(CONF_SENSORS): vol.All( @@ -102,17 +104,20 @@ async def async_configure_sabnzbd( host = config[CONF_HOST] port = config[CONF_PORT] + web_root = config.get(CONF_PATH) uri_scheme = "https" if use_ssl else "http" base_url = BASE_URL_FORMAT.format(uri_scheme, host, port) if api_key is None: conf = await hass.async_add_job(load_json, hass.config.path(CONFIG_FILE)) api_key = conf.get(base_url, {}).get(CONF_API_KEY, "") - sab_api = SabnzbdApi(base_url, api_key, session=async_get_clientsession(hass)) + sab_api = SabnzbdApi( + base_url, api_key, web_root=web_root, session=async_get_clientsession(hass) + ) if await async_check_sabnzbd(sab_api): async_setup_sabnzbd(hass, sab_api, config, name) else: - async_request_configuration(hass, config, base_url) + async_request_configuration(hass, config, base_url, web_root) async def async_setup(hass, config): @@ -181,7 +186,7 @@ def async_setup_sabnzbd(hass, sab_api, config, name): @callback -def async_request_configuration(hass, config, host): +def async_request_configuration(hass, config, host, web_root): """Request configuration steps from the user.""" from pysabnzbd import SabnzbdApi @@ -197,7 +202,9 @@ def async_request_configuration(hass, config, host): async def async_configuration_callback(data): """Handle configuration changes.""" api_key = data.get(CONF_API_KEY) - sab_api = SabnzbdApi(host, api_key, session=async_get_clientsession(hass)) + sab_api = SabnzbdApi( + host, api_key, web_root=web_root, session=async_get_clientsession(hass) + ) if not await async_check_sabnzbd(sab_api): return