Improve config flow type hints (n-p) (#124909)
This commit is contained in:
parent
4940968cd5
commit
6833af6286
10 changed files with 81 additions and 38 deletions
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import aiohttp
|
||||
from pyoctoprintapi import ApiError, OctoprintClient, OctoprintException
|
||||
|
@ -104,7 +104,9 @@ class OctoPrintConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self._user_input = user_input
|
||||
return await self.async_step_get_api_key()
|
||||
|
||||
async def async_step_get_api_key(self, user_input=None):
|
||||
async def async_step_get_api_key(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Get an Application Api Key."""
|
||||
if not self.api_key_task:
|
||||
self.api_key_task = self.hass.async_create_task(
|
||||
|
@ -130,7 +132,7 @@ class OctoPrintConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
return self.async_show_progress_done(next_step_id="user")
|
||||
|
||||
async def _finish_config(self, user_input: dict):
|
||||
async def _finish_config(self, user_input: dict[str, Any]) -> ConfigFlowResult:
|
||||
"""Finish the configuration setup."""
|
||||
existing_entry = await self.async_set_unique_id(self.unique_id)
|
||||
if existing_entry is not None:
|
||||
|
@ -156,7 +158,7 @@ class OctoPrintConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
return self.async_create_entry(title=user_input[CONF_HOST], data=user_input)
|
||||
|
||||
async def async_step_auth_failed(self, user_input):
|
||||
async def async_step_auth_failed(self, user_input: None) -> ConfigFlowResult:
|
||||
"""Handle api fetch failure."""
|
||||
return self.async_abort(reason="auth_failed")
|
||||
|
||||
|
@ -252,15 +254,17 @@ class OctoPrintConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self._user_input = self._reauth_data
|
||||
return await self.async_step_get_api_key()
|
||||
|
||||
async def _async_get_auth_key(self):
|
||||
async def _async_get_auth_key(self) -> None:
|
||||
"""Get application api key."""
|
||||
if TYPE_CHECKING:
|
||||
assert self._user_input is not None
|
||||
octoprint = self._get_octoprint_client(self._user_input)
|
||||
|
||||
self._user_input[CONF_API_KEY] = await octoprint.request_app_key(
|
||||
"Home Assistant", self._user_input[CONF_USERNAME], 300
|
||||
)
|
||||
|
||||
def _get_octoprint_client(self, user_input: dict) -> OctoprintClient:
|
||||
def _get_octoprint_client(self, user_input: dict[str, Any]) -> OctoprintClient:
|
||||
"""Build an octoprint client from the user_input."""
|
||||
verify_ssl = user_input.get(CONF_VERIFY_SSL, True)
|
||||
|
||||
|
@ -281,7 +285,7 @@ class OctoPrintConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
path=user_input[CONF_PATH],
|
||||
)
|
||||
|
||||
def async_remove(self):
|
||||
def async_remove(self) -> None:
|
||||
"""Detach the session."""
|
||||
for session in self._sessions:
|
||||
session.detach()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue