diff --git a/README.md b/README.md index 579d180..c3eeb53 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ Platform | Description ## Configuration is done in the UI +You can configure a custom gPodder server URL in the integration setup (e.g., https://gpodder.net or your self-hosted instance). + ## Contributions are welcome! If you want to contribute to this please read the [Contribution guidelines](CONTRIBUTING.md) diff --git a/custom_components/gpodder/__init__.py b/custom_components/gpodder/__init__.py index c3edc29..07ecd20 100644 --- a/custom_components/gpodder/__init__.py +++ b/custom_components/gpodder/__init__.py @@ -11,6 +11,7 @@ import podcastparser from homeassistant.exceptions import ConfigEntryNotReady from mygpoclient import api +from urllib.parse import urlparse from custom_components.gpodder.const import ( CONF_DEVICE, @@ -21,6 +22,8 @@ DOMAIN, REQUEST_HEADERS, STARTUP, + CONF_BASE_URL, + DEFAULT_BASE_URL, ) UPDATE_INTERVAL = timedelta(minutes=30) @@ -43,8 +46,11 @@ async def async_setup_entry(hass, entry): password = entry.data.get(CONF_PASSWORD) device = entry.data.get(CONF_DEVICE) name = entry.data.get(CONF_NAME) + base_url = entry.data.get(CONF_BASE_URL, DEFAULT_BASE_URL) - coordinator = GpodderDataUpdateCoordinator(hass, username, password, device, name) + coordinator = GpodderDataUpdateCoordinator( + hass, username, password, device, name, base_url + ) await coordinator.async_refresh() if not coordinator.last_update_success: @@ -119,11 +125,21 @@ def update_using_feedservice(urls): class GpodderDataUpdateCoordinator(DataUpdateCoordinator): """Class to manage fetching data from the API.""" - def __init__(self, hass, username, password, device, name): + def __init__(self, hass, username, password, device, name, base_url): """Initialize.""" self.hass = hass self.name = name - self.api = api.MygPodderClient(username, password) + # Parse base_url to derive host and SSL settings + try: + if "://" not in base_url: + base_url = f"https://{base_url}" + parsed = urlparse(base_url) + host = parsed.netloc or parsed.path + use_ssl = (parsed.scheme or "https").lower() != "http" + # Construct client with custom server and SSL preference + self.api = api.MygPodderClient(username, password, host, use_ssl) + except Exception: # Fallback to default behavior if parsing fails + self.api = api.MygPodderClient(username, password) self.device = device super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL) diff --git a/custom_components/gpodder/config_flow.py b/custom_components/gpodder/config_flow.py index 03d6221..cecb33c 100644 --- a/custom_components/gpodder/config_flow.py +++ b/custom_components/gpodder/config_flow.py @@ -7,7 +7,9 @@ CONF_PASSWORD, CONF_USERNAME, CONF_DEVICE, + CONF_BASE_URL, DEFAULT_NAME, + DEFAULT_BASE_URL, DOMAIN, ) @@ -42,6 +44,7 @@ async def _show_config_form(self, user_input): vol.Required(CONF_PASSWORD): str, vol.Required(CONF_DEVICE): str, vol.Required(CONF_NAME, default=DEFAULT_NAME): str, + vol.Required(CONF_BASE_URL, default=DEFAULT_BASE_URL): str, } ), errors=self._errors, diff --git a/custom_components/gpodder/const.py b/custom_components/gpodder/const.py index c227648..c64c36a 100644 --- a/custom_components/gpodder/const.py +++ b/custom_components/gpodder/const.py @@ -31,6 +31,8 @@ CONF_USERNAME = "username" CONF_PASSWORD = "password" CONF_DEVICE = "device" +CONF_BASE_URL = "base_url" # Defaults DEFAULT_NAME = DOMAIN +DEFAULT_BASE_URL = "https://gpodder.net" diff --git a/custom_components/gpodder/translations/en.json b/custom_components/gpodder/translations/en.json index 062aad2..63ed752 100644 --- a/custom_components/gpodder/translations/en.json +++ b/custom_components/gpodder/translations/en.json @@ -8,9 +8,10 @@ "username": "Username", "password": "Password", "device": "Device", - "name": "Name" + "name": "Name", + "base_url": "Server URL (e.g., https://gpodder.net)" } } } } -} \ No newline at end of file +}