I want to create two “async_show_form” for log in server and call api.
The config flow is working when I call one “async_show_form”, but when
I call two like below, it doesn’t work. It seems that I can get the data of user_imput
of second “async_show_form”. What I did wrong ? Somebody can help me, Please.
Thanks !!!
=========================Config flow=========================
from .const import (CONFIG_SCHEMA_1, CONFIG_SCHEMA_2, DOMAIN, CONF_SERVER_IP,
CONF_SERVER_PORT, CONF_SERVER_USERNAME, CONF_SERVER_PASSWORD,
CONF_CAMERA_USERNAME, CONF_CAMERA_PASSWORD,
CONF_CAMERA_IP_ADDRESS, CONF_ADD_ALL_DEVICE)
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
async def async_step_user(self, user_input=None):
errors = {}
if user_input is not None:
if user_input[CONF_SERVER_IP] =="111.111.0.111":
return await self.step_connect_camera()
else:
errors["base"] = "Camera create failed!!!"
return self.async_show_form(
step_id = "user", data_schema = CONFIG_SCHEMA_1, errors = errors
)
async def step_connect_camera(self,user_input=None):
errors = {}
if user_input is not None:
try:
if user_input[CONF_CAMERA_USERNAME] == 'stan':
print(user_input[CONF_CAMERA_USERNAME])
else:
errors["base"] = "Camera create failed!!!"
except:
errors["base"] = "Camera create failed!!!"
if not errors:
return await self.re_entry(user_input)
return self.async_show_form(
step_id = "connect_cam", data_schema = CONFIG_SCHEMA_2, errors = errors
)
async def re_entry(self,user_input):
return self.async_create_entry(
title = user_input,
data = {}
)
=========================const=========================
#----------SERVER----------
CONF_SERVER_IP = "server_ip"
CONF_SERVER_PORT = "server_port"
CONF_SERVER_USERNAME = "server_username"
CONF_SERVER_PASSWORD = "server_password"
#----------Camera----------
CONF_CAMERA_USERNAME = "camera_username"
CONF_CAMERA_PASSWORD = "camera_password"
CONF_CAMERA_IP_ADDRESS = "camera_ip_address"
CONF_ADD_ALL_DEVICE = "add_all_device"
CONFIG_SCHEMA_1 = vol.Schema(
{
vol.Required(CONF_SERVER_IP, default="1111.111.0.111"): cv.string,
vol.Required(CONF_SERVER_PORT, default="1111"): cv.string,
vol.Required(CONF_SERVER_USERNAME, default="stan"): cv.string,
vol.Required(CONF_SERVER_PASSWORD, default="123456"): cv.string,
}
)
CONFIG_SCHEMA_2 = vol.Schema(
{
vol.Optional(CONF_CAMERA_USERNAME, default=""): cv.string,
vol.Optional(CONF_CAMERA_PASSWORD, default=""): cv.string,
vol.Optional(CONF_CAMERA_IP_ADDRESS, default=""): cv.string,
vol.Optional(CONF_ADD_ALL_DEVICE): cv.boolean,
}
)