Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use VolDictType for service schemas #120403

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
8 changes: 4 additions & 4 deletions homeassistant/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.network import get_url
from homeassistant.helpers.template import Template
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.loader import bind_hass

from .const import ( # noqa: F401
Expand Down Expand Up @@ -130,14 +130,14 @@ class CameraEntityFeature(IntFlag):

MIN_STREAM_INTERVAL: Final = 0.5 # seconds

CAMERA_SERVICE_SNAPSHOT: Final = {vol.Required(ATTR_FILENAME): cv.template}
CAMERA_SERVICE_SNAPSHOT: VolDictType = {vol.Required(ATTR_FILENAME): cv.template}

CAMERA_SERVICE_PLAY_STREAM: Final = {
CAMERA_SERVICE_PLAY_STREAM: VolDictType = {
vol.Required(ATTR_MEDIA_PLAYER): cv.entities_domain(DOMAIN_MP),
vol.Optional(ATTR_FORMAT, default="hls"): vol.In(OUTPUT_FORMATS),
}

CAMERA_SERVICE_RECORD: Final = {
CAMERA_SERVICE_RECORD: VolDictType = {
vol.Required(CONF_FILENAME): cv.template,
vol.Optional(CONF_DURATION, default=30): vol.Coerce(int),
vol.Optional(CONF_LOOKBACK, default=0): vol.Coerce(int),
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/elkm1/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import VolDictType

from . import ElkAttachedEntity, ElkEntity, ElkM1ConfigEntry, create_elk_entities
from .const import (
Expand All @@ -41,7 +42,7 @@
)
from .models import ELKM1Data

DISPLAY_MESSAGE_SERVICE_SCHEMA = {
DISPLAY_MESSAGE_SERVICE_SCHEMA: VolDictType = {
vol.Optional("clear", default=2): vol.All(vol.Coerce(int), vol.In([0, 1, 2])),
vol.Optional("beep", default=False): cv.boolean,
vol.Optional("timeout", default=0): vol.All(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/elkm1/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import voluptuous as vol

from homeassistant.const import ATTR_CODE, CONF_ZONE
from homeassistant.helpers.typing import VolDictType

DOMAIN = "elkm1"

Expand Down Expand Up @@ -48,6 +49,6 @@
ATTR_CHANGED_BY_TIME = "changed_by_time"
ATTR_VALUE = "value"

ELK_USER_CODE_SERVICE_SCHEMA = {
ELK_USER_CODE_SERVICE_SCHEMA: VolDictType = {
vol.Required(ATTR_CODE): vol.All(vol.Coerce(int), vol.Range(0, 999999))
}
3 changes: 2 additions & 1 deletion homeassistant/components/elkm1/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import VolDictType

from . import ElkAttachedEntity, ElkEntity, ElkM1ConfigEntry, create_elk_entities
from .const import ATTR_VALUE, ELK_USER_CODE_SERVICE_SCHEMA
Expand All @@ -30,7 +31,7 @@
SERVICE_SENSOR_ZONE_TRIGGER = "sensor_zone_trigger"
UNDEFINED_TEMPERATURE = -40

ELK_SET_COUNTER_SERVICE_SCHEMA = {
ELK_SET_COUNTER_SERVICE_SCHEMA: VolDictType = {
vol.Required(ATTR_VALUE): vol.All(vol.Coerce(int), vol.Range(0, 65535))
}

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/environment_canada/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
AddEntitiesCallback,
async_get_current_platform,
)
from homeassistant.helpers.typing import VolDictType
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from . import device_info
from .const import ATTR_OBSERVATION_TIME, DOMAIN

SERVICE_SET_RADAR_TYPE = "set_radar_type"
SET_RADAR_TYPE_SCHEMA = {
SET_RADAR_TYPE_SCHEMA: VolDictType = {
vol.Required("radar_type"): vol.In(["Auto", "Rain", "Snow"]),
}

Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/flux_led/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import VolDictType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.color import (
color_temperature_kelvin_to_mired,
Expand Down Expand Up @@ -88,7 +89,7 @@
SERVICE_SET_ZONES: Final = "set_zones"
SERVICE_SET_MUSIC_MODE: Final = "set_music_mode"

CUSTOM_EFFECT_DICT: Final = {
CUSTOM_EFFECT_DICT: VolDictType = {
vol.Required(CONF_COLORS): vol.All(
cv.ensure_list,
vol.Length(min=1, max=16),
Expand All @@ -102,7 +103,7 @@
),
}

SET_MUSIC_MODE_DICT: Final = {
SET_MUSIC_MODE_DICT: VolDictType = {
vol.Optional(ATTR_SENSITIVITY, default=100): vol.All(
vol.Coerce(int), vol.Range(min=0, max=100)
),
Expand All @@ -121,7 +122,7 @@
),
}

SET_ZONES_DICT: Final = {
SET_ZONES_DICT: VolDictType = {
vol.Required(CONF_COLORS): vol.All(
cv.ensure_list,
vol.Length(min=1, max=2048),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/geniushub/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, VolDictType

from . import ATTR_DURATION, DOMAIN, GeniusZone

GH_ON_OFF_ZONE = "on / off"

SVC_SET_SWITCH_OVERRIDE = "set_switch_override"

SET_SWITCH_OVERRIDE_SCHEMA = {
SET_SWITCH_OVERRIDE_SCHEMA: VolDictType = {
vol.Optional(ATTR_DURATION): vol.All(
cv.time_period,
vol.Range(min=timedelta(minutes=5), max=timedelta(days=1)),
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/harmony/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import VolDictType

from .const import (
ACTIVITY_POWER_OFF,
Expand All @@ -50,7 +51,7 @@

ATTR_CHANNEL = "channel"

HARMONY_CHANGE_CHANNEL_SCHEMA = {
HARMONY_CHANGE_CHANNEL_SCHEMA: VolDictType = {
vol.Required(ATTR_CHANNEL): cv.positive_int,
}

Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/isy994/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import async_get_platforms
from homeassistant.helpers.service import entity_service_call
from homeassistant.helpers.typing import VolDictType

from .const import _LOGGER, DOMAIN

Expand Down Expand Up @@ -102,12 +103,14 @@ def valid_isy_commands(value: Any) -> str:
vol.Required(CONF_SIZE): vol.All(vol.Coerce(int), vol.In(VALID_PARAMETER_SIZES)),
}

SERVICE_SET_USER_CODE_SCHEMA = {
SERVICE_SET_USER_CODE_SCHEMA: VolDictType = {
vol.Required(CONF_USER_NUM): vol.Coerce(int),
vol.Required(CONF_CODE): vol.Coerce(int),
}

SERVICE_DELETE_USER_CODE_SCHEMA = {vol.Required(CONF_USER_NUM): vol.Coerce(int)}
SERVICE_DELETE_USER_CODE_SCHEMA: VolDictType = {
vol.Required(CONF_USER_NUM): vol.Coerce(int)
}

SERVICE_SEND_PROGRAM_COMMAND_SCHEMA = vol.All(
cv.has_at_least_one_key(CONF_ADDRESS, CONF_NAME),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/izone/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.temperature import display_temp as show_temp
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.typing import ConfigType, VolDictType

from .const import (
DATA_CONFIG,
Expand Down Expand Up @@ -65,7 +65,7 @@
IZONE_SERVICE_AIRFLOW_MIN = "airflow_min"
IZONE_SERVICE_AIRFLOW_MAX = "airflow_max"

IZONE_SERVICE_AIRFLOW_SCHEMA = {
IZONE_SERVICE_AIRFLOW_SCHEMA: VolDictType = {
vol.Required(ATTR_AIRFLOW): vol.All(
vol.Coerce(int), vol.Range(min=0, max=100), msg="invalid airflow"
),
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/keymitt_ble/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
AddEntitiesCallback,
async_get_current_platform,
)
from homeassistant.helpers.typing import VolDictType

from .const import DOMAIN
from .coordinator import MicroBotDataUpdateCoordinator
from .entity import MicroBotEntity

CALIBRATE = "calibrate"
CALIBRATE_SCHEMA = {
CALIBRATE_SCHEMA: VolDictType = {
vol.Required("depth"): cv.positive_int,
vol.Required("duration"): cv.positive_int,
vol.Required("mode"): vol.In(["normal", "invert", "toggle"]),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/kodi/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.network import is_internal_request
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, VolDictType
import homeassistant.util.dt as dt_util

from .browse_media import (
Expand Down Expand Up @@ -147,7 +147,7 @@
ATTR_METHOD = "method"


KODI_ADD_MEDIA_SCHEMA = {
KODI_ADD_MEDIA_SCHEMA: VolDictType = {
vol.Required(ATTR_MEDIA_TYPE): cv.string,
vol.Optional(ATTR_MEDIA_ID): cv.string,
vol.Optional(ATTR_MEDIA_NAME): cv.string,
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/lifx/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.typing import VolDictType

from .const import (
_LOGGER,
Expand Down Expand Up @@ -53,7 +54,7 @@

SERVICE_LIFX_SET_STATE = "set_state"

LIFX_SET_STATE_SCHEMA = {
LIFX_SET_STATE_SCHEMA: VolDictType = {
**LIGHT_TURN_ON_SCHEMA,
ATTR_INFRARED: vol.All(vol.Coerce(int), vol.Clamp(min=0, max=255)),
ATTR_ZONES: vol.All(cv.ensure_list, [cv.positive_int]),
Expand All @@ -63,7 +64,7 @@

SERVICE_LIFX_SET_HEV_CYCLE_STATE = "set_hev_cycle_state"

LIFX_SET_HEV_CYCLE_STATE_SCHEMA = {
LIFX_SET_HEV_CYCLE_STATE_SCHEMA: VolDictType = {
ATTR_POWER: vol.Required(cv.boolean),
ATTR_DURATION: vol.All(vol.Coerce(float), vol.Clamp(min=0, max=86400)),
}
Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)
from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.loader import bind_hass
import homeassistant.util.color as color_util

Expand Down Expand Up @@ -247,7 +247,7 @@ def get_supported_color_modes(hass: HomeAssistant, entity_id: str) -> set[str] |
VALID_BRIGHTNESS_STEP_PCT = vol.All(vol.Coerce(float), vol.Clamp(min=-100, max=100))
VALID_FLASH = vol.In([FLASH_SHORT, FLASH_LONG])

LIGHT_TURN_ON_SCHEMA = {
LIGHT_TURN_ON_SCHEMA: VolDictType = {
vol.Exclusive(ATTR_PROFILE, COLOR_GROUP): cv.string,
ATTR_TRANSITION: VALID_TRANSITION,
vol.Exclusive(ATTR_BRIGHTNESS, ATTR_BRIGHTNESS): VALID_BRIGHTNESS,
Expand Down Expand Up @@ -286,7 +286,10 @@ def get_supported_color_modes(hass: HomeAssistant, entity_id: str) -> set[str] |
ATTR_EFFECT: cv.string,
}

LIGHT_TURN_OFF_SCHEMA = {ATTR_TRANSITION: VALID_TRANSITION, ATTR_FLASH: VALID_FLASH}
LIGHT_TURN_OFF_SCHEMA: VolDictType = {
ATTR_TRANSITION: VALID_TRANSITION,
ATTR_FLASH: VALID_FLASH,
}


_LOGGER = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/lyric/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import VolDictType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from . import LyricDeviceEntity
Expand Down Expand Up @@ -111,7 +112,7 @@
SERVICE_HOLD_TIME = "set_hold_time"
ATTR_TIME_PERIOD = "time_period"

SCHEMA_HOLD_TIME = {
SCHEMA_HOLD_TIME: VolDictType = {
vol.Required(ATTR_TIME_PERIOD, default="01:00:00"): vol.All(
cv.time_period,
cv.positive_timedelta,
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/motion_blinds/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.typing import VolDictType

from .const import (
ATTR_ABSOLUTE_POSITION,
Expand Down Expand Up @@ -75,7 +76,7 @@
}


SET_ABSOLUTE_POSITION_SCHEMA = {
SET_ABSOLUTE_POSITION_SCHEMA: VolDictType = {
vol.Required(ATTR_ABSOLUTE_POSITION): vol.All(cv.positive_int, vol.Range(max=100)),
vol.Optional(ATTR_TILT_POSITION): vol.All(cv.positive_int, vol.Range(max=100)),
vol.Optional(ATTR_WIDTH): vol.All(cv.positive_int, vol.Range(max=100)),
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/nexia/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import VolDictType

from .const import (
ATTR_AIRCLEANER_MODE,
Expand All @@ -55,11 +56,11 @@
SERVICE_SET_HUMIDIFY_SETPOINT = "set_humidify_setpoint"
SERVICE_SET_HVAC_RUN_MODE = "set_hvac_run_mode"

SET_AIRCLEANER_SCHEMA = {
SET_AIRCLEANER_SCHEMA: VolDictType = {
vol.Required(ATTR_AIRCLEANER_MODE): cv.string,
}

SET_HUMIDITY_SCHEMA = {
SET_HUMIDITY_SCHEMA: VolDictType = {
vol.Required(ATTR_HUMIDITY): vol.All(vol.Coerce(int), vol.Range(min=35, max=65)),
}

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/rainbird/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import VolDictType
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import ATTR_DURATION, CONF_IMPORTED_NAMES, DOMAIN, MANUFACTURER
Expand All @@ -23,7 +24,7 @@

SERVICE_START_IRRIGATION = "start_irrigation"

SERVICE_SCHEMA_IRRIGATION = {
SERVICE_SCHEMA_IRRIGATION: VolDictType = {
vol.Required(ATTR_DURATION): cv.positive_float,
}

Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/rainmachine/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Awaitable, Callable, Coroutine
from dataclasses import dataclass
from datetime import datetime
from typing import Any, Concatenate
from typing import Any, Concatenate, cast

from regenmaschine.errors import RainMachineError
import voluptuous as vol
Expand All @@ -18,6 +18,7 @@
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import VolDictType

from . import RainMachineData, RainMachineEntity, async_update_programs_and_zones
from .const import (
Expand Down Expand Up @@ -191,7 +192,8 @@ async def async_setup_entry(
("stop_program", {}, "async_stop_program"),
("stop_zone", {}, "async_stop_zone"),
):
platform.async_register_entity_service(service_name, schema, method)
schema_dict = cast(VolDictType, schema)
platform.async_register_entity_service(service_name, schema_dict, method)

data: RainMachineData = hass.data[DOMAIN][entry.entry_id]
entities: list[RainMachineBaseSwitch] = []
Expand Down
Loading