1 """Config flow for the SolarEdge platform."""
3 from __future__
import annotations
8 from aiohttp
import ClientError
10 import voluptuous
as vol
18 from .const
import CONF_SITE_ID, DEFAULT_NAME, DOMAIN
22 """Handle a config flow."""
27 """Initialize the config flow."""
28 self.
_errors_errors: dict[str, str] = {}
32 """Return the site_ids for the domain."""
34 entry.data[CONF_SITE_ID]
36 if CONF_SITE_ID
in entry.data
40 """Return True if site_id exists in configuration."""
44 """Check if we can connect to the soleredge api service."""
46 api = aiosolaredge.SolarEdge(api_key, session)
48 response = await api.get_details(site_id)
49 if response[
"details"][
"status"].lower() !=
"active":
50 self.
_errors_errors[CONF_SITE_ID] =
"site_not_active"
52 except (TimeoutError, ClientError, socket.gaierror):
53 self.
_errors_errors[CONF_SITE_ID] =
"could_not_connect"
56 self.
_errors_errors[CONF_SITE_ID] =
"invalid_api_key"
61 self, user_input: dict[str, Any] |
None =
None
62 ) -> ConfigFlowResult:
63 """Step when user initializes a integration."""
65 if user_input
is not None:
66 name =
slugify(user_input.get(CONF_NAME, DEFAULT_NAME))
68 self.
_errors_errors[CONF_SITE_ID] =
"already_configured"
70 site = user_input[CONF_SITE_ID]
71 api = user_input[CONF_API_KEY]
75 title=name, data={CONF_SITE_ID: site, CONF_API_KEY: api}
79 user_input = {CONF_NAME: DEFAULT_NAME, CONF_SITE_ID:
"", CONF_API_KEY:
""}
82 data_schema=vol.Schema(
85 CONF_NAME, default=user_input.get(CONF_NAME, DEFAULT_NAME)
87 vol.Required(CONF_SITE_ID, default=user_input[CONF_SITE_ID]): str,
88 vol.Required(CONF_API_KEY, default=user_input[CONF_API_KEY]): str,
bool _async_check_site(self, str site_id, str api_key)
set[str] _async_current_site_ids(self)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
bool _site_in_configuration_exists(self, str site_id)
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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=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)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)