mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
binary_sensor: Validate max_length for on_click/on_double_click (#5068)
This commit is contained in:
parent
62aee36f82
commit
d7bfdd0efc
1 changed files with 38 additions and 20 deletions
|
@ -323,6 +323,18 @@ def validate_multi_click_timing(value):
|
||||||
validate_device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_")
|
validate_device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_")
|
||||||
|
|
||||||
|
|
||||||
|
def validate_click_timing(value):
|
||||||
|
for v in value:
|
||||||
|
min_length = v.get(CONF_MIN_LENGTH)
|
||||||
|
max_length = v.get(CONF_MAX_LENGTH)
|
||||||
|
if max_length < min_length:
|
||||||
|
raise cv.Invalid(
|
||||||
|
f"Max length ({max_length}) must be larger than min length ({min_length})."
|
||||||
|
)
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
BINARY_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend(
|
BINARY_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(BinarySensor),
|
cv.GenerateID(): cv.declare_id(BinarySensor),
|
||||||
|
@ -342,27 +354,33 @@ BINARY_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).ex
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ReleaseTrigger),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ReleaseTrigger),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_ON_CLICK): automation.validate_automation(
|
cv.Optional(CONF_ON_CLICK): cv.All(
|
||||||
{
|
automation.validate_automation(
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ClickTrigger),
|
{
|
||||||
cv.Optional(
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ClickTrigger),
|
||||||
CONF_MIN_LENGTH, default="50ms"
|
cv.Optional(
|
||||||
): cv.positive_time_period_milliseconds,
|
CONF_MIN_LENGTH, default="50ms"
|
||||||
cv.Optional(
|
): cv.positive_time_period_milliseconds,
|
||||||
CONF_MAX_LENGTH, default="350ms"
|
cv.Optional(
|
||||||
): cv.positive_time_period_milliseconds,
|
CONF_MAX_LENGTH, default="350ms"
|
||||||
}
|
): cv.positive_time_period_milliseconds,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
validate_click_timing,
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_ON_DOUBLE_CLICK): automation.validate_automation(
|
cv.Optional(CONF_ON_DOUBLE_CLICK): cv.All(
|
||||||
{
|
automation.validate_automation(
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DoubleClickTrigger),
|
{
|
||||||
cv.Optional(
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DoubleClickTrigger),
|
||||||
CONF_MIN_LENGTH, default="50ms"
|
cv.Optional(
|
||||||
): cv.positive_time_period_milliseconds,
|
CONF_MIN_LENGTH, default="50ms"
|
||||||
cv.Optional(
|
): cv.positive_time_period_milliseconds,
|
||||||
CONF_MAX_LENGTH, default="350ms"
|
cv.Optional(
|
||||||
): cv.positive_time_period_milliseconds,
|
CONF_MAX_LENGTH, default="350ms"
|
||||||
}
|
): cv.positive_time_period_milliseconds,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
validate_click_timing,
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_ON_MULTI_CLICK): automation.validate_automation(
|
cv.Optional(CONF_ON_MULTI_CLICK): automation.validate_automation(
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue