1 """Config flow for growatt server integration."""
6 import voluptuous
as vol
16 LOGIN_INVALID_AUTH_CODE,
22 """Config flow class."""
26 api: growattServer.GrowattApi
29 """Initialise growatt server flow."""
31 self.
datadata: dict[str, Any] = {}
35 """Show the form to the user."""
36 data_schema = vol.Schema(
38 vol.Required(CONF_USERNAME): str,
39 vol.Required(CONF_PASSWORD): str,
40 vol.Required(CONF_URL, default=DEFAULT_URL): vol.In(SERVER_URLS),
45 step_id=
"user", data_schema=data_schema, errors=errors
49 self, user_input: dict[str, Any] |
None =
None
50 ) -> ConfigFlowResult:
51 """Handle the start of the config flow."""
56 self.
apiapi = growattServer.GrowattApi(
57 add_random_user_id=
True, agent_identifier=user_input[CONF_USERNAME]
59 self.
apiapi.server_url = user_input[CONF_URL]
60 login_response = await self.hass.async_add_executor_job(
61 self.
apiapi.login, user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
65 not login_response[
"success"]
66 and login_response[
"msg"] == LOGIN_INVALID_AUTH_CODE
69 self.
user_iduser_id = login_response[
"user"][
"id"]
75 self, user_input: dict[str, Any] |
None =
None
76 ) -> ConfigFlowResult:
77 """Handle adding a "plant" to Home Assistant."""
78 plant_info = await self.hass.async_add_executor_job(
82 if not plant_info[
"data"]:
85 plants = {plant[
"plantId"]: plant[
"plantName"]
for plant
in plant_info[
"data"]}
87 if user_input
is None and len(plant_info[
"data"]) > 1:
88 data_schema = vol.Schema({vol.Required(CONF_PLANT_ID): vol.In(plants)})
92 if user_input
is None:
94 user_input = {CONF_PLANT_ID: plant_info[
"data"][0][
"plantId"]}
96 user_input[CONF_NAME] = plants[user_input[CONF_PLANT_ID]]
ConfigFlowResult async_step_plant(self, dict[str, Any]|None user_input=None)
def _async_show_user_form(self, errors=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
IssData update(pyiss.ISS iss)