1 """Config flow to configure Blink."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from blinkpy.auth
import Auth, LoginError, TokenRefreshFailed
10 from blinkpy.blinkpy
import Blink, BlinkSetupError
11 import voluptuous
as vol
19 from .const
import DEVICE_ID, DOMAIN
21 _LOGGER = logging.getLogger(__name__)
25 """Validate the user input allows us to connect."""
28 except (LoginError, TokenRefreshFailed)
as err:
29 raise InvalidAuth
from err
30 if auth.check_key_required():
35 """Send 2FA pin to blink servers."""
38 blink.setup_login_ids()
40 return await auth.send_auth_key(blink, pin)
44 """Handle a Blink config flow."""
49 """Initialize the blink flow."""
50 self.
authauth: Auth |
None =
None
53 self, user_input: dict[str, Any] |
None =
None
54 ) -> ConfigFlowResult:
55 """Handle a flow initiated by the user."""
57 if user_input
is not None:
59 {**user_input,
"device_id": DEVICE_ID},
73 errors[
"base"] =
"invalid_auth"
75 _LOGGER.exception(
"Unexpected exception")
76 errors[
"base"] =
"unknown"
80 data_schema=vol.Schema(
82 vol.Required(CONF_USERNAME): str,
83 vol.Required(CONF_PASSWORD): str,
90 self, user_input: dict[str, Any] |
None =
None
91 ) -> ConfigFlowResult:
92 """Handle 2FA step."""
94 if user_input
is not None:
97 self.hass, self.
authauth, user_input.get(CONF_PIN)
99 except BlinkSetupError:
100 errors[
"base"] =
"cannot_connect"
102 _LOGGER.exception(
"Unexpected exception")
103 errors[
"base"] =
"unknown"
108 errors[
"base"] =
"invalid_access_token"
112 data_schema=vol.Schema(
113 {vol.Optional(CONF_PIN): vol.All(str, vol.Length(min=1))}
119 self, entry_data: Mapping[str, Any]
120 ) -> ConfigFlowResult:
121 """Perform reauth upon migration of old entries."""
126 """Finish with setup."""
132 """Error to indicate we require 2FA."""
135 class InvalidAuth(HomeAssistantError):
136 """Error to indicate there is invalid auth."""
ConfigFlowResult _async_finish_flow(self)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_2fa(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_step_user(self, dict[str, Any]|None user_input=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)
None validate_input(Auth auth)
bool _send_blink_2fa_pin(HomeAssistant hass, Auth auth, str|None pin)
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)