Add handler to validate_user_input (#82681)

* Add handler to validate_user_input

* Adjust group config flow
This commit is contained in:
epenet 2022-11-25 09:29:54 +01:00 committed by GitHub
parent f3b3193f7a
commit a4dbb9a24e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 13 deletions

View file

@ -10,6 +10,7 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
from homeassistant.helpers import selector
from homeassistant.helpers.schema_config_entry_flow import (
SchemaCommonFlowHandler,
SchemaConfigFlowHandler,
SchemaFlowError,
SchemaFlowFormStep,
@ -18,11 +19,13 @@ from homeassistant.helpers.schema_config_entry_flow import (
from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN
def _validate_mode(data: Any) -> Any:
def _validate_mode(
handler: SchemaCommonFlowHandler, user_input: dict[str, Any]
) -> dict[str, Any]:
"""Validate the threshold mode, and set limits to None if not set."""
if CONF_LOWER not in data and CONF_UPPER not in data:
if CONF_LOWER not in user_input and CONF_UPPER not in user_input:
raise SchemaFlowError("need_lower_upper")
return {CONF_LOWER: None, CONF_UPPER: None, **data}
return {CONF_LOWER: None, CONF_UPPER: None, **user_input}
OPTIONS_SCHEMA = vol.Schema(