Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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
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
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
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
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