Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions custom_components/poollab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -141,5 +146,3 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
installed_minor_version,
)
return True

return False
22 changes: 12 additions & 10 deletions custom_components/poollab/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand All @@ -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
5 changes: 3 additions & 2 deletions custom_components/poollab/poollab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion custom_components/poollab/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down