Example #1
0
def do_substitution_pass(config):
    if CONF_SUBSTITUTIONS not in config:
        return config

    substitutions = config[CONF_SUBSTITUTIONS]
    if not isinstance(substitutions, dict):
        raise pi4homeError(
            u"Substitutions must be a key to value mapping, got {}"
            u"".format(type(substitutions)))

    key = ''
    try:
        replace_keys = []
        for key, value in substitutions.items():
            sub = validate_substitution_key(key)
            if sub != key:
                replace_keys.append((key, sub))
            substitutions[key] = cv.string_strict(value)
        for old, new in replace_keys:
            substitutions[new] = substitutions[old]
            del substitutions[old]
    except vol.Invalid as err:
        err.path.append(key)

        raise pi4homeError(
            u"Error while parsing substitutions: {}".format(err))

    config[CONF_SUBSTITUTIONS] = substitutions
    _substitute_item(substitutions, config, [])

    return config
Example #2
0
def validate_tz(value):
    value = cv.string_strict(value)

    try:
        import pytz

        return convert_tz(pytz.timezone(value))
    except Exception:  # pylint: disable=broad-except
        return value
Example #3
0
File: wifi.py Project: khzd/pi4home
def validate_password(value):
    value = cv.string_strict(value)
    if not value:
        return value
    if len(value) < 8:
        raise vol.Invalid(u"WPA password must be at least 8 characters long")
    if len(value) > 64:
        raise vol.Invalid(u"WPA password must be at most 64 characters long")
    return value
Example #4
0
File: copy.py Project: khzd/pi4home
def validate_copy_output(value):
    if not isinstance(value, dict):
        raise vol.Invalid("Value must be dict")
    type = cv.string_strict(value.get(CONF_TYPE, 'float')).lower()
    value[CONF_TYPE] = type
    if type == 'binary':
        return BINARY_SCHEMA(value)
    if type == 'float':
        return FLOAT_SCHEMA(value)
    raise vol.Invalid("type must either be binary or float, not {}!".format(type))
Example #5
0
def validate_uid(value):
    value = cv.string_strict(value)
    for x in value.split('-'):
        if len(x) != 2:
            raise vol.Invalid(
                "Each part (separated by '-') of the UID must be two characters "
                "long.")
        try:
            x = int(x, 16)
        except ValueError:
            raise vol.Invalid(
                "Valid characters for parts of a UID are 0123456789ABCDEF.")
        if x < 0 or x > 255:
            raise vol.Invalid(
                "Valid values for UID parts (separated by '-') are 00 to FF")
    return value
Example #6
0
def validate_simple_pi4home_core_version(value):
    value = cv.string_strict(value)
    if value.upper() == 'LATEST':
        if PI4HOME_CORE_VERSION == 'dev':
            return validate_simple_pi4home_core_version('dev')
        return {
            CONF_REPOSITORY: LIBRARY_URI_REPO,
            CONF_TAG: 'v' + PI4HOME_CORE_VERSION,
        }
    if value.upper() == 'DEV':
        return {
            CONF_REPOSITORY: LIBRARY_URI_REPO,
            CONF_BRANCH: 'dev'
        }
    if VERSION_REGEX.match(value) is not None:
        return {
            CONF_REPOSITORY: LIBRARY_URI_REPO,
            CONF_TAG: 'v' + value,
        }
    raise vol.Invalid("Only simple pi4home core versions!")
Example #7
0
def validate_arduino_version(value):
    value = cv.string_strict(value)
    value_ = value.upper()
    if CORE.is_esp8266:
        if VERSION_REGEX.match(value) is not None and value_ not in PLATFORMIO_ESP8266_LUT:
            raise vol.Invalid("Unfortunately the arduino framework version '{}' is unsupported "
                              "at this time. You can override this by manually using "
                              "espressif8266@<platformio version>")
        if value_ in PLATFORMIO_ESP8266_LUT:
            return PLATFORMIO_ESP8266_LUT[value_]
        return value
    if CORE.is_esp32:
        if VERSION_REGEX.match(value) is not None and value_ not in PLATFORMIO_ESP32_LUT:
            raise vol.Invalid("Unfortunately the arduino framework version '{}' is unsupported "
                              "at this time. You can override this by manually using "
                              "espressif32@<platformio version>")
        if value_ in PLATFORMIO_ESP32_LUT:
            return PLATFORMIO_ESP32_LUT[value_]
        return value
    raise NotImplementedError