mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-31 18:18:27 +02:00
Reject template select/number/switches that don't handle user input (#2230)
This commit is contained in:
@@ -29,12 +29,16 @@ def validate_min_max(config):
|
||||
|
||||
def validate(config):
|
||||
if CONF_LAMBDA in config:
|
||||
if CONF_OPTIMISTIC in config:
|
||||
if config[CONF_OPTIMISTIC]:
|
||||
raise cv.Invalid("optimistic cannot be used with lambda")
|
||||
if CONF_INITIAL_VALUE in config:
|
||||
raise cv.Invalid("initial_value cannot be used with lambda")
|
||||
if CONF_RESTORE_VALUE in config:
|
||||
raise cv.Invalid("restore_value cannot be used with lambda")
|
||||
if not config[CONF_OPTIMISTIC] and CONF_SET_ACTION not in config:
|
||||
raise cv.Invalid(
|
||||
"Either optimistic mode must be enabled, or set_action must be set, to handle the number being set."
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
@@ -46,7 +50,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Required(CONF_MIN_VALUE): cv.float_,
|
||||
cv.Required(CONF_STEP): cv.positive_float,
|
||||
cv.Optional(CONF_LAMBDA): cv.returning_lambda,
|
||||
cv.Optional(CONF_OPTIMISTIC): cv.boolean,
|
||||
cv.Optional(CONF_OPTIMISTIC, default=False): cv.boolean,
|
||||
cv.Optional(CONF_SET_ACTION): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_INITIAL_VALUE): cv.float_,
|
||||
cv.Optional(CONF_RESTORE_VALUE): cv.boolean,
|
||||
@@ -75,8 +79,7 @@ async def to_code(config):
|
||||
cg.add(var.set_template(template_))
|
||||
|
||||
else:
|
||||
if CONF_OPTIMISTIC in config:
|
||||
cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
|
||||
cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
|
||||
if CONF_INITIAL_VALUE in config:
|
||||
cg.add(var.set_initial_value(config[CONF_INITIAL_VALUE]))
|
||||
if CONF_RESTORE_VALUE in config:
|
||||
|
||||
Reference in New Issue
Block a user