55import voluptuous as vol
66
77from homeassistant import config_entries , core , exceptions
8+ from homeassistant .const import CONF_HOST , CONF_PASSWORD
89from homeassistant .helpers .aiohttp_client import async_get_clientsession
910from Plugwise_Smile .Smile import Smile
1011
1112from .const import DOMAIN # pylint:disable=unused-import
1213
1314_LOGGER = logging .getLogger (__name__ )
1415
15-
16- def _get_config_schema (input_dict : Dict [str , Any ] = None ) -> vol .Schema :
17- """
18- Return schema defaults for init step based on user input/config dict.
19-
20- Retain info already provided for future form views by setting them as defaults in schema.
21- """
22- if input_dict is None :
23- input_dict = {}
24-
25- return vol .Schema ({vol .Required ("host" ): str , vol .Required ("password" ): str })
26-
16+ DATA_SCHEMA = vol .Schema ({vol .Required (CONF_HOST ): str , vol .Required (CONF_PASSWORD ): str })
2717
2818async def validate_input (hass : core .HomeAssistant , data ):
2919 """
@@ -36,7 +26,11 @@ async def validate_input(hass: core.HomeAssistant, data):
3626 host = data ["host" ], password = data ["password" ], timeout = 30 , websession = websession
3727 )
3828
39- if not await api .connect ():
29+ try :
30+ await api .connect ()
31+ except Smile .InvalidAuthentication :
32+ raise InvalidAuth
33+ except Smile .PlugwiseError :
4034 raise CannotConnect
4135
4236 return {"title" : api .smile_name }
@@ -48,14 +42,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
4842 VERSION = 1
4943 CONNECTION_CLASS = config_entries .CONN_CLASS_LOCAL_POLL
5044
51- def __init__ (self ) -> None :
52- """Initialize config flow."""
53- self ._user_schema = None
54-
5545 async def async_step_user (self , user_input = None ):
5646 """Handle the initial step."""
5747 errors = {}
58- self ._user_schema = _get_config_schema (user_input )
5948 if user_input is not None :
6049
6150 try :
@@ -71,7 +60,7 @@ async def async_step_user(self, user_input=None):
7160 errors ["base" ] = "unknown"
7261
7362 return self .async_show_form (
74- step_id = "user" , data_schema = self . _user_schema , errors = errors
63+ step_id = "user" , data_schema = DATA_SCHEMA , errors = errors
7564 )
7665
7766
0 commit comments