Improve collection schema typing (#120441)

This commit is contained in:
Marc Mueller 2024-06-25 18:57:15 +02:00 committed by GitHub
parent 197062139e
commit b393024acd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 49 additions and 48 deletions

View File

@ -29,7 +29,7 @@ from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import collection, config_entry_oauth2_flow from homeassistant.helpers import collection, config_entry_oauth2_flow
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.loader import ( from homeassistant.loader import (
IntegrationNotFound, IntegrationNotFound,
async_get_application_credentials, async_get_application_credentials,
@ -49,14 +49,14 @@ DATA_STORAGE = "storage"
CONF_AUTH_DOMAIN = "auth_domain" CONF_AUTH_DOMAIN = "auth_domain"
DEFAULT_IMPORT_NAME = "Import from configuration.yaml" DEFAULT_IMPORT_NAME = "Import from configuration.yaml"
CREATE_FIELDS = { CREATE_FIELDS: VolDictType = {
vol.Required(CONF_DOMAIN): cv.string, vol.Required(CONF_DOMAIN): cv.string,
vol.Required(CONF_CLIENT_ID): vol.All(cv.string, vol.Strip), vol.Required(CONF_CLIENT_ID): vol.All(cv.string, vol.Strip),
vol.Required(CONF_CLIENT_SECRET): vol.All(cv.string, vol.Strip), vol.Required(CONF_CLIENT_SECRET): vol.All(cv.string, vol.Strip),
vol.Optional(CONF_AUTH_DOMAIN): cv.string, vol.Optional(CONF_AUTH_DOMAIN): cv.string,
vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_NAME): cv.string,
} }
UPDATE_FIELDS: dict = {} # Not supported UPDATE_FIELDS: VolDictType = {} # Not supported
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)

View File

@ -45,7 +45,7 @@ from homeassistant.helpers.collection import (
) )
from homeassistant.helpers.singleton import singleton from homeassistant.helpers.singleton import singleton
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import UNDEFINED, UndefinedType from homeassistant.helpers.typing import UNDEFINED, UndefinedType, VolDictType
from homeassistant.util import ( from homeassistant.util import (
dt as dt_util, dt as dt_util,
language as language_util, language as language_util,
@ -94,7 +94,7 @@ def validate_language(data: dict[str, Any]) -> Any:
return data return data
PIPELINE_FIELDS = { PIPELINE_FIELDS: VolDictType = {
vol.Required("conversation_engine"): str, vol.Required("conversation_engine"): str,
vol.Required("conversation_language"): str, vol.Required("conversation_language"): str,
vol.Required("language"): str, vol.Required("language"): str,

View File

@ -21,7 +21,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -49,7 +49,7 @@ SERVICE_SET_VALUE = "set_value"
STORAGE_KEY = DOMAIN STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1 STORAGE_VERSION = 1
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ICON): cv.icon,
vol.Optional(CONF_INITIAL, default=DEFAULT_INITIAL): cv.positive_int, vol.Optional(CONF_INITIAL, default=DEFAULT_INITIAL): cv.positive_int,
vol.Required(CONF_NAME): vol.All(cv.string, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(cv.string, vol.Length(min=1)),

View File

@ -21,7 +21,7 @@ from homeassistant.const import CONF_ID
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import collection, config_validation as cv from homeassistant.helpers import collection, config_validation as cv
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from .const import DOMAIN from .const import DOMAIN
@ -32,11 +32,11 @@ STORAGE_VERSION = 1
VALID_SIZES = {256, 512} VALID_SIZES = {256, 512}
MAX_SIZE = 1024 * 1024 * 10 MAX_SIZE = 1024 * 1024 * 10
CREATE_FIELDS = { CREATE_FIELDS: VolDictType = {
vol.Required("file"): FileField, vol.Required("file"): FileField,
} }
UPDATE_FIELDS = { UPDATE_FIELDS: VolDictType = {
vol.Optional("name"): vol.All(str, vol.Length(min=1)), vol.Optional("name"): vol.All(str, vol.Length(min=1)),
} }

View File

@ -26,7 +26,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.helpers.service import homeassistant.helpers.service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
DOMAIN = "input_boolean" DOMAIN = "input_boolean"
@ -35,7 +35,7 @@ _LOGGER = logging.getLogger(__name__)
CONF_INITIAL = "initial" CONF_INITIAL = "initial"
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional(CONF_INITIAL): cv.boolean, vol.Optional(CONF_INITIAL): cv.boolean,
vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ICON): cv.icon,

View File

@ -22,13 +22,13 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.helpers.service import homeassistant.helpers.service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
DOMAIN = "input_button" DOMAIN = "input_button"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ICON): cv.icon,
} }

