Skip to content

Commit 777834f

Browse files
authored
Merge pull request #59 from dala318/ssl_conf
Add config option to use SSL
2 parents 15bbae2 + b6b6126 commit 777834f

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
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: 12 additions & 10 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,12 @@
1818

1919
_LOGGER = logging.getLogger(__name__)
2020

21-
PLACEHOLDERS = {
22-
CONF_API_KEY: "API key",
23-
CONF_URL: "API endpoint URL",
24-
}
25-
2621

2722
class PoolLabConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
2823
"""PoolLab config flow."""
2924

3025
VERSION = 1
31-
MINOR_VERSION = 2
26+
MINOR_VERSION = 3
3227
data = None
3328
options = None
3429
_reauth_entry: config_entries.ConfigEntry | None = None
@@ -41,6 +36,7 @@ async def async_step_user(
4136
defaults = {
4237
CONF_API_KEY: "",
4338
CONF_URL: API_ENDPOINT,
39+
CONF_SSL: True,
4440
}
4541

4642
if user_input is not None:
@@ -79,12 +75,14 @@ async def async_step_user(
7975
vol.Optional(
8076
CONF_URL, default=defaults.get(CONF_URL, API_ENDPOINT)
8177
): cv.string,
78+
vol.Optional(
79+
CONF_SSL, default=defaults.get(CONF_SSL, True)
80+
): cv.boolean,
8281
}
8382
)
8483
return self.async_show_form(
8584
step_id="user",
8685
data_schema=user_schema,
87-
description_placeholders=PLACEHOLDERS,
8886
errors=errors,
8987
)
9088

@@ -122,12 +120,14 @@ async def async_step_reconfigure(
122120
vol.Optional(
123121
CONF_URL, default=config_entry.data.get(CONF_URL, API_ENDPOINT)
124122
): cv.string,
123+
vol.Optional(
124+
CONF_SSL, default=config_entry.data.get(CONF_SSL, True)
125+
): cv.boolean,
125126
}
126127
)
127128
return self.async_show_form(
128129
step_id="reconfigure",
129130
data_schema=user_schema,
130-
description_placeholders=PLACEHOLDERS,
131131
errors=errors,
132132
)
133133

@@ -145,7 +145,9 @@ async def async_step_reauth(self, user_input: Mapping[str, Any]) -> FlowResult:
145145
async def is_valid(self, user_input):
146146
"""Check for user input errors."""
147147
poollab_api = PoolLabApi(
148-
token=user_input[CONF_API_KEY], url=user_input[CONF_URL]
148+
token=user_input[CONF_API_KEY],
149+
url=user_input[CONF_URL],
150+
ssl=user_input[CONF_SSL],
149151
)
150152
if not await poollab_api.test():
151153
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)