Ejemplo n.º 1
0
def validate_broker(value):
    value = cv.string_strict(value)
    if u':' in value:
        raise vol.Invalid(u"Please specify the port using the port: option")
    if not value:
        raise vol.Invalid(u"Broker cannot be empty")
    return value
Ejemplo n.º 2
0
def validate_arduino_version(value):
    value = cv.string_strict(value)
    value_ = value.upper()
    if core.ESP_PLATFORM == ESP_PLATFORM_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
    elif core.ESP_PLATFORM == ESP_PLATFORM_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
    else:
        raise NotImplementedError
Ejemplo n.º 3
0
def do_substitution_pass(config):
    if CONF_SUBSTITUTIONS not in config:
        return config

    substitutions = config[CONF_SUBSTITUTIONS]
    if not isinstance(substitutions, dict):
        raise EsphomeyamlError(
            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 EsphomeyamlError(
            u"Error while parsing substitutions: {}".format(err))

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

    return config
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def validate_broker(value):
    value = cv.string_strict(value)
    if value.endswith(u'.local'):
        raise vol.Invalid(u"MQTT server addresses ending with '.local' are currently unsupported."
                          u" Please use the static IP instead.")
    if u':' in value:
        raise vol.Invalid(u"Please specify the port using the port: option")
    if not value:
        raise vol.Invalid(u"Broker cannot be empty")
    return value
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def validate_custom_output(value):
    if not isinstance(value, dict):
        raise vol.Invalid("Value must be dict")
    if CONF_TYPE not in value:
        raise vol.Invalid("type not specified!")
    type = cv.string_strict(value[CONF_TYPE]).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))
Ejemplo n.º 8
0
def validate_simple_esphomelib_version(value):
    value = cv.string_strict(value)
    if value.upper() == 'LATEST':
        return {
            CONF_REPOSITORY: LIBRARY_URI_REPO,
            CONF_TAG: 'v' + ESPHOMELIB_VERSION,
        }
    elif value.upper() == 'DEV':
        return {CONF_REPOSITORY: LIBRARY_URI_REPO, CONF_BRANCH: 'master'}
    elif VERSION_REGEX.match(value) is not None:
        return {
            CONF_REPOSITORY: LIBRARY_URI_REPO,
            CONF_TAG: 'v' + value,
        }
    return value
Ejemplo n.º 9
0
def validate_mac(value):
    value = cv.string_strict(value)
    parts = value.split(':')
    if len(parts) != 6:
        raise vol.Invalid(
            "MAC Address must consist of 6 : (colon) separated parts")
    parts_int = []
    if any(len(part) != 2 for part in parts):
        raise vol.Invalid("MAC Address must be format XX:XX:XX:XX:XX:XX")
    for part in parts:
        try:
            parts_int.append(int(part, 16))
        except ValueError:
            raise vol.Invalid(
                "MAC Address parts must be hexadecimal values from 00 to FF")

    return MACAddress(*parts_int)
Ejemplo n.º 10
0
def validate_simple_esphomelib_version(value):
    value = cv.string_strict(value)
    if value.upper() == 'LATEST':
        if ESPHOMELIB_VERSION == 'dev':
            return validate_simple_esphomelib_version('dev')
        return {
            CONF_REPOSITORY: LIBRARY_URI_REPO,
            CONF_TAG: 'v' + ESPHOMELIB_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 esphomelib versions!")