Skip to content

Commit

Permalink
Add type hints to async_step_reauth (home-assistant#74164)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jun 29, 2022
1 parent 500105f commit d323508
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 33 deletions.
7 changes: 5 additions & 2 deletions homeassistant/components/august/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Config flow for August integration."""
from collections.abc import Mapping
import logging
from typing import Any

import voluptuous as vol
from yalexs.authenticator import ValidationResult

from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.data_entry_flow import FlowResult

from .const import CONF_LOGIN_METHOD, DOMAIN, LOGIN_METHODS, VERIFICATION_CODE_KEY
from .exceptions import CannotConnect, InvalidAuth, RequireValidation
Expand Down Expand Up @@ -109,9 +112,9 @@ async def async_step_validation(self, user_input=None):
},
)

async def async_step_reauth(self, data):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Handle configuration by re-auth."""
self._user_auth_details = dict(data)
self._user_auth_details = dict(entry_data)
self._mode = "reauth"
self._needs_reset = True
self._august_gateway = AugustGateway(self.hass)
Expand Down
15 changes: 10 additions & 5 deletions homeassistant/components/azure_devops/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Config flow to configure the Azure DevOps integration."""
from collections.abc import Mapping
from typing import Any

from aioazuredevops.client import DevOpsClient
import aiohttp
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.data_entry_flow import FlowResult

from .const import CONF_ORG, CONF_PAT, CONF_PROJECT, DOMAIN

Expand Down Expand Up @@ -82,12 +86,12 @@ async def async_step_user(self, user_input=None):
return await self._show_setup_form(errors)
return self._async_create_entry()

async def async_step_reauth(self, user_input):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Handle configuration by re-auth."""
if user_input.get(CONF_ORG) and user_input.get(CONF_PROJECT):
self._organization = user_input[CONF_ORG]
self._project = user_input[CONF_PROJECT]
self._pat = user_input[CONF_PAT]
if entry_data.get(CONF_ORG) and entry_data.get(CONF_PROJECT):
self._organization = entry_data[CONF_ORG]
self._project = entry_data[CONF_PROJECT]
self._pat = entry_data[CONF_PAT]

self.context["title_placeholders"] = {
"project_url": f"{self._organization}/{self._project}",
Expand All @@ -100,6 +104,7 @@ async def async_step_reauth(self, user_input):
return await self._show_reauth_form(errors)

entry = await self.async_set_unique_id(self.unique_id)
assert entry
self.hass.config_entries.async_update_entry(
entry,
data={
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/elmax/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Config flow for elmax-cloud integration."""
from __future__ import annotations

from collections.abc import Mapping
import logging
from typing import Any

Expand Down Expand Up @@ -167,10 +168,10 @@ async def async_step_panels(
step_id="panels", data_schema=self._panels_schema, errors=errors
)

async def async_step_reauth(self, user_input=None):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Perform reauth upon an API authentication error."""
self._reauth_username = user_input.get(CONF_ELMAX_USERNAME)
self._reauth_panelid = user_input.get(CONF_ELMAX_PANEL_ID)
self._reauth_username = entry_data.get(CONF_ELMAX_USERNAME)
self._reauth_panelid = entry_data.get(CONF_ELMAX_PANEL_ID)
return await self.async_step_reauth_confirm()

async def async_step_reauth_confirm(self, user_input=None):
Expand Down
10 changes: 7 additions & 3 deletions homeassistant/components/hive/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Config Flow for Hive."""
from __future__ import annotations

from collections.abc import Mapping
from typing import Any

from apyhiveapi import Auth
from apyhiveapi.helper.hive_exceptions import (
HiveApiError,
Expand All @@ -13,6 +16,7 @@
from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult

from .const import CONF_CODE, CONF_DEVICE_NAME, CONFIG_ENTRY_VERSION, DOMAIN

Expand Down Expand Up @@ -136,11 +140,11 @@ async def async_setup_hive_entry(self):
return self.async_abort(reason="reauth_successful")
return self.async_create_entry(title=self.data["username"], data=self.data)

async def async_step_reauth(self, user_input=None):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Re Authenticate a user."""
data = {
CONF_USERNAME: user_input[CONF_USERNAME],
CONF_PASSWORD: user_input[CONF_PASSWORD],
CONF_USERNAME: entry_data[CONF_USERNAME],
CONF_PASSWORD: entry_data[CONF_PASSWORD],
}
return await self.async_step_user(data)

Expand Down
7 changes: 2 additions & 5 deletions homeassistant/components/hyperion/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,9 @@ async def _advance_to_auth_step_if_necessary(
return await self.async_step_auth()
return await self.async_step_confirm()

async def async_step_reauth(
self,
config_data: Mapping[str, Any],
) -> FlowResult:
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Handle a reauthentication flow."""
self._data = dict(config_data)
self._data = dict(entry_data)
async with self._create_client(raw_connection=True) as hyperion_client:
if not hyperion_client:
return self.async_abort(reason="cannot_connect")
Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/mazda/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Config flow for Mazda Connected Services integration."""
from collections.abc import Mapping
import logging
from typing import Any

import aiohttp
from pymazda import (
Expand All @@ -11,6 +13,7 @@

from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_REGION
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import aiohttp_client

from .const import DOMAIN, MAZDA_REGIONS
Expand Down Expand Up @@ -97,11 +100,11 @@ async def async_step_user(self, user_input=None):
errors=errors,
)

async def async_step_reauth(self, user_input=None):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Perform reauth if the user credentials have changed."""
self._reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
self._email = user_input[CONF_EMAIL]
self._region = user_input[CONF_REGION]
self._email = entry_data[CONF_EMAIL]
self._region = entry_data[CONF_REGION]
return await self.async_step_user()
6 changes: 4 additions & 2 deletions homeassistant/components/nuki/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Config flow to configure the Nuki integration."""
from collections.abc import Mapping
import logging
from typing import Any

from pynuki import NukiBridge
from pynuki.bridge import InvalidCredentialsException
Expand Down Expand Up @@ -80,9 +82,9 @@ async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowRes

return await self.async_step_validate()

async def async_step_reauth(self, data):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Perform reauth upon an API authentication error."""
self._data = data
self._data = entry_data

return await self.async_step_reauth_confirm()

Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/plex/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Config flow for Plex."""
from __future__ import annotations

from collections.abc import Mapping
import copy
import logging
from typing import Any

from aiohttp import web_response
import plexapi.exceptions
Expand All @@ -26,6 +28,7 @@
CONF_VERIFY_SSL,
)
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv

Expand Down Expand Up @@ -329,9 +332,9 @@ async def async_step_use_external_token(self, user_input=None):
server_config = {CONF_TOKEN: self.token}
return await self.async_step_server_validate(server_config)

async def async_step_reauth(self, data):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Handle a reauthorization flow request."""
self.current_login = dict(data)
self.current_login = dict(entry_data)
return await self.async_step_user()


Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/sense/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Config flow for Sense integration."""
from collections.abc import Mapping
import logging
from typing import Any

from sense_energy import (
ASyncSenseable,
Expand All @@ -10,6 +12,7 @@

from homeassistant import config_entries
from homeassistant.const import CONF_CODE, CONF_EMAIL, CONF_PASSWORD, CONF_TIMEOUT
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import ACTIVE_UPDATE_RATE, DEFAULT_TIMEOUT, DOMAIN, SENSE_CONNECT_EXCEPTIONS
Expand Down Expand Up @@ -120,10 +123,10 @@ async def async_step_user(self, user_input=None):
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)

async def async_step_reauth(self, data):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Handle configuration by re-auth."""
self._auth_data = dict(data)
return await self.async_step_reauth_validate(data)
self._auth_data = dict(entry_data)
return await self.async_step_reauth_validate(entry_data)

async def async_step_reauth_validate(self, user_input=None):
"""Handle reauth and validation."""
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/spotify/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ async def async_oauth_create_entry(self, data: dict[str, Any]) -> FlowResult:

return self.async_create_entry(title=name, data=data)

async def async_step_reauth(self, entry: Mapping[str, Any]) -> FlowResult:
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Perform reauth upon migration of old entries."""
self.reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)

persistent_notification.async_create(
self.hass,
f"Spotify integration for account {entry['id']} needs to be re-authenticated. Please go to the integrations page to re-configure it.",
f"Spotify integration for account {entry_data['id']} needs to be "
"re-authenticated. Please go to the integrations page to re-configure it.",
"Spotify re-authentication",
"spotify_reauth",
)
Expand Down
10 changes: 7 additions & 3 deletions homeassistant/components/totalconnect/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Config flow for the Total Connect component."""
from __future__ import annotations

from collections.abc import Mapping
from typing import Any

from total_connect_client.client import TotalConnectClient
from total_connect_client.exceptions import AuthenticationError
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.const import CONF_LOCATION, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult

from .const import AUTO_BYPASS, CONF_USERCODES, DOMAIN

Expand Down Expand Up @@ -121,10 +125,10 @@ async def async_step_locations(self, user_entry=None):
description_placeholders={"location_id": location_for_user},
)

async def async_step_reauth(self, config):
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Perform reauth upon an authentication error or no usercode."""
self.username = config[CONF_USERNAME]
self.usercodes = config[CONF_USERCODES]
self.username = entry_data[CONF_USERNAME]
self.usercodes = entry_data[CONF_USERCODES]

return await self.async_step_reauth_confirm()

Expand Down

0 comments on commit d323508

Please sign in to comment.