mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 07:08:20 +00:00
Update
This commit is contained in:
parent
fb1013e885
commit
2ec5c5e2f3
@ -30,23 +30,28 @@ def validate_recursive_condition(value):
|
|||||||
for i, item in enumerate(value):
|
for i, item in enumerate(value):
|
||||||
item = copy.deepcopy(item)
|
item = copy.deepcopy(item)
|
||||||
if not isinstance(item, dict):
|
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)
|
key = next((x for x in item if x != CONF_CONDITION_ID), None)
|
||||||
if key is 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:
|
if key not in CONDITION_REGISTRY:
|
||||||
raise vol.Invalid(u"Unable to find condition with the name '{}', is the "
|
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)
|
item.setdefault(CONF_CONDITION_ID, None)
|
||||||
key2 = next((x for x in item if x != CONF_CONDITION_ID and x != key), None)
|
key2 = next((x for x in item if x != CONF_CONDITION_ID and x != key), None)
|
||||||
if key2 is not None:
|
if key2 is not None:
|
||||||
raise vol.Invalid(u"Cannot have two conditions in one item. Key '{}' overrides '{}'! "
|
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"Did you forget to indent the block inside the condition?"
|
||||||
u"".format(key, key2))
|
u"".format(key, key2), [i])
|
||||||
validator = CONDITION_REGISTRY[key][0]
|
validator = CONDITION_REGISTRY[key][0]
|
||||||
|
try:
|
||||||
|
condition = validator(item[key])
|
||||||
|
except vol.Invalid as e:
|
||||||
|
e.prepend([i])
|
||||||
|
raise e
|
||||||
value[i] = {
|
value[i] = {
|
||||||
CONF_CONDITION_ID: cv.declare_variable_id(Condition)(item[CONF_CONDITION_ID]),
|
CONF_CONDITION_ID: cv.declare_variable_id(Condition)(item[CONF_CONDITION_ID]),
|
||||||
key: validator(item[key])
|
key: condition,
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@ -56,23 +61,28 @@ def validate_recursive_action(value):
|
|||||||
for i, item in enumerate(value):
|
for i, item in enumerate(value):
|
||||||
item = copy.deepcopy(item)
|
item = copy.deepcopy(item)
|
||||||
if not isinstance(item, dict):
|
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)
|
key = next((x for x in item if x != CONF_ACTION_ID), None)
|
||||||
if key is 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:
|
if key not in ACTION_REGISTRY:
|
||||||
raise vol.Invalid(u"Unable to find action with the name '{}', is the component loaded?"
|
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)
|
item.setdefault(CONF_ACTION_ID, None)
|
||||||
key2 = next((x for x in item if x != CONF_ACTION_ID and x != key), None)
|
key2 = next((x for x in item if x != CONF_ACTION_ID and x != key), None)
|
||||||
if key2 is not None:
|
if key2 is not None:
|
||||||
raise vol.Invalid(u"Cannot have two actions in one item. Key '{}' overrides '{}'! "
|
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"Did you forget to indent the block inside the action?"
|
||||||
u"".format(key, key2))
|
u"".format(key, key2), [i])
|
||||||
validator = ACTION_REGISTRY[key][0]
|
validator = ACTION_REGISTRY[key][0]
|
||||||
|
try:
|
||||||
|
action = validator(item[key])
|
||||||
|
except vol.Invalid as e:
|
||||||
|
e.prepend([i])
|
||||||
|
raise e
|
||||||
value[i] = {
|
value[i] = {
|
||||||
CONF_ACTION_ID: cv.declare_variable_id(Action)(item[CONF_ACTION_ID]),
|
CONF_ACTION_ID: cv.declare_variable_id(Action)(item[CONF_ACTION_ID]),
|
||||||
key: validator(item[key])
|
key: action,
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -182,21 +182,21 @@ def validate_effects(allowed_effects):
|
|||||||
ret = []
|
ret = []
|
||||||
for i, effect in enumerate(value):
|
for i, effect in enumerate(value):
|
||||||
if not isinstance(effect, dict):
|
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:
|
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:
|
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()))
|
key = next(iter(effect.keys()))
|
||||||
if key not in allowed_effects:
|
if key not in allowed_effects:
|
||||||
raise vol.Invalid("The effect '{}' does not exist or is not allowed for this "
|
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 {}
|
effect[key] = effect[key] or {}
|
||||||
conf = EFFECTS_SCHEMA(effect)
|
conf = EFFECTS_SCHEMA(effect)
|
||||||
name = conf[key][CONF_NAME]
|
name = conf[key][CONF_NAME]
|
||||||
if name in names:
|
if name in names:
|
||||||
raise vol.Invalid(u"Found the effect name '{}' twice. All effects must have "
|
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)
|
names.add(name)
|
||||||
ret.append(conf)
|
ret.append(conf)
|
||||||
return ret
|
return ret
|
||||||
|
@ -448,8 +448,10 @@ def load_config():
|
|||||||
|
|
||||||
def line_info(obj, highlight=True):
|
def line_info(obj, highlight=True):
|
||||||
"""Display line config source."""
|
"""Display line config source."""
|
||||||
|
if not highlight:
|
||||||
|
return None
|
||||||
if hasattr(obj, '__config_file__'):
|
if hasattr(obj, '__config_file__'):
|
||||||
return color('cyan' if highlight else 'white', "[source {}:{}]"
|
return color('cyan', "[source {}:{}]"
|
||||||
.format(obj.__config_file__, obj.__line__ or '?'))
|
.format(obj.__config_file__, obj.__line__ or '?'))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user