mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Adjust config-flow type hints in vera (#72409)
* Adjust config-flow type hints in vera * Reduce size of PR
This commit is contained in:
parent
a8763d7479
commit
6971bb8f5b
@ -14,6 +14,7 @@ from homeassistant import config_entries
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE
|
from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .const import CONF_CONTROLLER, CONF_LEGACY_UNIQUE_ID, DOMAIN
|
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])
|
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."""
|
"""Create a standard options object."""
|
||||||
return {CONF_LIGHTS: lights, CONF_EXCLUDE: exclude}
|
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."""
|
"""Return options schema."""
|
||||||
options = options or {}
|
options = options or {}
|
||||||
return {
|
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 options dict."""
|
||||||
return new_options(
|
return new_options(
|
||||||
str_to_int_list(user_input.get(CONF_LIGHTS, "")),
|
str_to_int_list(user_input.get(CONF_LIGHTS, "")),
|
||||||
@ -72,7 +75,10 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
"""Init object."""
|
"""Init object."""
|
||||||
self.config_entry = config_entry
|
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."""
|
"""Manage the options."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
@ -95,7 +101,9 @@ class VeraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Get the options flow."""
|
"""Get the options flow."""
|
||||||
return OptionsFlowHandler(config_entry)
|
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."""
|
"""Handle user initiated flow."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return await self.async_step_finish(
|
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."""
|
"""Handle a flow initialized by import."""
|
||||||
|
|
||||||
# If there are entities with the legacy unique_id, then this imported config
|
# 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."""
|
"""Validate and create config entry."""
|
||||||
base_url = config[CONF_CONTROLLER] = config[CONF_CONTROLLER].rstrip("/")
|
base_url = config[CONF_CONTROLLER] = config[CONF_CONTROLLER].rstrip("/")
|
||||||
controller = pv.VeraController(base_url)
|
controller = pv.VeraController(base_url)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user