1 """Adds config flow for Nord Pool integration."""
3 from __future__
import annotations
7 from pynordpool
import (
10 NordPoolEmptyResponseError,
13 from pynordpool.const
import AREAS
14 import voluptuous
as vol
28 from .const
import CONF_AREAS, DEFAULT_NAME, DOMAIN
33 SELECT_CURRENCY = [currency.value
for currency
in Currency]
35 DATA_SCHEMA = vol.Schema(
41 mode=SelectSelectorMode.DROPDOWN,
47 options=SELECT_CURRENCY,
49 mode=SelectSelectorMode.DROPDOWN,
57 async
def test_api(hass: HomeAssistant, user_input: dict[str, Any]) -> dict[str, str]:
58 """Test fetch data from Nord Pool."""
61 await client.async_get_delivery_period(
63 Currency(user_input[CONF_CURRENCY]),
64 user_input[CONF_AREAS],
66 except NordPoolEmptyResponseError:
67 return {
"base":
"no_data"}
69 return {
"base":
"cannot_connect"}
75 """Handle a config flow for Nord Pool integration."""
80 self, user_input: dict[str, Any] |
None =
None
81 ) -> ConfigFlowResult:
82 """Handle the initial step."""
83 errors: dict[str, str] = {}
85 errors = await
test_api(self.hass, user_input)
94 data_schema=DATA_SCHEMA,
99 self, user_input: dict[str, Any] |
None =
None
100 ) -> ConfigFlowResult:
101 """Handle the reconfiguration step."""
102 errors: dict[str, str] = {}
104 errors = await
test_api(self.hass, user_input)
108 reconfigure_entry, data_updates=user_input
112 step_id=
"reconfigure",
113 data_schema=DATA_SCHEMA,
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reconfigure(self, dict[str, Any]|None user_input=None)
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_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigEntry _get_reconfigure_entry(self)
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)
dict[str, str] test_api(HomeAssistant hass, dict[str, Any] user_input)
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)