How to use the esphome.config_validation.Invalid function in esphome

To help you get started, we’ve selected a few esphome examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esphome / esphome / esphome / components / pn532 / binary_sensor.py View on Github external
def validate_uid(value):
    value = cv.string_strict(value)
    for x in value.split('-'):
        if len(x) != 2:
            raise cv.Invalid("Each part (separated by '-') of the UID must be two characters "
                             "long.")
        try:
            x = int(x, 16)
        except ValueError:
            raise cv.Invalid("Valid characters for parts of a UID are 0123456789ABCDEF.")
        if x < 0 or x > 255:
            raise cv.Invalid("Valid values for UID parts (separated by '-') are 00 to FF")
    return value
github esphome / esphome / esphome / components / wifi / __init__.py View on Github external
def validate_password(value):
    value = cv.string_strict(value)
    if not value:
        return value
    if len(value) < 8:
        raise cv.Invalid("WPA password must be at least 8 characters long")
    if len(value) > 64:
        raise cv.Invalid("WPA password must be at most 64 characters long")
    return value
github esphome / esphome / esphome / components / sensor / __init__.py View on Github external
def validate_calibrate_polynomial(config):
    if config[CONF_DEGREE] >= len(config[CONF_DATAPOINTS]):
        raise cv.Invalid("Degree is too high! Maximum possible degree with given datapoints is "
                         "{}".format(len(config[CONF_DATAPOINTS]) - 1), [CONF_DEGREE])
    return config
github esphome / esphome / esphome / pins.py View on Github external
def output_pin(value):
    value = validate_gpio_pin(value)
    if CORE.is_esp32:
        if 34 <= value <= 39:
            raise cv.Invalid("ESP32: GPIO{} (34-39) can only be used as an "
                             "input pin.".format(value))
        return value
    if CORE.is_esp8266:
        if value == 17:
            raise cv.Invalid("GPIO17 (TOUT) is an analog-only pin on the ESP8266.")
        return value
    raise NotImplementedError
github esphome / esphome / esphome / components / deep_sleep / __init__.py View on Github external
def validate_pin_number(value):
    valid_pins = [0, 2, 4, 12, 13, 14, 15, 25, 26, 27, 32, 33, 34, 35, 36, 37, 38, 39]
    if value[CONF_NUMBER] not in valid_pins:
        raise cv.Invalid("Only pins {} support wakeup"
                         "".format(', '.join(str(x) for x in valid_pins)))
    return value
github esphome / esphome / esphome / automation.py View on Github external
def validator(value):
        value = validator_(value)
        if extra_validators is not None:
            value = cv.Schema([extra_validators])(value)
        if single:
            if len(value) != 1:
                raise cv.Invalid("Cannot have more than 1 automation for templates")
            return value[0]
        return value
github esphome / esphome / esphome / components / uart / __init__.py View on Github external
def validate_rx_pin(value):
    value = pins.input_pin(value)
    if CORE.is_esp8266 and value >= 16:
        raise cv.Invalid("Pins GPIO16 and GPIO17 cannot be used as RX pins on ESP8266.")
    return value
github esphome / esphome / esphome / pins.py View on Github external
def output_pin(value):
    value = validate_gpio_pin(value)
    if CORE.is_esp32:
        if 34 <= value <= 39:
            raise cv.Invalid("ESP32: GPIO{} (34-39) can only be used as an "
                             "input pin.".format(value))
        return value
    if CORE.is_esp8266:
        if value == 17:
            raise cv.Invalid("GPIO17 (TOUT) is an analog-only pin on the ESP8266.")
        return value
    raise NotImplementedError