def setup(hass, base_config): """Set up the Supla component.""" server_confs = base_config[DOMAIN][CONF_SERVERS] hass.data[SUPLA_SERVERS] = {} hass.data[SUPLA_CHANNELS] = {} for server_conf in server_confs: server_address = server_conf[CONF_SERVER] server = SuplaAPI(server_address, server_conf[CONF_ACCESS_TOKEN]) # Test connection try: srv_info = server.get_server_info() if srv_info.get("authenticated"): hass.data[SUPLA_SERVERS][server_conf[CONF_SERVER]] = server else: _LOGGER.error( "Server: %s not configured. API call returned: %s", server_address, srv_info, ) return False except OSError: _LOGGER.exception( "Server: %s not configured. Error on Supla API access: ", server_address) return False discover_devices(hass, base_config) return True
async def async_step_init(self, user_input=None): """Handle a flow start.""" errors = {} description_placeholders = {"error_info": ""} if user_input is not None: # Test connection server = SuplaAPI(user_input[CONF_SERVER], user_input[CONF_ACCESS_TOKEN]) srv_info = server.get_server_info() if srv_info.get("authenticated"): """Finish config flow""" return self.async_create_entry( title="AIS " + user_input[CONF_SERVER], data=user_input ) else: _LOGGER.error( "Server: %s not configured. API call returned: %s", user_input[CONF_SERVER], srv_info, ) errors = {CONF_SERVER: "supla_no_connection"} description_placeholders = {"error_info": str(srv_info)} return self.async_show_form( step_id="init", data_schema=vol.Schema( {vol.Required(CONF_SERVER): str, vol.Required(CONF_ACCESS_TOKEN): str} ), errors=errors, description_placeholders=description_placeholders, )