mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Update PCA9554 pin checks to new facility (#5656)
This commit is contained in:
parent
29b1233609
commit
b0a400d82b
1 changed files with 9 additions and 24 deletions
|
@ -10,7 +10,6 @@ from esphome.const import (
|
|||
CONF_INVERTED,
|
||||
CONF_OUTPUT,
|
||||
)
|
||||
from esphome.core import CORE, ID
|
||||
|
||||
CODEOWNERS = ["@hwstar", "@clydebarrow"]
|
||||
DEPENDENCIES = ["i2c"]
|
||||
|
@ -53,27 +52,6 @@ def validate_mode(value):
|
|||
return value
|
||||
|
||||
|
||||
def validate_pin(config):
|
||||
pca_id = config[CONF_PCA9554].id
|
||||
|
||||
# when pin config validation is performed, the entire YAML has been read, but depending on the component order,
|
||||
# the pca9554 component may not yet have been processed, so its id property could be either the original string,
|
||||
# or an ID object.
|
||||
def matcher(p):
|
||||
id = p[CONF_ID]
|
||||
if isinstance(id, ID):
|
||||
return id.id == pca_id
|
||||
return id == pca_id
|
||||
|
||||
pca = list(filter(matcher, CORE.raw_config[CONF_PCA9554]))
|
||||
if not pca:
|
||||
raise cv.Invalid(f"No pca9554 component found with id matching {pca_id}")
|
||||
count = pca[0][CONF_PIN_COUNT]
|
||||
if config[CONF_NUMBER] >= count:
|
||||
raise cv.Invalid(f"Pin number must be in range 0-{count - 1}")
|
||||
return config
|
||||
|
||||
|
||||
PCA9554_PIN_SCHEMA = cv.All(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(PCA9554GPIOPin),
|
||||
|
@ -88,11 +66,18 @@ PCA9554_PIN_SCHEMA = cv.All(
|
|||
),
|
||||
cv.Optional(CONF_INVERTED, default=False): cv.boolean,
|
||||
},
|
||||
validate_pin,
|
||||
)
|
||||
|
||||
|
||||
@pins.PIN_SCHEMA_REGISTRY.register(CONF_PCA9554, PCA9554_PIN_SCHEMA)
|
||||
def pca9554_pin_final_validate(pin_config, parent_config):
|
||||
count = parent_config[CONF_PIN_COUNT]
|
||||
if pin_config[CONF_NUMBER] >= count:
|
||||
raise cv.Invalid(f"Pin number must be in range 0-{count - 1}")
|
||||
|
||||
|
||||
@pins.PIN_SCHEMA_REGISTRY.register(
|
||||
CONF_PCA9554, PCA9554_PIN_SCHEMA, pca9554_pin_final_validate
|
||||
)
|
||||
async def pca9554_pin_to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
parent = await cg.get_variable(config[CONF_PCA9554])
|
||||
|
|
Loading…
Reference in a new issue