View File

@ -24,7 +24,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.helpers.service import homeassistant.helpers.service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -59,7 +59,7 @@ def validate_set_datetime_attrs(config):
STORAGE_KEY = DOMAIN STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1 STORAGE_VERSION = 1
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional(CONF_HAS_DATE, default=False): cv.boolean, vol.Optional(CONF_HAS_DATE, default=False): cv.boolean,
vol.Optional(CONF_HAS_TIME, default=False): cv.boolean, vol.Optional(CONF_HAS_TIME, default=False): cv.boolean,

View File

@ -25,7 +25,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.helpers.service import homeassistant.helpers.service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -64,7 +64,7 @@ def _cv_input_number(cfg):
return cfg return cfg
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Required(CONF_MIN): vol.Coerce(float), vol.Required(CONF_MIN): vol.Coerce(float),
vol.Required(CONF_MAX): vol.Coerce(float), vol.Required(CONF_MAX): vol.Coerce(float),

View File

@ -33,7 +33,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.helpers.service import homeassistant.helpers.service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -55,7 +55,7 @@ def _unique(options: Any) -> Any:
raise HomeAssistantError("Duplicate options are not allowed") from exc raise HomeAssistantError("Duplicate options are not allowed") from exc
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Required(CONF_OPTIONS): vol.All( vol.Required(CONF_OPTIONS): vol.All(
cv.ensure_list, vol.Length(min=1), _unique, [cv.string] cv.ensure_list, vol.Length(min=1), _unique, [cv.string]

View File

@ -24,7 +24,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.helpers.service import homeassistant.helpers.service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -50,7 +50,7 @@ SERVICE_SET_VALUE = "set_value"
STORAGE_KEY = DOMAIN STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1 STORAGE_VERSION = 1
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional(CONF_MIN, default=CONF_MIN_VALUE): vol.Coerce(int), vol.Optional(CONF_MIN, default=CONF_MIN_VALUE): vol.Coerce(int),
vol.Optional(CONF_MAX, default=CONF_MAX_VALUE): vol.Coerce(int), vol.Optional(CONF_MAX, default=CONF_MAX_VALUE): vol.Coerce(int),

View File

@ -13,6 +13,7 @@ from homeassistant.const import (
) )
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import VolDictType
from homeassistant.util import slugify from homeassistant.util import slugify
DOMAIN = "lovelace" DOMAIN = "lovelace"
@ -37,12 +38,12 @@ RESOURCE_FIELDS = {
RESOURCE_SCHEMA = vol.Schema(RESOURCE_FIELDS) RESOURCE_SCHEMA = vol.Schema(RESOURCE_FIELDS)
RESOURCE_CREATE_FIELDS = { RESOURCE_CREATE_FIELDS: VolDictType = {
vol.Required(CONF_RESOURCE_TYPE_WS): vol.In(RESOURCE_TYPES), vol.Required(CONF_RESOURCE_TYPE_WS): vol.In(RESOURCE_TYPES),
vol.Required(CONF_URL): cv.string, vol.Required(CONF_URL): cv.string,
} }
RESOURCE_UPDATE_FIELDS = { RESOURCE_UPDATE_FIELDS: VolDictType = {
vol.Optional(CONF_RESOURCE_TYPE_WS): vol.In(RESOURCE_TYPES), vol.Optional(CONF_RESOURCE_TYPE_WS): vol.In(RESOURCE_TYPES),
vol.Optional(CONF_URL): cv.string, vol.Optional(CONF_URL): cv.string,
} }
@ -54,7 +55,7 @@ CONF_TITLE = "title"
CONF_REQUIRE_ADMIN = "require_admin" CONF_REQUIRE_ADMIN = "require_admin"
CONF_SHOW_IN_SIDEBAR = "show_in_sidebar" CONF_SHOW_IN_SIDEBAR = "show_in_sidebar"
DASHBOARD_BASE_CREATE_FIELDS = { DASHBOARD_BASE_CREATE_FIELDS: VolDictType = {
vol.Optional(CONF_REQUIRE_ADMIN, default=False): cv.boolean, vol.Optional(CONF_REQUIRE_ADMIN, default=False): cv.boolean,
vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ICON): cv.icon,
vol.Required(CONF_TITLE): cv.string, vol.Required(CONF_TITLE): cv.string,
@ -62,7 +63,7 @@ DASHBOARD_BASE_CREATE_FIELDS = {
} }
DASHBOARD_BASE_UPDATE_FIELDS = { DASHBOARD_BASE_UPDATE_FIELDS: VolDictType = {
vol.Optional(CONF_REQUIRE_ADMIN): cv.boolean, vol.Optional(CONF_REQUIRE_ADMIN): cv.boolean,
vol.Optional(CONF_ICON): vol.Any(cv.icon, None), vol.Optional(CONF_ICON): vol.Any(cv.icon, None),
vol.Optional(CONF_TITLE): cv.string, vol.Optional(CONF_TITLE): cv.string,
@ -70,7 +71,7 @@ DASHBOARD_BASE_UPDATE_FIELDS = {
} }
STORAGE_DASHBOARD_CREATE_FIELDS = { STORAGE_DASHBOARD_CREATE_FIELDS: VolDictType = {
**DASHBOARD_BASE_CREATE_FIELDS, **DASHBOARD_BASE_CREATE_FIELDS,
vol.Required(CONF_URL_PATH): cv.string, vol.Required(CONF_URL_PATH): cv.string,
# For now we write "storage" as all modes. # For now we write "storage" as all modes.

View File

@ -50,7 +50,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import async_track_state_change_event from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from .const import DOMAIN from .const import DOMAIN
@ -165,7 +165,7 @@ def entities_in_person(hass: HomeAssistant, entity_id: str) -> list[str]:
return person_entity.device_trackers return person_entity.device_trackers
CREATE_FIELDS = { CREATE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional(CONF_USER_ID): vol.Any(str, None), vol.Optional(CONF_USER_ID): vol.Any(str, None),
vol.Optional(CONF_DEVICE_TRACKERS, default=list): vol.All( vol.Optional(CONF_DEVICE_TRACKERS, default=list): vol.All(
@ -175,7 +175,7 @@ CREATE_FIELDS = {
} }
UPDATE_FIELDS = { UPDATE_FIELDS: VolDictType = {
vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional(CONF_USER_ID): vol.Any(str, None), vol.Optional(CONF_USER_ID): vol.Any(str, None),
vol.Optional(CONF_DEVICE_TRACKERS, default=list): vol.All( vol.Optional(CONF_DEVICE_TRACKERS, default=list): vol.All(

View File

@ -33,7 +33,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import async_track_point_in_utc_time from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.helpers.service import async_register_admin_service from homeassistant.helpers.service import async_register_admin_service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from .const import ( from .const import (
@ -104,12 +104,12 @@ def serialize_to_time(value: Any) -> Any:
return vol.Coerce(str)(value) return vol.Coerce(str)(value)
BASE_SCHEMA = { BASE_SCHEMA: VolDictType = {
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ICON): cv.icon,
} }
TIME_RANGE_SCHEMA = { TIME_RANGE_SCHEMA: VolDictType = {
vol.Required(CONF_FROM): cv.time, vol.Required(CONF_FROM): cv.time,
vol.Required(CONF_TO): deserialize_to_time, vol.Required(CONF_TO): deserialize_to_time,
} }
@ -122,13 +122,13 @@ STORAGE_TIME_RANGE_SCHEMA = vol.Schema(
} }
) )
SCHEDULE_SCHEMA = { SCHEDULE_SCHEMA: VolDictType = {
vol.Optional(day, default=[]): vol.All( vol.Optional(day, default=[]): vol.All(
cv.ensure_list, [TIME_RANGE_SCHEMA], valid_schedule cv.ensure_list, [TIME_RANGE_SCHEMA], valid_schedule
) )
for day in CONF_ALL_DAYS for day in CONF_ALL_DAYS
} }
STORAGE_SCHEDULE_SCHEMA = { STORAGE_SCHEDULE_SCHEMA: VolDictType = {
vol.Optional(day, default=[]): vol.All( vol.Optional(day, default=[]): vol.All(
cv.ensure_list, [TIME_RANGE_SCHEMA], valid_schedule, [STORAGE_TIME_RANGE_SCHEMA] cv.ensure_list, [TIME_RANGE_SCHEMA], valid_schedule, [STORAGE_TIME_RANGE_SCHEMA]
) )

View File

@ -18,7 +18,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.util import slugify from homeassistant.util import slugify
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from homeassistant.util.hass_dict import HassKey from homeassistant.util.hass_dict import HassKey
@ -35,7 +35,7 @@ STORAGE_VERSION_MINOR = 3
TAG_DATA: HassKey[TagStorageCollection] = HassKey(DOMAIN) TAG_DATA: HassKey[TagStorageCollection] = HassKey(DOMAIN)
CREATE_FIELDS = { CREATE_FIELDS: VolDictType = {
vol.Optional(TAG_ID): cv.string, vol.Optional(TAG_ID): cv.string,
vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional("description"): cv.string, vol.Optional("description"): cv.string,
@ -43,7 +43,7 @@ CREATE_FIELDS = {
vol.Optional(DEVICE_ID): cv.string, vol.Optional(DEVICE_ID): cv.string,
} }
UPDATE_FIELDS = { UPDATE_FIELDS: VolDictType = {
vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)), vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)),
vol.Optional("description"): cv.string, vol.Optional("description"): cv.string,
vol.Optional(LAST_SCANNED): cv.datetime, vol.Optional(LAST_SCANNED): cv.datetime,
@ -192,8 +192,8 @@ class TagDictStorageCollectionWebsocket(
storage_collection: TagStorageCollection, storage_collection: TagStorageCollection,
api_prefix: str, api_prefix: str,
model_name: str, model_name: str,
create_schema: ConfigType, create_schema: VolDictType,
update_schema: ConfigType, update_schema: VolDictType,
) -> None: ) -> None:
"""Initialize a websocket for tag.""" """Initialize a websocket for tag."""
super().__init__( super().__init__(

View File

@ -26,7 +26,7 @@ from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.helpers.service import homeassistant.helpers.service
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -66,7 +66,7 @@ SERVICE_FINISH = "finish"
STORAGE_KEY = DOMAIN STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1 STORAGE_VERSION = 1
STORAGE_FIELDS = { STORAGE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): cv.string, vol.Required(CONF_NAME): cv.string,
vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ICON): cv.icon,
vol.Optional(CONF_DURATION, default=DEFAULT_DURATION): cv.time_period, vol.Optional(CONF_DURATION, default=DEFAULT_DURATION): cv.time_period,

View File

@ -45,7 +45,7 @@ from homeassistant.helpers import (
service, service,
storage, storage,
) )
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from homeassistant.util.location import distance from homeassistant.util.location import distance
@ -62,7 +62,7 @@ ENTITY_ID_HOME = ENTITY_ID_FORMAT.format(HOME_ZONE)
ICON_HOME = "mdi:home" ICON_HOME = "mdi:home"
ICON_IMPORT = "mdi:import" ICON_IMPORT = "mdi:import"
CREATE_FIELDS = { CREATE_FIELDS: VolDictType = {
vol.Required(CONF_NAME): cv.string, vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_LATITUDE): cv.latitude, vol.Required(CONF_LATITUDE): cv.latitude,
vol.Required(CONF_LONGITUDE): cv.longitude, vol.Required(CONF_LONGITUDE): cv.longitude,
@ -72,7 +72,7 @@ CREATE_FIELDS = {
} }
UPDATE_FIELDS = { UPDATE_FIELDS: VolDictType = {
vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude, vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude, vol.Optional(CONF_LONGITUDE): cv.longitude,

View File

@ -26,7 +26,7 @@ from . import entity_registry
from .entity import Entity from .entity import Entity
from .entity_component import EntityComponent from .entity_component import EntityComponent
from .storage import Store from .storage import Store
from .typing import ConfigType from .typing import ConfigType, VolDictType
STORAGE_VERSION = 1 STORAGE_VERSION = 1
SAVE_DELAY = 10 SAVE_DELAY = 10
@ -515,8 +515,8 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]:
storage_collection: _StorageCollectionT, storage_collection: _StorageCollectionT,
api_prefix: str, api_prefix: str,
model_name: str, model_name: str,
create_schema: dict, create_schema: VolDictType,
update_schema: dict, update_schema: VolDictType,
) -> None: ) -> None:
"""Initialize a websocket CRUD.""" """Initialize a websocket CRUD."""
self.storage_collection = storage_collection self.storage_collection = storage_collection