示例#1
0
 def validator_(value):
     if isinstance(value, list):
         # List of items, there are two possible options here, either a sequence of
         # actions (no then:) or a list of automations.
         try:
             # First try as a sequence of actions
             # If that succeeds, return immediately
             with cv.remove_prepend_path([CONF_THEN]):
                 return [schema({CONF_THEN: value})]
         except cv.Invalid as err:
             # Next try as a sequence of automations
             try:
                 return cv.Schema([schema])(value)
             except cv.Invalid as err2:
                 if "extra keys not allowed" in str(err2) and len(
                         err2.path) == 2:
                     # pylint: disable=raise-missing-from
                     raise err
                 if "Unable to find action" in str(err):
                     raise err2
                 raise cv.MultipleInvalid([err, err2])
     elif isinstance(value, dict):
         if CONF_THEN in value:
             return [schema(value)]
         with cv.remove_prepend_path([CONF_THEN]):
             return [schema({CONF_THEN: value})]
     # This should only happen with invalid configs, but let's have a nice error message.
     return [schema(value)]
示例#2
0
def validate_potentially_and_condition(value):
    if isinstance(value, list):
        with cv.remove_prepend_path(['and']):
            return validate_condition({
                'and': value
            })
    return validate_condition(value)
示例#3
0
    def validate(value):
        if value == SCHEMA_EXTRACT:
            return (validator, conf)

        if isinstance(value, dict):
            return validator(value)
        with cv.remove_prepend_path([conf]):
            return validator({conf: value})
示例#4
0
    def validate(value):
        # pylint: disable=comparison-with-callable
        if value == jschema_extractor:
            return validator

        if isinstance(value, dict):
            return validator(value)
        with cv.remove_prepend_path([conf]):
            return validator({conf: value})
示例#5
0
 def validate(value):
     if isinstance(value, dict):
         return validator(value)
     with cv.remove_prepend_path([CONF_ID]):
         return validator({CONF_ID: value})
示例#6
0
 def validate(value):
     if isinstance(value, dict):
         return validator(value)
     with cv.remove_prepend_path([conf]):
         return validator({conf: value})