From 2ec5c5e2f3504b578d91d386779410bda190baa2 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Wed, 5 Dec 2018 09:12:49 +0100 Subject: [PATCH] Update --- esphomeyaml/automation.py | 30 ++++++++++++++++-------- esphomeyaml/components/light/__init__.py | 10 ++++---- esphomeyaml/config.py | 4 +++- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/esphomeyaml/automation.py b/esphomeyaml/automation.py index 1c6c035d35..e829b07954 100644 --- a/esphomeyaml/automation.py +++ b/esphomeyaml/automation.py @@ -30,23 +30,28 @@ def validate_recursive_condition(value): for i, item in enumerate(value): item = copy.deepcopy(item) if not isinstance(item, dict): - raise vol.Invalid(u"Condition must consist of key-value mapping! Got {}".format(item)) + raise vol.Invalid(u"Condition must consist of key-value mapping! Got {}".format(item), [i]) key = next((x for x in item if x != CONF_CONDITION_ID), None) if key is None: - raise vol.Invalid(u"Key missing from action! Got {}".format(item)) + raise vol.Invalid(u"Key missing from action! Got {}".format(item), [i]) if key not in CONDITION_REGISTRY: raise vol.Invalid(u"Unable to find condition with the name '{}', is the " - u"component loaded?".format(key)) + u"component loaded?".format(key), [i]) item.setdefault(CONF_CONDITION_ID, None) key2 = next((x for x in item if x != CONF_CONDITION_ID and x != key), None) if key2 is not None: raise vol.Invalid(u"Cannot have two conditions in one item. Key '{}' overrides '{}'! " u"Did you forget to indent the block inside the condition?" - u"".format(key, key2)) + u"".format(key, key2), [i]) validator = CONDITION_REGISTRY[key][0] + try: + condition = validator(item[key]) + except vol.Invalid as e: + e.prepend([i]) + raise e value[i] = { CONF_CONDITION_ID: cv.declare_variable_id(Condition)(item[CONF_CONDITION_ID]), - key: validator(item[key]) + key: condition, } return value @@ -56,23 +61,28 @@ def validate_recursive_action(value): for i, item in enumerate(value): item = copy.deepcopy(item) if not isinstance(item, dict): - raise vol.Invalid(u"Action must consist of key-value mapping! Got {}".format(item)) + raise vol.Invalid(u"Action must consist of key-value mapping! Got {}".format(item), [i]) key = next((x for x in item if x != CONF_ACTION_ID), None) if key is None: - raise vol.Invalid(u"Key missing from action! Got {}".format(item)) + raise vol.Invalid(u"Key missing from action! Got {}".format(item), [i]) if key not in ACTION_REGISTRY: raise vol.Invalid(u"Unable to find action with the name '{}', is the component loaded?" - u"".format(key)) + u"".format(key), [i, key]) item.setdefault(CONF_ACTION_ID, None) key2 = next((x for x in item if x != CONF_ACTION_ID and x != key), None) if key2 is not None: raise vol.Invalid(u"Cannot have two actions in one item. Key '{}' overrides '{}'! " u"Did you forget to indent the block inside the action?" - u"".format(key, key2)) + u"".format(key, key2), [i]) validator = ACTION_REGISTRY[key][0] + try: + action = validator(item[key]) + except vol.Invalid as e: + e.prepend([i]) + raise e value[i] = { CONF_ACTION_ID: cv.declare_variable_id(Action)(item[CONF_ACTION_ID]), - key: validator(item[key]) + key: action, } return value diff --git a/esphomeyaml/components/light/__init__.py b/esphomeyaml/components/light/__init__.py index f2d838f6cc..a59f7273f2 100644 --- a/esphomeyaml/components/light/__init__.py +++ b/esphomeyaml/components/light/__init__.py @@ -182,21 +182,21 @@ def validate_effects(allowed_effects): ret = [] for i, effect in enumerate(value): if not isinstance(effect, dict): - raise vol.Invalid("Each effect must be a dictionary, not {}".format(type(value))) + raise vol.Invalid("Each effect must be a dictionary, not {}".format(type(value)), [i]) if len(effect) > 1: - raise vol.Invalid("Each entry in the 'effects:' option must be a single effect.") + raise vol.Invalid("Each entry in the 'effects:' option must be a single effect.", [i]) if not effect: - raise vol.Invalid("Found no effect for the {}th entry in 'effects:'!".format(i)) + raise vol.Invalid("Found no effect for the {}th entry in 'effects:'!".format(i), [i]) key = next(iter(effect.keys())) if key not in allowed_effects: raise vol.Invalid("The effect '{}' does not exist or is not allowed for this " - "light type".format(key)) + "light type".format(key), [i]) effect[key] = effect[key] or {} conf = EFFECTS_SCHEMA(effect) name = conf[key][CONF_NAME] if name in names: raise vol.Invalid(u"Found the effect name '{}' twice. All effects must have " - u"unique names".format(name)) + u"unique names".format(name), [i]) names.add(name) ret.append(conf) return ret diff --git a/esphomeyaml/config.py b/esphomeyaml/config.py index c8d194a346..cb3b9a78b2 100644 --- a/esphomeyaml/config.py +++ b/esphomeyaml/config.py @@ -448,8 +448,10 @@ def load_config(): def line_info(obj, highlight=True): """Display line config source.""" + if not highlight: + return None if hasattr(obj, '__config_file__'): - return color('cyan' if highlight else 'white', "[source {}:{}]" + return color('cyan', "[source {}:{}]" .format(obj.__config_file__, obj.__line__ or '?')) return None