1 """Config flow for microBees integration."""
3 from collections.abc
import Mapping
7 from microBeesPy
import MicroBees, MicroBeesException
13 from .const
import DOMAIN
17 config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
19 """Handle a config flow for microBees."""
26 return logging.getLogger(__name__)
30 """Extra data that needs to be appended to the authorize url."""
31 scopes = [
"read",
"write"]
32 return {
"scope":
" ".join(scopes)}
35 """Create an oauth config entry or update existing entry for reauth."""
37 microbees = MicroBees(
38 session=aiohttp_client.async_get_clientsession(self.hass),
39 token=data[CONF_TOKEN][CONF_ACCESS_TOKEN],
43 current_user = await microbees.getMyProfile()
44 except MicroBeesException:
45 return self.async_abort(reason=
"invalid_auth")
47 self.
loggerlogger.exception(
"Unexpected error")
48 return self.async_abort(reason=
"unknown")
50 await self.async_set_unique_id(current_user.id)
51 if self.source != SOURCE_REAUTH:
52 self._abort_if_unique_id_configured()
53 return self.async_create_entry(
54 title=current_user.username,
58 self._abort_if_unique_id_mismatch(reason=
"wrong_account")
59 return self.async_update_reload_and_abort(self._get_reauth_entry(), data=data)
62 self, entry_data: Mapping[str, Any]
63 ) -> ConfigFlowResult:
64 """Perform reauth upon an API authentication error."""
68 self, user_input: dict[str, Any] |
None =
None
69 ) -> ConfigFlowResult:
70 """Confirm reauth dialog."""
71 if user_input
is None:
72 return self.async_show_form(step_id=
"reauth_confirm")
73 return await self.async_step_user()
logging.Logger logger(self)
dict[str, Any] extra_authorize_data(self)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_oauth_create_entry(self, dict[str, Any] data)