mirror of https://github.com/home-assistant/core
Strictly type tradfri config_flow.py (#56391)
* Strictly type config_flow.py. * Review comments.
This commit is contained in:
parent
56b66d5124
commit
34de74d869
|
@ -106,6 +106,7 @@ homeassistant.components.systemmonitor.*
|
|||
homeassistant.components.tag.*
|
||||
homeassistant.components.tcp.*
|
||||
homeassistant.components.tile.*
|
||||
homeassistant.components.tradfri.*
|
||||
homeassistant.components.tts.*
|
||||
homeassistant.components.upcloud.*
|
||||
homeassistant.components.uptime.*
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
"""Config flow for Tradfri."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
import async_timeout
|
||||
|
@ -8,6 +11,9 @@ from pytradfri.api.aiocoap_api import APIFactory
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
|
||||
from .const import (
|
||||
CONF_GATEWAY_ID,
|
||||
|
@ -23,7 +29,7 @@ from .const import (
|
|||
class AuthError(Exception):
|
||||
"""Exception if authentication occurs."""
|
||||
|
||||
def __init__(self, code):
|
||||
def __init__(self, code: str) -> None:
|
||||
"""Initialize exception."""
|
||||
super().__init__()
|
||||
self.code = code
|
||||
|
@ -34,18 +40,22 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
"""Initialize flow."""
|
||||
self._host = None
|
||||
self._import_groups = False
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle a flow initialized by the user."""
|
||||
return await self.async_step_auth()
|
||||
|
||||
async def async_step_auth(self, user_input=None):
|
||||
async def async_step_auth(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle the authentication with a gateway."""
|
||||
errors = {}
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input is not None:
|
||||
host = user_input.get(CONF_HOST, self._host)
|
||||
|
@ -82,7 +92,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="auth", data_schema=vol.Schema(fields), errors=errors
|
||||
)
|
||||
|
||||
async def async_step_homekit(self, discovery_info):
|
||||
async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult:
|
||||
"""Handle homekit discovery."""
|
||||
await self.async_set_unique_id(discovery_info["properties"]["id"])
|
||||
self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]})
|
||||
|
@ -104,7 +114,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self._host = host
|
||||
return await self.async_step_auth()
|
||||
|
||||
async def async_step_import(self, user_input):
|
||||
async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult:
|
||||
"""Import a config entry."""
|
||||
self._async_abort_entries_match({CONF_HOST: user_input["host"]})
|
||||
|
||||
|
@ -131,7 +141,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self._host = user_input["host"]
|
||||
return await self.async_step_auth()
|
||||
|
||||
async def _entry_from_data(self, data):
|
||||
async def _entry_from_data(self, data: dict[str, Any]) -> FlowResult:
|
||||
"""Create an entry from data."""
|
||||
host = data[CONF_HOST]
|
||||
gateway_id = data[CONF_GATEWAY_ID]
|
||||
|
@ -154,7 +164,9 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
return self.async_create_entry(title=host, data=data)
|
||||
|
||||
|
||||
async def authenticate(hass, host, security_code):
|
||||
async def authenticate(
|
||||
hass: HomeAssistant, host: str, security_code: str
|
||||
) -> dict[str, str | bool]:
|
||||
"""Authenticate with a Tradfri hub."""
|
||||
|
||||
identity = uuid4().hex
|
||||
|
@ -174,7 +186,9 @@ async def authenticate(hass, host, security_code):
|
|||
return await get_gateway_info(hass, host, identity, key)
|
||||
|
||||
|
||||
async def get_gateway_info(hass, host, identity, key):
|
||||
async def get_gateway_info(
|
||||
hass: HomeAssistant, host: str, identity: str, key: str
|
||||
) -> dict[str, str | bool]:
|
||||
"""Return info for the gateway."""
|
||||
|
||||
try:
|
||||
|
|
11
mypy.ini
11
mypy.ini
|
@ -1177,6 +1177,17 @@ no_implicit_optional = true
|
|||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.tradfri.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
no_implicit_optional = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.tts.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
|
Loading…
Reference in New Issue