mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Improve collection schema typing (#120441)
This commit is contained in:
parent
197062139e
commit
b393024acd
@ -29,7 +29,7 @@ from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import collection, config_entry_oauth2_flow
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
from homeassistant.loader import (
|
||||
IntegrationNotFound,
|
||||
async_get_application_credentials,
|
||||
@ -49,14 +49,14 @@ DATA_STORAGE = "storage"
|
||||
CONF_AUTH_DOMAIN = "auth_domain"
|
||||
DEFAULT_IMPORT_NAME = "Import from configuration.yaml"
|
||||
|
||||
CREATE_FIELDS = {
|
||||
CREATE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_DOMAIN): cv.string,
|
||||
vol.Required(CONF_CLIENT_ID): 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_NAME): cv.string,
|
||||
}
|
||||
UPDATE_FIELDS: dict = {} # Not supported
|
||||
UPDATE_FIELDS: VolDictType = {} # Not supported
|
||||
|
||||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
||||
|
||||
|
@ -45,7 +45,7 @@ from homeassistant.helpers.collection import (
|
||||
)
|
||||
from homeassistant.helpers.singleton import singleton
|
||||
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 (
|
||||
dt as dt_util,
|
||||
language as language_util,
|
||||
@ -94,7 +94,7 @@ def validate_language(data: dict[str, Any]) -> Any:
|
||||
return data
|
||||
|
||||
|
||||
PIPELINE_FIELDS = {
|
||||
PIPELINE_FIELDS: VolDictType = {
|
||||
vol.Required("conversation_engine"): str,
|
||||
vol.Required("conversation_language"): str,
|
||||
vol.Required("language"): str,
|
||||
|
@ -21,7 +21,7 @@ import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -49,7 +49,7 @@ SERVICE_SET_VALUE = "set_value"
|
||||
STORAGE_KEY = DOMAIN
|
||||
STORAGE_VERSION = 1
|
||||
|
||||
STORAGE_FIELDS = {
|
||||
STORAGE_FIELDS: VolDictType = {
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
vol.Optional(CONF_INITIAL, default=DEFAULT_INITIAL): cv.positive_int,
|
||||
vol.Required(CONF_NAME): vol.All(cv.string, vol.Length(min=1)),
|
||||
|
@ -21,7 +21,7 @@ from homeassistant.const import CONF_ID
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import collection, config_validation as cv
|
||||
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
|
||||
|
||||
from .const import DOMAIN
|
||||
@ -32,11 +32,11 @@ STORAGE_VERSION = 1
|
||||
VALID_SIZES = {256, 512}
|
||||
MAX_SIZE = 1024 * 1024 * 10
|
||||
|
||||
CREATE_FIELDS = {
|
||||
CREATE_FIELDS: VolDictType = {
|
||||
vol.Required("file"): FileField,
|
||||
}
|
||||
|
||||
UPDATE_FIELDS = {
|
||||
UPDATE_FIELDS: VolDictType = {
|
||||
vol.Optional("name"): vol.All(str, vol.Length(min=1)),
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
import homeassistant.helpers.service
|
||||
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
|
||||
|
||||
DOMAIN = "input_boolean"
|
||||
@ -35,7 +35,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_INITIAL = "initial"
|
||||
|
||||
STORAGE_FIELDS = {
|
||||
STORAGE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Optional(CONF_INITIAL): cv.boolean,
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
|
@ -22,13 +22,13 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
import homeassistant.helpers.service
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
|
||||
DOMAIN = "input_button"
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
STORAGE_FIELDS = {
|
||||
STORAGE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
import homeassistant.helpers.service
|
||||
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
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -59,7 +59,7 @@ def validate_set_datetime_attrs(config):
|
||||
STORAGE_KEY = DOMAIN
|
||||
STORAGE_VERSION = 1
|
||||
|
||||
STORAGE_FIELDS = {
|
||||
STORAGE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Optional(CONF_HAS_DATE, default=False): cv.boolean,
|
||||
vol.Optional(CONF_HAS_TIME, default=False): cv.boolean,
|
||||
|
@ -25,7 +25,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
import homeassistant.helpers.service
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -64,7 +64,7 @@ def _cv_input_number(cfg):
|
||||
return cfg
|
||||
|
||||
|
||||
STORAGE_FIELDS = {
|
||||
STORAGE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Required(CONF_MIN): vol.Coerce(float),
|
||||
vol.Required(CONF_MAX): vol.Coerce(float),
|
||||
|
@ -33,7 +33,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
import homeassistant.helpers.service
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -55,7 +55,7 @@ def _unique(options: Any) -> Any:
|
||||
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_OPTIONS): vol.All(
|
||||
cv.ensure_list, vol.Length(min=1), _unique, [cv.string]
|
||||
|
@ -24,7 +24,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
import homeassistant.helpers.service
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -50,7 +50,7 @@ SERVICE_SET_VALUE = "set_value"
|
||||
STORAGE_KEY = DOMAIN
|
||||
STORAGE_VERSION = 1
|
||||
|
||||
STORAGE_FIELDS = {
|
||||
STORAGE_FIELDS: VolDictType = {
|
||||
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_MAX, default=CONF_MAX_VALUE): vol.Coerce(int),
|
||||
|
@ -13,6 +13,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
from homeassistant.util import slugify
|
||||
|
||||
DOMAIN = "lovelace"
|
||||
@ -37,12 +38,12 @@ 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_URL): cv.string,
|
||||
}
|
||||
|
||||
RESOURCE_UPDATE_FIELDS = {
|
||||
RESOURCE_UPDATE_FIELDS: VolDictType = {
|
||||
vol.Optional(CONF_RESOURCE_TYPE_WS): vol.In(RESOURCE_TYPES),
|
||||
vol.Optional(CONF_URL): cv.string,
|
||||
}
|
||||
@ -54,7 +55,7 @@ CONF_TITLE = "title"
|
||||
CONF_REQUIRE_ADMIN = "require_admin"
|
||||
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_ICON): cv.icon,
|
||||
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_ICON): vol.Any(cv.icon, None),
|
||||
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,
|
||||
vol.Required(CONF_URL_PATH): cv.string,
|
||||
# For now we write "storage" as all modes.
|
||||
|
@ -50,7 +50,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
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 .const import DOMAIN
|
||||
@ -165,7 +165,7 @@ def entities_in_person(hass: HomeAssistant, entity_id: str) -> list[str]:
|
||||
return person_entity.device_trackers
|
||||
|
||||
|
||||
CREATE_FIELDS = {
|
||||
CREATE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Optional(CONF_USER_ID): vol.Any(str, None),
|
||||
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_USER_ID): vol.Any(str, None),
|
||||
vol.Optional(CONF_DEVICE_TRACKERS, default=list): vol.All(
|
||||
|
@ -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.service import async_register_admin_service
|
||||
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 .const import (
|
||||
@ -104,12 +104,12 @@ def serialize_to_time(value: Any) -> Any:
|
||||
return vol.Coerce(str)(value)
|
||||
|
||||
|
||||
BASE_SCHEMA = {
|
||||
BASE_SCHEMA: VolDictType = {
|
||||
vol.Required(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
}
|
||||
|
||||
TIME_RANGE_SCHEMA = {
|
||||
TIME_RANGE_SCHEMA: VolDictType = {
|
||||
vol.Required(CONF_FROM): cv.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(
|
||||
cv.ensure_list, [TIME_RANGE_SCHEMA], valid_schedule
|
||||
)
|
||||
for day in CONF_ALL_DAYS
|
||||
}
|
||||
STORAGE_SCHEDULE_SCHEMA = {
|
||||
STORAGE_SCHEDULE_SCHEMA: VolDictType = {
|
||||
vol.Optional(day, default=[]): vol.All(
|
||||
cv.ensure_list, [TIME_RANGE_SCHEMA], valid_schedule, [STORAGE_TIME_RANGE_SCHEMA]
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
from homeassistant.util import slugify
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
@ -35,7 +35,7 @@ STORAGE_VERSION_MINOR = 3
|
||||
|
||||
TAG_DATA: HassKey[TagStorageCollection] = HassKey(DOMAIN)
|
||||
|
||||
CREATE_FIELDS = {
|
||||
CREATE_FIELDS: VolDictType = {
|
||||
vol.Optional(TAG_ID): cv.string,
|
||||
vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Optional("description"): cv.string,
|
||||
@ -43,7 +43,7 @@ CREATE_FIELDS = {
|
||||
vol.Optional(DEVICE_ID): cv.string,
|
||||
}
|
||||
|
||||
UPDATE_FIELDS = {
|
||||
UPDATE_FIELDS: VolDictType = {
|
||||
vol.Optional(CONF_NAME): vol.All(str, vol.Length(min=1)),
|
||||
vol.Optional("description"): cv.string,
|
||||
vol.Optional(LAST_SCANNED): cv.datetime,
|
||||
@ -192,8 +192,8 @@ class TagDictStorageCollectionWebsocket(
|
||||
storage_collection: TagStorageCollection,
|
||||
api_prefix: str,
|
||||
model_name: str,
|
||||
create_schema: ConfigType,
|
||||
update_schema: ConfigType,
|
||||
create_schema: VolDictType,
|
||||
update_schema: VolDictType,
|
||||
) -> None:
|
||||
"""Initialize a websocket for tag."""
|
||||
super().__init__(
|
||||
|
@ -26,7 +26,7 @@ from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
import homeassistant.helpers.service
|
||||
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
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -66,7 +66,7 @@ SERVICE_FINISH = "finish"
|
||||
STORAGE_KEY = DOMAIN
|
||||
STORAGE_VERSION = 1
|
||||
|
||||
STORAGE_FIELDS = {
|
||||
STORAGE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
vol.Optional(CONF_DURATION, default=DEFAULT_DURATION): cv.time_period,
|
||||
|
@ -45,7 +45,7 @@ from homeassistant.helpers import (
|
||||
service,
|
||||
storage,
|
||||
)
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.location import distance
|
||||
|
||||
@ -62,7 +62,7 @@ ENTITY_ID_HOME = ENTITY_ID_FORMAT.format(HOME_ZONE)
|
||||
ICON_HOME = "mdi:home"
|
||||
ICON_IMPORT = "mdi:import"
|
||||
|
||||
CREATE_FIELDS = {
|
||||
CREATE_FIELDS: VolDictType = {
|
||||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_LATITUDE): cv.latitude,
|
||||
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_LATITUDE): cv.latitude,
|
||||
vol.Optional(CONF_LONGITUDE): cv.longitude,
|
||||
|
@ -26,7 +26,7 @@ from . import entity_registry
|
||||
from .entity import Entity
|
||||
from .entity_component import EntityComponent
|
||||
from .storage import Store
|
||||
from .typing import ConfigType
|
||||
from .typing import ConfigType, VolDictType
|
||||
|
||||
STORAGE_VERSION = 1
|
||||
SAVE_DELAY = 10
|
||||
@ -515,8 +515,8 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]:
|
||||
storage_collection: _StorageCollectionT,
|
||||
api_prefix: str,
|
||||
model_name: str,
|
||||
create_schema: dict,
|
||||
update_schema: dict,
|
||||
create_schema: VolDictType,
|
||||
update_schema: VolDictType,
|
||||
) -> None:
|
||||
"""Initialize a websocket CRUD."""
|
||||
self.storage_collection = storage_collection
|
||||
|
Loading…
x
Reference in New Issue
Block a user