From 8280772b9151e71ef544ee8e849285536ee2bcdb Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 10 May 2024 10:57:47 +1200 Subject: [PATCH] Add new Error type to skip prepending path (#6716) --- esphome/config.py | 2 ++ esphome/config_validation.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/esphome/config.py b/esphome/config.py index 36a81f677b..4f340225fe 100644 --- a/esphome/config.py +++ b/esphome/config.py @@ -148,6 +148,8 @@ class Config(OrderedDict, fv.FinalValidateConfig): path = path or [] try: yield + except cv.FinalExternalInvalid as e: + self.add_error(e) except vol.Invalid as e: e.prepend(path) self.add_error(e) diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 512f1d8f67..5fc72921e1 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -267,6 +267,10 @@ class Required(vol.Required): super().__init__(key, msg=msg) +class FinalExternalInvalid(Invalid): + """Represents an invalid value in the final validation phase where the path should not be prepended.""" + + def check_not_templatable(value): if isinstance(value, Lambda): raise Invalid("This option is not templatable!")