mirror of
https://github.com/esphome/esphome.git
synced 2025-09-09 23:02:23 +01:00
Allow validation of pins based on hub config (#5647)
This commit is contained in:
@@ -57,6 +57,32 @@ class SimpleRegistry(dict):
|
||||
return decorator
|
||||
|
||||
|
||||
def _final_validate(parent_id_key, fun):
|
||||
def validator(fconf, pin_config):
|
||||
import esphome.config_validation as cv
|
||||
|
||||
parent_path = fconf.get_path_for_id(pin_config[parent_id_key])[:-1]
|
||||
parent_config = fconf.get_config_for_path(parent_path)
|
||||
|
||||
pin_path = fconf.get_path_for_id(pin_config[const.CONF_ID])[:-1]
|
||||
with cv.prepend_path([cv.ROOT_CONFIG_PATH] + pin_path):
|
||||
fun(pin_config, parent_config)
|
||||
|
||||
return validator
|
||||
|
||||
|
||||
class PinRegistry(dict):
|
||||
def register(self, name, schema, final_validate=None):
|
||||
if final_validate is not None:
|
||||
final_validate = _final_validate(name, final_validate)
|
||||
|
||||
def decorator(fun):
|
||||
self[name] = (fun, schema, final_validate)
|
||||
return fun
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def safe_print(message="", end="\n"):
|
||||
from esphome.core import CORE
|
||||
|
||||
|
Reference in New Issue
Block a user