Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions homeassistant/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import asyncio
from collections import OrderedDict
from datetime import timedelta
from typing import Any, Dict, Optional, Tuple, cast
from typing import Any, Dict, Mapping, Optional, Tuple, cast

import jwt

from homeassistant import data_entry_flow
from homeassistant.auth.const import ACCESS_TOKEN_EXPIRATION
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.util import dt as dt_util

from . import auth_store, models
Expand Down Expand Up @@ -97,8 +98,8 @@ async def async_create_flow(
return await auth_provider.async_login_flow(context)

async def async_finish_flow(
self, flow: data_entry_flow.FlowHandler, result: dict[str, Any]
) -> dict[str, Any]:
self, flow: data_entry_flow.FlowHandler, result: FlowResultDict
) -> FlowResultDict:
"""Return a user as result of login flow."""
flow = cast(LoginFlow, flow)

Expand All @@ -115,7 +116,7 @@ async def async_finish_flow(
raise KeyError(f"Unknown auth provider {result['handler']}")

credentials = await auth_provider.async_get_or_create_credentials(
result["data"]
cast(Mapping[str, str], result["data"]),
)

if flow.context.get("credential_only"):
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/auth/mfa_modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from homeassistant import data_entry_flow, requirements
from homeassistant.const import CONF_ID, CONF_NAME, CONF_TYPE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util.decorator import Registry

Expand Down Expand Up @@ -105,7 +106,7 @@ def __init__(

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the first step of setup flow.

Return self.async_show_form(step_id='init') if user_input is None.
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/auth/mfa_modules/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from homeassistant.const import CONF_EXCLUDE, CONF_INCLUDE
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import ServiceNotFound
from homeassistant.helpers import config_validation as cv

Expand Down Expand Up @@ -292,7 +293,7 @@ def __init__(

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Let user select available notify services."""
errors: dict[str, str] = {}

Expand All @@ -318,7 +319,7 @@ async def async_step_init(

async def async_step_setup(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Verify user can receive one-time password."""
errors: dict[str, str] = {}

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/auth/mfa_modules/totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from homeassistant.auth.models import User
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultDict

from . import (
MULTI_FACTOR_AUTH_MODULE_SCHEMA,
Expand Down Expand Up @@ -189,7 +190,7 @@ def __init__(

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the first step of setup flow.

Return self.async_show_form(step_id='init') if user_input is None.
Expand Down
12 changes: 7 additions & 5 deletions homeassistant/auth/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Auth providers for Home Assistant."""
from __future__ import annotations

from collections.abc import Mapping
import importlib
import logging
import types
Expand All @@ -12,6 +13,7 @@
from homeassistant import data_entry_flow, requirements
from homeassistant.const import CONF_ID, CONF_NAME, CONF_TYPE
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import dt as dt_util
from homeassistant.util.decorator import Registry
Expand Down Expand Up @@ -102,7 +104,7 @@ async def async_login_flow(self, context: dict | None) -> LoginFlow:
raise NotImplementedError

async def async_get_or_create_credentials(
self, flow_result: dict[str, str]
self, flow_result: Mapping[str, str]
) -> Credentials:
"""Get credentials based on the flow result."""
raise NotImplementedError
Expand Down Expand Up @@ -198,7 +200,7 @@ def __init__(self, auth_provider: AuthProvider) -> None:

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the first step of login flow.

Return self.async_show_form(step_id='init') if user_input is None.
Expand All @@ -208,7 +210,7 @@ async def async_step_init(

async def async_step_select_mfa_module(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the step of select mfa module."""
errors = {}

Expand All @@ -233,7 +235,7 @@ async def async_step_select_mfa_module(

async def async_step_mfa(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the step of mfa validation."""
assert self.credential
assert self.user
Expand Down Expand Up @@ -285,6 +287,6 @@ async def async_step_mfa(
errors=errors,
)

async def async_finish(self, flow_result: Any) -> dict:
async def async_finish(self, flow_result: Any) -> FlowResultDict:
"""Handle the pass of login flow."""
return self.async_create_entry(title=self._auth_provider.name, data=flow_result)
6 changes: 4 additions & 2 deletions homeassistant/auth/providers/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import asyncio.subprocess
import collections
from collections.abc import Mapping
import logging
import os
from typing import Any, cast

import voluptuous as vol

from homeassistant.const import CONF_COMMAND
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import HomeAssistantError

from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow
Expand Down Expand Up @@ -100,7 +102,7 @@ async def async_validate_login(self, username: str, password: str) -> None:
self._user_meta[username] = meta

async def async_get_or_create_credentials(
self, flow_result: dict[str, str]
self, flow_result: Mapping[str, str]
) -> Credentials:
"""Get credentials based on the flow result."""
username = flow_result["username"]
Expand All @@ -127,7 +129,7 @@ class CommandLineLoginFlow(LoginFlow):

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the step of the form."""
errors = {}

Expand Down
6 changes: 4 additions & 2 deletions homeassistant/auth/providers/homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio
import base64
from collections import OrderedDict
from collections.abc import Mapping
import logging
from typing import Any, cast

Expand All @@ -12,6 +13,7 @@

from homeassistant.const import CONF_ID
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import HomeAssistantError

from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow
Expand Down Expand Up @@ -277,7 +279,7 @@ async def async_change_password(self, username: str, new_password: str) -> None:
await self.data.async_save()

async def async_get_or_create_credentials(
self, flow_result: dict[str, str]
self, flow_result: Mapping[str, str]
) -> Credentials:
"""Get credentials based on the flow result."""
if self.data is None:
Expand Down Expand Up @@ -319,7 +321,7 @@ class HassLoginFlow(LoginFlow):

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the step of the form."""
errors = {}

Expand Down
8 changes: 5 additions & 3 deletions homeassistant/auth/providers/insecure_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from __future__ import annotations

from collections import OrderedDict
from collections.abc import Mapping
import hmac
from typing import Any, cast
from typing import cast

import voluptuous as vol

from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import HomeAssistantError

from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow
Expand Down Expand Up @@ -62,7 +64,7 @@ def async_validate_login(self, username: str, password: str) -> None:
raise InvalidAuthError

async def async_get_or_create_credentials(
self, flow_result: dict[str, str]
self, flow_result: Mapping[str, str]
) -> Credentials:
"""Get credentials based on the flow result."""
username = flow_result["username"]
Expand Down Expand Up @@ -97,7 +99,7 @@ class ExampleLoginFlow(LoginFlow):

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the step of the form."""
errors = {}

Expand Down
8 changes: 5 additions & 3 deletions homeassistant/auth/providers/legacy_api_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"""
from __future__ import annotations

from collections.abc import Mapping
import hmac
from typing import Any, cast
from typing import cast

import voluptuous as vol

from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv

Expand Down Expand Up @@ -57,7 +59,7 @@ def async_validate_login(self, password: str) -> None:
raise InvalidAuthError

async def async_get_or_create_credentials(
self, flow_result: dict[str, str]
self, flow_result: Mapping[str, str]
) -> Credentials:
"""Return credentials for this login."""
credentials = await self.async_credentials()
Expand All @@ -82,7 +84,7 @@ class LegacyLoginFlow(LoginFlow):

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the step of the form."""
errors = {}

Expand Down
6 changes: 4 additions & 2 deletions homeassistant/auth/providers/trusted_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
from __future__ import annotations

from collections.abc import Mapping
from ipaddress import (
IPv4Address,
IPv4Network,
Expand All @@ -18,6 +19,7 @@
import voluptuous as vol

from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv

Expand Down Expand Up @@ -127,7 +129,7 @@ async def async_login_flow(self, context: dict | None) -> LoginFlow:
)

async def async_get_or_create_credentials(
self, flow_result: dict[str, str]
self, flow_result: Mapping[str, str]
) -> Credentials:
"""Get credentials based on the flow result."""
user_id = flow_result["user"]
Expand Down Expand Up @@ -199,7 +201,7 @@ def __init__(

async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle the step of the form."""
try:
cast(
Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/bond/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
HTTP_UNAUTHORIZED,
)
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import DiscoveryInfoType

Expand Down Expand Up @@ -91,7 +92,9 @@ async def _async_try_automatic_configure(self) -> None:
_, hub_name = await _validate_input(self.hass, self._discovered)
self._discovered[CONF_NAME] = hub_name

async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType) -> dict[str, Any]: # type: ignore
async def async_step_zeroconf( # type: ignore[override]
self, discovery_info: DiscoveryInfoType
) -> FlowResultDict:
"""Handle a flow initialized by zeroconf discovery."""
name: str = discovery_info[CONF_NAME]
host: str = discovery_info[CONF_HOST]
Expand All @@ -115,7 +118,7 @@ async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType) -> dict[s

async def async_step_confirm(
self, user_input: dict[str, Any] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle confirmation flow for discovered bond hub."""
errors = {}
if user_input is not None:
Expand Down Expand Up @@ -156,7 +159,7 @@ async def async_step_confirm(

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> dict[str, Any]:
) -> FlowResultDict:
"""Handle a flow initialized by the user."""
errors = {}
if user_input is not None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def get_core_info(hass):

@callback
@bind_hass
def is_hassio(hass):
def is_hassio(hass: HomeAssistant) -> bool:
"""Return true if Hass.io is loaded.

Async friendly.
Expand Down
Loading