1
0
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:
Jesse Hills
2023-11-02 15:32:00 +13:00
committed by GitHub
parent 40c001bdc2
commit 9eea52ea85
8 changed files with 72 additions and 12 deletions

View File

@@ -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