Add check for use of GPIOXX in config (#6419)

This commit is contained in:
Clyde Stubbs 2024-03-22 19:32:37 +11:00 committed by GitHub
parent a3b0ddf686
commit 3801462589
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -311,10 +311,18 @@ def gpio_base_schema(
map(lambda m: (cv.Optional(m, default=mode_default), cv.boolean), modes)
)
def _number_validator(value):
if isinstance(value, str) and value.upper().startswith("GPIOX"):
raise cv.Invalid(
f"Found placeholder '{value}' when expecting a GPIO pin number.\n"
"You must replace this with an actual pin number."
)
return number_validator(value)
schema = cv.Schema(
{
cv.GenerateID(): cv.declare_id(pin_type),
cv.Required(CONF_NUMBER): number_validator,
cv.Required(CONF_NUMBER): _number_validator,
cv.Optional(CONF_ALLOW_OTHER_USES): cv.boolean,
cv.Optional(CONF_MODE, default={}): cv.All(mode_dict, mode_validator),
}