Improve type hints in konnected config flow (#124904)

This commit is contained in:
epenet 2024-08-30 11:24:06 +02:00 committed by GitHub
parent 9e2360791d
commit ffabd5d7db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,7 +7,7 @@ import copy
import logging
import random
import string
from typing import Any
from typing import TYPE_CHECKING, Any
from urllib.parse import urlparse
import voluptuous as vol
@ -227,8 +227,12 @@ class KonnectedFlowHandler(ConfigFlow, domain=DOMAIN):
self._abort_if_unique_id_configured()
return await self.async_step_import_confirm()
async def async_step_import_confirm(self, user_input=None):
async def async_step_import_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Confirm the user wants to import the config entry."""
if TYPE_CHECKING:
assert self.unique_id is not None
if user_input is None:
return self.async_show_form(
step_id="import_confirm",
@ -349,7 +353,9 @@ class KonnectedFlowHandler(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_confirm(self, user_input=None):
async def async_step_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Attempt to link with the Konnected panel.
Given a configured host, will ask the user to confirm and finalize
@ -401,8 +407,8 @@ class OptionsFlowHandler(OptionsFlow):
self.current_opt = self.entry.options or self.entry.data[CONF_DEFAULT_OPTIONS]
# as config proceeds we'll build up new options and then replace what's in the config entry
self.new_opt: dict[str, dict[str, Any]] = {CONF_IO: {}}
self.active_cfg = None
self.new_opt: dict[str, Any] = {CONF_IO: {}}
self.active_cfg: str | None = None
self.io_cfg: dict[str, Any] = {}
self.current_states: list[dict[str, Any]] = []
self.current_state = 1
@ -419,13 +425,17 @@ class OptionsFlowHandler(OptionsFlow):
{},
)
async def async_step_init(self, user_input=None):
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle options flow."""
return await self.async_step_options_io()
async def async_step_options_io(self, user_input=None):
async def async_step_options_io(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Configure legacy panel IO or first half of pro IO."""
errors = {}
errors: dict[str, str] = {}
current_io = self.current_opt.get(CONF_IO, {})
if user_input is not None:
@ -508,9 +518,11 @@ class OptionsFlowHandler(OptionsFlow):
return self.async_abort(reason="not_konn_panel")
async def async_step_options_io_ext(self, user_input=None):
async def async_step_options_io_ext(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Allow the user to configure the extended IO for pro."""
errors = {}
errors: dict[str, str] = {}
current_io = self.current_opt.get(CONF_IO, {})
if user_input is not None:
@ -566,10 +578,12 @@ class OptionsFlowHandler(OptionsFlow):
return self.async_abort(reason="not_konn_panel")
async def async_step_options_binary(self, user_input=None):
async def async_step_options_binary(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Allow the user to configure the IO options for binary sensors."""
errors = {}
if user_input is not None:
errors: dict[str, str] = {}
if user_input is not None and self.active_cfg is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
self.new_opt[CONF_BINARY_SENSORS] = [
@ -602,7 +616,7 @@ class OptionsFlowHandler(OptionsFlow):
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper
else self.active_cfg.upper()
},
errors=errors,
)
@ -635,17 +649,19 @@ class OptionsFlowHandler(OptionsFlow):
description_placeholders={
"zone": f"Zone {self.active_cfg}"
if len(self.active_cfg) < 3
else self.active_cfg.upper
else self.active_cfg.upper()
},
errors=errors,
)
return await self.async_step_options_digital()
async def async_step_options_digital(self, user_input=None):
async def async_step_options_digital(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Allow the user to configure the IO options for digital sensors."""
errors = {}
if user_input is not None:
errors: dict[str, str] = {}
if user_input is not None and self.active_cfg is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
self.new_opt[CONF_SENSORS] = [*self.new_opt.get(CONF_SENSORS, []), zone]
@ -710,10 +726,12 @@ class OptionsFlowHandler(OptionsFlow):
return await self.async_step_options_switch()
async def async_step_options_switch(self, user_input=None):
async def async_step_options_switch(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Allow the user to configure the IO options for switches."""
errors = {}
if user_input is not None:
errors: dict[str, str] = {}
if user_input is not None and self.active_cfg is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
del zone[CONF_MORE_STATES]
@ -825,7 +843,9 @@ class OptionsFlowHandler(OptionsFlow):
return await self.async_step_options_misc()
async def async_step_options_misc(self, user_input=None):
async def async_step_options_misc(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Allow the user to configure the LED behavior."""
errors = {}
if user_input is not None: