Adjust config-flow type hints in vera (#72409)

* Adjust config-flow type hints in vera

* Reduce size of PR
pull/73167/head
epenet 2022-06-07 11:15:31 +02:00 committed by GitHub
parent a8763d7479
commit 6971bb8f5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 7 deletions

View File

@ -14,6 +14,7 @@ from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import entity_registry as er
from .const import CONF_CONTROLLER, CONF_LEGACY_UNIQUE_ID, DOMAIN
@ -37,12 +38,14 @@ def list_to_str(data: list[Any]) -> str:
return " ".join([str(i) for i in data])
def new_options(lights: list[int], exclude: list[int]) -> dict:
def new_options(lights: list[int], exclude: list[int]) -> dict[str, list[int]]:
"""Create a standard options object."""
return {CONF_LIGHTS: lights, CONF_EXCLUDE: exclude}
def options_schema(options: Mapping[str, Any] = None) -> dict:
def options_schema(
options: Mapping[str, Any] | None = None
) -> dict[vol.Optional, type[str]]:
"""Return options schema."""
options = options or {}
return {
@ -57,7 +60,7 @@ def options_schema(options: Mapping[str, Any] = None) -> dict:
}
def options_data(user_input: dict) -> dict:
def options_data(user_input: dict[str, str]) -> dict[str, list[int]]:
"""Return options dict."""
return new_options(
str_to_int_list(user_input.get(CONF_LIGHTS, "")),
@ -72,7 +75,10 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
"""Init object."""
self.config_entry = config_entry
async def async_step_init(self, user_input: dict = None):
async def async_step_init(
self,
user_input: dict[str, str] | None = None,
) -> FlowResult:
"""Manage the options."""
if user_input is not None:
return self.async_create_entry(
@ -95,7 +101,9 @@ class VeraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Get the options flow."""
return OptionsFlowHandler(config_entry)
async def async_step_user(self, user_input: dict = None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle user initiated flow."""
if user_input is not None:
return await self.async_step_finish(
@ -114,7 +122,7 @@ class VeraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
),
)
async def async_step_import(self, config: dict):
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
"""Handle a flow initialized by import."""
# If there are entities with the legacy unique_id, then this imported config
@ -139,7 +147,7 @@ class VeraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
}
)
async def async_step_finish(self, config: dict):
async def async_step_finish(self, config: dict[str, Any]) -> FlowResult:
"""Validate and create config entry."""
base_url = config[CONF_CONTROLLER] = config[CONF_CONTROLLER].rstrip("/")
controller = pv.VeraController(base_url)