mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +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,7 +354,8 @@ 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.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ClickTrigger),
|
||||||
cv.Optional(
|
cv.Optional(
|
||||||
|
@ -353,7 +366,10 @@ BINARY_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).ex
|
||||||
): cv.positive_time_period_milliseconds,
|
): cv.positive_time_period_milliseconds,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_ON_DOUBLE_CLICK): automation.validate_automation(
|
validate_click_timing,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_DOUBLE_CLICK): cv.All(
|
||||||
|
automation.validate_automation(
|
||||||
{
|
{
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DoubleClickTrigger),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DoubleClickTrigger),
|
||||||
cv.Optional(
|
cv.Optional(
|
||||||
|
@ -364,6 +380,8 @@ BINARY_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).ex
|
||||||
): cv.positive_time_period_milliseconds,
|
): 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(
|
||||||
{
|
{
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MultiClickTrigger),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MultiClickTrigger),
|
||||||
|
|
Loading…
Reference in a new issue