diff --git a/custom_components/poollab/__init__.py b/custom_components/poollab/__init__.py index b72525e..8f8d488 100644 --- a/custom_components/poollab/__init__.py +++ b/custom_components/poollab/__init__.py @@ -9,7 +9,7 @@ from gql.client import TransportQueryError from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_API_KEY, CONF_URL +from homeassistant.const import CONF_API_KEY, CONF_SSL, CONF_URL from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -81,7 +81,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b hass.data[DOMAIN][config_entry.entry_id] = poollab = PoolLabCoordinator( hass, PoolLabApi( - token=config_entry.data[CONF_API_KEY], url=config_entry.data[CONF_URL] + token=config_entry.data[CONF_API_KEY], + url=config_entry.data[CONF_URL], + ssl=config_entry.data.get("ssl", True), ), ) else: @@ -128,6 +130,9 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> if CONF_URL not in config_entry.data: new_data[CONF_URL] = API_ENDPOINT + if CONF_SSL not in config_entry.data: + new_data[CONF_SSL] = True + hass.config_entries.async_update_entry( config_entry, data=new_data, @@ -141,5 +146,3 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> installed_minor_version, ) return True - - return False diff --git a/custom_components/poollab/config_flow.py b/custom_components/poollab/config_flow.py index 4712979..4bf0921 100644 --- a/custom_components/poollab/config_flow.py +++ b/custom_components/poollab/config_flow.py @@ -9,7 +9,7 @@ import voluptuous as vol from homeassistant import config_entries -from homeassistant.const import CONF_API_KEY, CONF_URL +from homeassistant.const import CONF_API_KEY, CONF_SSL, CONF_URL from homeassistant.data_entry_flow import FlowResult import homeassistant.helpers.config_validation as cv @@ -18,17 +18,12 @@ _LOGGER = logging.getLogger(__name__) -PLACEHOLDERS = { - CONF_API_KEY: "API key", - CONF_URL: "API endpoint URL", -} - class PoolLabConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """PoolLab config flow.""" VERSION = 1 - MINOR_VERSION = 2 + MINOR_VERSION = 3 data = None options = None _reauth_entry: config_entries.ConfigEntry | None = None @@ -41,6 +36,7 @@ async def async_step_user( defaults = { CONF_API_KEY: "", CONF_URL: API_ENDPOINT, + CONF_SSL: True, } if user_input is not None: @@ -79,12 +75,14 @@ async def async_step_user( vol.Optional( CONF_URL, default=defaults.get(CONF_URL, API_ENDPOINT) ): cv.string, + vol.Optional( + CONF_SSL, default=defaults.get(CONF_SSL, True) + ): cv.boolean, } ) return self.async_show_form( step_id="user", data_schema=user_schema, - description_placeholders=PLACEHOLDERS, errors=errors, ) @@ -122,12 +120,14 @@ async def async_step_reconfigure( vol.Optional( CONF_URL, default=config_entry.data.get(CONF_URL, API_ENDPOINT) ): cv.string, + vol.Optional( + CONF_SSL, default=config_entry.data.get(CONF_SSL, True) + ): cv.boolean, } ) return self.async_show_form( step_id="reconfigure", data_schema=user_schema, - description_placeholders=PLACEHOLDERS, errors=errors, ) @@ -145,7 +145,9 @@ async def async_step_reauth(self, user_input: Mapping[str, Any]) -> FlowResult: async def is_valid(self, user_input): """Check for user input errors.""" poollab_api = PoolLabApi( - token=user_input[CONF_API_KEY], url=user_input[CONF_URL] + token=user_input[CONF_API_KEY], + url=user_input[CONF_URL], + ssl=user_input[CONF_SSL], ) if not await poollab_api.test(): raise InvalidAuth diff --git a/custom_components/poollab/poollab.py b/custom_components/poollab/poollab.py index e641542..ef088ec 100644 --- a/custom_components/poollab/poollab.py +++ b/custom_components/poollab/poollab.py @@ -240,11 +240,12 @@ def as_dict(self) -> dict[str, Any]: class PoolLabApi: """Public API class for PoolLab.""" - def __init__(self, token: str, url=API_ENDPOINT) -> None: + def __init__(self, token: str, url: str = API_ENDPOINT, ssl: bool = True) -> None: """Init the cloud api object.""" self._token = token self._data = None self._url = url + self._ssl = ssl def _build_schema(self) -> str: schema = "\n" @@ -259,7 +260,7 @@ async def _update(self, schema: str | None = None) -> bool: if schema is None: schema = self._build_schema() transport = AIOHTTPTransport( - url=self._url, headers={"Authorization": self._token}, ssl=True + url=self._url, headers={"Authorization": self._token}, ssl=self._ssl ) async with Client( transport=transport, diff --git a/custom_components/poollab/translations/en.json b/custom_components/poollab/translations/en.json index 38f3f0d..0c8ffd1 100644 --- a/custom_components/poollab/translations/en.json +++ b/custom_components/poollab/translations/en.json @@ -6,7 +6,17 @@ "description": "Setup a PoolLab integration, get key from https://labcom.cloud/pages/user-setting", "data": { "api_key": "API key", - "url": "API endpoint URL" + "url": "API endpoint URL", + "ssl": "Use SSL" + } + }, + "reconfigure": { + "title": "PoolLab", + "description": "Reconfigure a PoolLab integration, get key from https://labcom.cloud/pages/user-setting", + "data": { + "api_key": "API key", + "url": "API endpoint URL", + "ssl": "Use SSL" } } },