forked from DominikStarke/becker_centralcontrol_has
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_flow.py
75 lines (54 loc) · 2.37 KB
/
config_flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Config flow for Becker Antriebe GmbH CentralControl."""
import logging
import voluptuous as vol
from homeassistant import config_entries, exceptions
from homeassistant.components import zeroconf
from homeassistant.const import CONF_HOST, CONF_TOKEN
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from .const import DOMAIN
# from .service_listener import CentralControlDiscovery
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_TOKEN): cv.string,
}
)
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for the CentralControl."""
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
async def async_step_user(self, user_input=None) -> config_entries.ConfigFlowResult:
"""Handle the initial step."""
errors = {}
if user_input is not None:
try:
return self.async_create_entry(title="address", data=user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidHost:
errors["host"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
return self.async_show_form(data_schema=DATA_SCHEMA, errors=errors)
async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> config_entries.ConfigFlowResult:
"""Handle Zeroconf discovery."""
# return await self.async_step_discovery_confirm()
async def async_step_discovery_confirm(
self, user_input: dict[str, vol.Any] | None = None
) -> config_entries.ConfigFlowResult:
"""Confirm discovery."""
_LOGGER.exception("[async_step_discovery_confirm] zeroconf not implemented yet")
class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""
class InvalidHost(exceptions.HomeAssistantError):
"""Error to indicate there is an invalid hostname."""
async def validate_input(hass: HomeAssistant, data: dict) -> bool:
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
return True