Skip to content

Commit 570d108

Browse files
committed
Add config option to use SSL
1 parent 15bbae2 commit 570d108

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

custom_components/poollab/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from gql.client import TransportQueryError
1010

1111
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
12-
from homeassistant.const import CONF_API_KEY, CONF_URL
12+
from homeassistant.const import CONF_API_KEY, CONF_SSL, CONF_URL
1313
from homeassistant.core import HomeAssistant
1414
from homeassistant.exceptions import ConfigEntryAuthFailed
1515
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
@@ -81,7 +81,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
8181
hass.data[DOMAIN][config_entry.entry_id] = poollab = PoolLabCoordinator(
8282
hass,
8383
PoolLabApi(
84-
token=config_entry.data[CONF_API_KEY], url=config_entry.data[CONF_URL]
84+
token=config_entry.data[CONF_API_KEY],
85+
url=config_entry.data[CONF_URL],
86+
ssl=config_entry.data.get("ssl", True),
8587
),
8688
)
8789
else:
@@ -128,6 +130,9 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
128130
if CONF_URL not in config_entry.data:
129131
new_data[CONF_URL] = API_ENDPOINT
130132

133+
if CONF_SSL not in config_entry.data:
134+
new_data[CONF_SSL] = True
135+
131136
hass.config_entries.async_update_entry(
132137
config_entry,
133138
data=new_data,
@@ -141,5 +146,3 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
141146
installed_minor_version,
142147
)
143148
return True
144-
145-
return False

custom_components/poollab/config_flow.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import voluptuous as vol
1010

1111
from homeassistant import config_entries
12-
from homeassistant.const import CONF_API_KEY, CONF_URL
12+
from homeassistant.const import CONF_API_KEY, CONF_SSL, CONF_URL
1313
from homeassistant.data_entry_flow import FlowResult
1414
import homeassistant.helpers.config_validation as cv
1515

@@ -18,17 +18,18 @@
1818

1919
_LOGGER = logging.getLogger(__name__)
2020

21-
PLACEHOLDERS = {
22-
CONF_API_KEY: "API key",
23-
CONF_URL: "API endpoint URL",
24-
}
21+
# PLACEHOLDERS = {
22+
# CONF_API_KEY: "API key",
23+
# CONF_URL: "API endpoint URL",
24+
# CONF_SSL: "Use SSL (recommended)",
25+
# }
2526

2627

2728
class PoolLabConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
2829
"""PoolLab config flow."""
2930

3031
VERSION = 1
31-
MINOR_VERSION = 2
32+
MINOR_VERSION = 3
3233
data = None
3334
options = None
3435
_reauth_entry: config_entries.ConfigEntry | None = None
@@ -41,6 +42,7 @@ async def async_step_user(
4142
defaults = {
4243
CONF_API_KEY: "",
4344
CONF_URL: API_ENDPOINT,
45+
CONF_SSL: True,
4446
}
4547

4648
if user_input is not None:
@@ -79,12 +81,15 @@ async def async_step_user(
7981
vol.Optional(
8082
CONF_URL, default=defaults.get(CONF_URL, API_ENDPOINT)
8183
): cv.string,
84+
vol.Optional(
85+
CONF_SSL, default=defaults.get(CONF_SSL, True)
86+
): cv.boolean,
8287
}
8388
)
8489
return self.async_show_form(
8590
step_id="user",
8691
data_schema=user_schema,
87-
description_placeholders=PLACEHOLDERS,
92+
# description_placeholders=PLACEHOLDERS,
8893
errors=errors,
8994
)
9095

@@ -122,12 +127,15 @@ async def async_step_reconfigure(
122127
vol.Optional(
123128
CONF_URL, default=config_entry.data.get(CONF_URL, API_ENDPOINT)
124129
): cv.string,
130+
vol.Optional(
131+
CONF_SSL, default=config_entry.data.get(CONF_SSL, True)
132+
): cv.boolean,
125133
}
126134
)
127135
return self.async_show_form(
128136
step_id="reconfigure",
129137
data_schema=user_schema,
130-
description_placeholders=PLACEHOLDERS,
138+
# description_placeholders=PLACEHOLDERS,
131139
errors=errors,
132140
)
133141

@@ -145,7 +153,9 @@ async def async_step_reauth(self, user_input: Mapping[str, Any]) -> FlowResult:
145153
async def is_valid(self, user_input):
146154
"""Check for user input errors."""
147155
poollab_api = PoolLabApi(
148-
token=user_input[CONF_API_KEY], url=user_input[CONF_URL]
156+
token=user_input[CONF_API_KEY],
157+
url=user_input[CONF_URL],
158+
ssl=user_input[CONF_SSL],
149159
)
150160
if not await poollab_api.test():
151161
raise InvalidAuth

custom_components/poollab/poollab.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,12 @@ def as_dict(self) -> dict[str, Any]:
240240
class PoolLabApi:
241241
"""Public API class for PoolLab."""
242242

243-
def __init__(self, token: str, url=API_ENDPOINT) -> None:
243+
def __init__(self, token: str, url: str = API_ENDPOINT, ssl: bool = True) -> None:
244244
"""Init the cloud api object."""
245245
self._token = token
246246
self._data = None
247247
self._url = url
248+
self._ssl = ssl
248249

249250
def _build_schema(self) -> str:
250251
schema = "\n"
@@ -259,7 +260,7 @@ async def _update(self, schema: str | None = None) -> bool:
259260
if schema is None:
260261
schema = self._build_schema()
261262
transport = AIOHTTPTransport(
262-
url=self._url, headers={"Authorization": self._token}, ssl=True
263+
url=self._url, headers={"Authorization": self._token}, ssl=self._ssl
263264
)
264265
async with Client(
265266
transport=transport,

custom_components/poollab/translations/en.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
"description": "Setup a PoolLab integration, get key from https://labcom.cloud/pages/user-setting",
77
"data": {
88
"api_key": "API key",
9-
"url": "API endpoint URL"
9+
"url": "API endpoint URL",
10+
"ssl": "Use SSL"
11+
}
12+
},
13+
"reconfigure": {
14+
"title": "PoolLab",
15+
"description": "Reconfigure a PoolLab integration, get key from https://labcom.cloud/pages/user-setting",
16+
"data": {
17+
"api_key": "API key",
18+
"url": "API endpoint URL",
19+
"ssl": "Use SSL"
1020
}
1121
}
1222
},

0 commit comments

Comments
 (0)