1 """Config flow for SRP Energy."""
3 from __future__
import annotations
7 from srpenergy.client
import SrpEnergyClient
8 import voluptuous
as vol
15 from .const
import CONF_IS_TOU, DOMAIN, LOGGER
18 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
19 """Validate the user input allows us to connect.
21 Data has the keys from DATA_SCHEMA with values provided by the user.
23 srp_client = SrpEnergyClient(
29 is_valid = await hass.async_add_executor_job(srp_client.validate)
31 LOGGER.debug(
"Is user input valid: %s", is_valid)
39 """Handle an SRP Energy config flow."""
44 def _show_form(self, errors: dict[str, Any]) -> ConfigFlowResult:
45 """Show the form to the user."""
46 LOGGER.debug(
"Show Form")
49 data_schema=vol.Schema(
52 CONF_NAME, default=self.hass.config.location_name
54 vol.Required(CONF_ID): str,
55 vol.Required(CONF_USERNAME): str,
56 vol.Required(CONF_PASSWORD): str,
57 vol.Optional(CONF_IS_TOU, default=
False): bool,
64 self, user_input: dict[str, Any] |
None =
None
65 ) -> ConfigFlowResult:
66 """Handle a flow initialized by the user."""
67 LOGGER.debug(
"Config entry")
68 errors: dict[str, str] = {}
76 errors[
"base"] =
"invalid_account"
79 errors[
"base"] =
"invalid_auth"
82 LOGGER.exception(
"Unexpected exception")
92 """Error to indicate there is invalid auth."""
ConfigFlowResult _show_form(self, dict[str, Any] errors)
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)
dict[str, Any] validate_input(HomeAssistant hass, dict[str, Any] data)