Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve collection schema typing #120441

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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,
Expand All @@ -49,14 +49,14 @@
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)

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/assist_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)
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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/counter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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__)

Expand Down Expand Up @@ -49,7 +49,7 @@
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)),
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/image_upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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
Expand All @@ -32,11 +32,11 @@
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)),
}

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/input_boolean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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"
Expand All @@ -35,7 +35,7 @@

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,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/input_button/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
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,
}
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/input_datetime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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__)
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/input_number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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__)

Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/input_select/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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__)

Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/input_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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__)

Expand All @@ -50,7 +50,7 @@
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),
Expand Down
11 changes: 6 additions & 5 deletions homeassistant/components/lovelace/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
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"
Expand All @@ -37,12 +38,12 @@

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,
}
Expand All @@ -54,23 +55,23 @@
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,
vol.Optional(CONF_SHOW_IN_SIDEBAR, default=True): cv.boolean,
}


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,
vol.Optional(CONF_SHOW_IN_SIDEBAR): cv.boolean,
}


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.
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/person/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
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
Expand Down Expand Up @@ -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(
Expand All @@ -175,7 +175,7 @@ def entities_in_person(hass: HomeAssistant, entity_id: str) -> list[str]:
}


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(
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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 (
Expand Down Expand Up @@ -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,
}
Expand All @@ -122,13 +122,13 @@ def serialize_to_time(value: Any) -> Any:
}
)

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]
)
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/tag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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
Expand All @@ -35,15 +35,15 @@

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,
vol.Optional(LAST_SCANNED): cv.datetime,
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,
Expand Down Expand Up @@ -192,8 +192,8 @@ def __init__(
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__(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/timer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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__)
Expand Down Expand Up @@ -66,7 +66,7 @@
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,
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/zone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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

Expand All @@ -62,7 +62,7 @@
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,
Expand All @@ -72,7 +72,7 @@
}


UPDATE_FIELDS = {
UPDATE_FIELDS: VolDictType = {
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude,
Expand Down
Loading