mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
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
This commit is contained in:
parent
eee2b2d543
commit
c5ca431894
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user