Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit b15a6b7

Browse files
authored
Fix config flow (#25)
1 parent 7ce1537 commit b15a6b7

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

custom_components/fullykiosk/config_flow.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
import logging
33

44
import voluptuous as vol
5+
from async_timeout import timeout
6+
7+
from aiohttp.client_exceptions import ClientConnectorError
58

69
from fullykiosk import FullyKiosk
10+
from fullykiosk.exceptions import FullyKioskError
711

812
from homeassistant import config_entries, core, exceptions
913
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_PASSWORD
14+
from homeassistant.helpers.aiohttp_client import async_get_clientsession
15+
1016

1117
from .const import DOMAIN # pylint:disable=unused-import
1218

@@ -39,25 +45,15 @@ async def authenticate(self, username, password) -> bool:
3945

4046

4147
async def validate_input(hass: core.HomeAssistant, data):
42-
"""Validate the user input allows us to connect.
43-
44-
Data has the keys from DATA_SCHEMA with values provided by the user.
45-
"""
46-
# TODO validate the data can be used to set up a connection.
47-
48-
# If your PyPI package is not built with async, pass your methods
49-
# to the executor:
50-
# await hass.async_add_executor_job(
51-
# your_validate_func, data["username"], data["password"]
52-
# )
53-
54-
fully = FullyKiosk(data["host"], data["port"], data["password"])
55-
56-
# try:
57-
deviceInfo = await hass.async_add_executor_job(fully.getDeviceInfo)
58-
# except:
59-
60-
# raise InvalidAuth
48+
"""Validate the user input allows us to connect."""
49+
session = async_get_clientsession()
50+
fully = FullyKiosk(session, data["host"], data["port"], data["password"])
51+
52+
try:
53+
with timeout(10):
54+
deviceInfo = await fully.getDeviceInfo()
55+
except (FullyKioskError, ClientConnectorError):
56+
raise CannotConnect
6157

6258
# If you cannot connect:
6359
# throw CannotConnect

0 commit comments

Comments
 (0)