Validate sn74hc595 pin number are within range (#5655)

This commit is contained in:
Jesse Hills 2023-11-02 16:45:00 +13:00 committed by GitHub
parent c3f7cae2b0
commit 29b1233609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -75,7 +75,15 @@ SN74HC595_PIN_SCHEMA = cv.All(
) )
@pins.PIN_SCHEMA_REGISTRY.register(CONF_SN74HC595, SN74HC595_PIN_SCHEMA) def sn74hc595_pin_final_validate(pin_config, parent_config):
max_pins = parent_config[CONF_SR_COUNT] * 8
if pin_config[CONF_NUMBER] >= max_pins:
raise cv.Invalid(f"Pin number must be less than {max_pins}")
@pins.PIN_SCHEMA_REGISTRY.register(
CONF_SN74HC595, SN74HC595_PIN_SCHEMA, sn74hc595_pin_final_validate
)
async def sn74hc595_pin_to_code(config): async def sn74hc595_pin_to_code(config):
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_parented(var, config[CONF_SN74HC595]) await cg.register_parented(var, config[CONF_SN74HC595])