Add some more VolDictType annotations (#120610)

This commit is contained in:
Marc Mueller 2024-06-26 22:44:43 +02:00 committed by GitHub
parent fcfb580f0c
commit 6bceb8ec48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 43 additions and 33 deletions

View File

@ -21,7 +21,7 @@ from homeassistant.const import (
)
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.typing import DiscoveryInfoType
from homeassistant.helpers.typing import DiscoveryInfoType, VolDictType
from homeassistant.util import slugify
from homeassistant.util.network import is_ip_address
@ -52,7 +52,7 @@ PROTOCOL_MAP = {
VALIDATE_TIMEOUT = 35
BASE_SCHEMA = {
BASE_SCHEMA: VolDictType = {
vol.Optional(CONF_USERNAME, default=""): str,
vol.Optional(CONF_PASSWORD, default=""): str,
}

View File

@ -33,6 +33,7 @@ from homeassistant.const import (
CONF_USERNAME,
)
from homeassistant.core import callback
from homeassistant.helpers.typing import VolDictType
from .const import (
CONF_OLD_DISCOVERY,
@ -210,7 +211,7 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN):
) -> ConfigFlowResult:
"""Show the setup form to the user."""
advanced_data_schema = {}
advanced_data_schema: VolDictType = {}
if self.show_advanced_options:
advanced_data_schema = {
vol.Optional(CONF_PORT): vol.Coerce(int),
@ -348,7 +349,7 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any], errors: dict[str, str] | None = None
) -> ConfigFlowResult:
"""Show the reconfigure form to the user."""
advanced_data_schema = {}
advanced_data_schema: VolDictType = {}
if self.show_advanced_options:
advanced_data_schema = {
vol.Optional(CONF_PORT, default=user_input[CONF_PORT]): vol.Coerce(int),

View File

@ -61,7 +61,7 @@ from homeassistant.helpers.event import (
)
from homeassistant.helpers.reload import async_setup_reload_service
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, VolDictType
from . import DOMAIN, PLATFORMS
@ -96,6 +96,10 @@ CONF_PRESETS = {
)
}
PRESETS_SCHEMA: VolDictType = {
vol.Optional(v): vol.Coerce(float) for v in CONF_PRESETS.values()
}
PLATFORM_SCHEMA_COMMON = vol.Schema(
{
vol.Required(CONF_HEATER): cv.entity_id,
@ -120,7 +124,7 @@ PLATFORM_SCHEMA_COMMON = vol.Schema(
vol.In([PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE])
),
vol.Optional(CONF_UNIQUE_ID): cv.string,
**{vol.Optional(v): vol.Coerce(float) for v in CONF_PRESETS.values()},
**PRESETS_SCHEMA,
}
)

View File

@ -29,6 +29,7 @@ from homeassistant.helpers.schema_config_entry_flow import (
SchemaOptionsFlowHandler,
)
from homeassistant.helpers.selector import TextSelector
from homeassistant.helpers.typing import VolDictType
from homeassistant.util import slugify
from . import DEFAULT_FADE_RATE, calculate_unique_id
@ -62,7 +63,7 @@ CONTROLLER_EDIT = {
),
}
LIGHT_EDIT = {
LIGHT_EDIT: VolDictType = {
vol.Optional(CONF_RATE, default=DEFAULT_FADE_RATE): selector.NumberSelector(
selector.NumberSelectorConfig(
min=0,
@ -73,7 +74,7 @@ LIGHT_EDIT = {
),
}
BUTTON_EDIT = {
BUTTON_EDIT: VolDictType = {
vol.Optional(CONF_LED, default=False): selector.BooleanSelector(),
vol.Optional(CONF_RELEASE_DELAY, default=0): selector.NumberSelector(
selector.NumberSelectorConfig(

View File

@ -24,6 +24,7 @@ from homeassistant.const import (
)
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import VolDictType
from .const import (
CONF_CONSIDER_HOME,
@ -84,7 +85,7 @@ class KeeneticFlowHandler(ConfigFlow, domain=DOMAIN):
title=router_info.name, data={CONF_HOST: host, **user_input}
)
host_schema = (
host_schema: VolDictType = (
{vol.Required(CONF_HOST): str} if CONF_HOST not in self.context else {}
)

View File

@ -21,6 +21,7 @@ from homeassistant.const import (
UnitOfTemperature,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import VolDictType
from .const import (
BINSENSOR_PORTS,
@ -61,14 +62,14 @@ from .helpers import has_unique_host_names, is_address
# Domain data
#
DOMAIN_DATA_BINARY_SENSOR = {
DOMAIN_DATA_BINARY_SENSOR: VolDictType = {
vol.Required(CONF_SOURCE): vol.All(
vol.Upper, vol.In(SETPOINTS + KEYS + BINSENSOR_PORTS)
),
}
DOMAIN_DATA_CLIMATE = {
DOMAIN_DATA_CLIMATE: VolDictType = {
vol.Required(CONF_SOURCE): vol.All(vol.Upper, vol.In(VARIABLES)),
vol.Required(CONF_SETPOINT): vol.All(vol.Upper, vol.In(VARIABLES + SETPOINTS)),
vol.Optional(CONF_MAX_TEMP, default=DEFAULT_MAX_TEMP): vol.Coerce(float),
@ -80,7 +81,7 @@ DOMAIN_DATA_CLIMATE = {
}
DOMAIN_DATA_COVER = {
DOMAIN_DATA_COVER: VolDictType = {
vol.Required(CONF_MOTOR): vol.All(vol.Upper, vol.In(MOTOR_PORTS)),
vol.Optional(CONF_REVERSE_TIME, default="rt1200"): vol.All(
vol.Upper, vol.In(MOTOR_REVERSE_TIME)
@ -88,7 +89,7 @@ DOMAIN_DATA_COVER = {
}
DOMAIN_DATA_LIGHT = {
DOMAIN_DATA_LIGHT: VolDictType = {
vol.Required(CONF_OUTPUT): vol.All(vol.Upper, vol.In(OUTPUT_PORTS + RELAY_PORTS)),
vol.Optional(CONF_DIMMABLE, default=False): vol.Coerce(bool),
vol.Optional(CONF_TRANSITION, default=0): vol.All(
@ -97,7 +98,7 @@ DOMAIN_DATA_LIGHT = {
}
DOMAIN_DATA_SCENE = {
DOMAIN_DATA_SCENE: VolDictType = {
vol.Required(CONF_REGISTER): vol.All(vol.Coerce(int), vol.Range(0, 9)),
vol.Required(CONF_SCENE): vol.All(vol.Coerce(int), vol.Range(0, 9)),
vol.Optional(CONF_OUTPUTS, default=[]): vol.All(
@ -113,7 +114,7 @@ DOMAIN_DATA_SCENE = {
),
}
DOMAIN_DATA_SENSOR = {
DOMAIN_DATA_SENSOR: VolDictType = {
vol.Required(CONF_SOURCE): vol.All(
vol.Upper,
vol.In(
@ -126,7 +127,7 @@ DOMAIN_DATA_SENSOR = {
}
DOMAIN_DATA_SWITCH = {
DOMAIN_DATA_SWITCH: VolDictType = {
vol.Required(CONF_OUTPUT): vol.All(vol.Upper, vol.In(OUTPUT_PORTS + RELAY_PORTS)),
}
@ -134,7 +135,7 @@ DOMAIN_DATA_SWITCH = {
# Configuration
#
DOMAIN_DATA_BASE = {
DOMAIN_DATA_BASE: VolDictType = {
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_ADDRESS): is_address,
}

View File

@ -299,7 +299,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
def preprocess_turn_on_alternatives(
hass: HomeAssistant, params: dict[str, Any] | dict[str | vol.Optional, Any]
hass: HomeAssistant, params: dict[str, Any] | VolDictType
) -> None:
"""Process extra data for turn light on request.
@ -403,11 +403,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
# of the light base platform.
hass.async_create_task(profiles.async_initialize(), eager_start=True)
def preprocess_data(
data: dict[str | vol.Optional, Any],
) -> dict[str | vol.Optional, Any]:
def preprocess_data(data: VolDictType) -> VolDictType:
"""Preprocess the service data."""
base: dict[str | vol.Optional, Any] = {
base: VolDictType = {
entity_field: data.pop(entity_field)
for entity_field in cv.ENTITY_SERVICE_FIELDS
if entity_field in data

View File

@ -12,6 +12,7 @@ from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.const import CONF_PORT
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.typing import VolDictType
from .const import (
CONF_SOURCE_1,
@ -35,7 +36,7 @@ SOURCES = [
CONF_SOURCE_6,
]
OPTIONS_FOR_DATA = {vol.Optional(source): str for source in SOURCES}
OPTIONS_FOR_DATA: VolDictType = {vol.Optional(source): str for source in SOURCES}
DATA_SCHEMA = vol.Schema({vol.Required(CONF_PORT): str, **OPTIONS_FOR_DATA})

View File

@ -24,6 +24,7 @@ from homeassistant.const import CONF_SOURCE, CONF_URL, CONF_WEBHOOK_ID
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import VolDictType
from . import create_motioneye_client
from .const import (
@ -55,7 +56,7 @@ class MotionEyeConfigFlow(ConfigFlow, domain=DOMAIN):
user_input: dict[str, Any], errors: dict[str, str] | None = None
) -> ConfigFlowResult:
"""Show the form to the user."""
url_schema: dict[vol.Required, type[str]] = {}
url_schema: VolDictType = {}
if not self._hassio_discovery:
# Only ask for URL when not discovered
url_schema[

View File

@ -17,6 +17,7 @@ from homeassistant.core import callback
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import VolDictType
from .const import (
_LOGGER,
@ -137,14 +138,16 @@ class NinaConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "no_selection"
regions_schema: VolDictType = {
vol.Optional(region): cv.multi_select(self.regions[region])
for region in CONST_REGIONS
}
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
**{
vol.Optional(region): cv.multi_select(self.regions[region])
for region in CONST_REGIONS
},
**regions_schema,
vol.Required(CONF_MESSAGE_SLOTS, default=5): vol.All(
int, vol.Range(min=1, max=20)
),

View File

@ -22,6 +22,7 @@ from homeassistant.config_entries import (
from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE
from homeassistant.core import callback
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.typing import VolDictType
from .const import CONF_CONTROLLER, CONF_LEGACY_UNIQUE_ID, DOMAIN
@ -49,9 +50,7 @@ def new_options(lights: list[int], exclude: list[int]) -> dict[str, list[int]]:
return {CONF_LIGHTS: lights, CONF_EXCLUDE: exclude}
def options_schema(
options: Mapping[str, Any] | None = None,
) -> dict[vol.Optional, type[str]]:
def options_schema(options: Mapping[str, Any] | None = None) -> VolDictType:
"""Return options schema."""
options = options or {}
return {

View File

@ -1204,7 +1204,7 @@ PLATFORM_SCHEMA = vol.Schema(
PLATFORM_SCHEMA_BASE = PLATFORM_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA)
ENTITY_SERVICE_FIELDS = {
ENTITY_SERVICE_FIELDS: VolDictType = {
# Either accept static entity IDs, a single dynamic template or a mixed list
# of static and dynamic templates. While this could be solved with a single
# complex template, handling it like this, keeps config validation useful.
@ -1310,7 +1310,7 @@ def script_action(value: Any) -> dict:
SCRIPT_SCHEMA = vol.All(ensure_list, [script_action])
SCRIPT_ACTION_BASE_SCHEMA = {
SCRIPT_ACTION_BASE_SCHEMA: VolDictType = {
vol.Optional(CONF_ALIAS): string,
vol.Optional(CONF_CONTINUE_ON_ERROR): boolean,
vol.Optional(CONF_ENABLED): vol.Any(boolean, template),