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