From bb9c1faffa73d7b51c21ca2d1cfc76659cabf938 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Fri, 23 Nov 2018 13:51:22 +0100 Subject: [PATCH] Improve one_of validator (#240) --- esphomeyaml/components/binary_sensor/__init__.py | 2 +- .../components/binary_sensor/remote_receiver.py | 4 ++-- esphomeyaml/components/deep_sleep.py | 6 +++--- esphomeyaml/components/display/ssd1306_spi.py | 2 +- esphomeyaml/components/display/waveshare_epaper.py | 2 +- esphomeyaml/components/esp32_ble_beacon.py | 2 +- esphomeyaml/components/fan/__init__.py | 6 +----- esphomeyaml/components/light/fastled_clockless.py | 4 ++-- esphomeyaml/components/light/fastled_spi.py | 4 ++-- esphomeyaml/components/logger.py | 4 ++-- esphomeyaml/components/my9231.py | 3 +-- esphomeyaml/components/remote_receiver.py | 2 +- esphomeyaml/components/remote_transmitter.py | 8 +++----- esphomeyaml/components/sensor/adc.py | 3 ++- esphomeyaml/components/sensor/bme280.py | 4 ++-- esphomeyaml/components/sensor/bme680.py | 4 ++-- esphomeyaml/components/sensor/bmp280.py | 4 ++-- esphomeyaml/components/sensor/dht.py | 2 +- esphomeyaml/components/sensor/hmc5883l.py | 2 +- esphomeyaml/components/sensor/hx711.py | 2 +- esphomeyaml/components/sensor/pmsx003.py | 2 +- esphomeyaml/components/sensor/pulse_counter.py | 2 +- esphomeyaml/components/sensor/rotary_encoder.py | 2 +- esphomeyaml/components/sensor/tcs34725.py | 4 ++-- esphomeyaml/components/sensor/tsl2561.py | 2 +- .../components/switch/remote_transmitter.py | 4 ++-- esphomeyaml/components/wifi.py | 2 +- esphomeyaml/config_validation.py | 14 +++++++++++++- esphomeyaml/core_config.py | 6 +++--- esphomeyaml/pins.py | 9 ++++----- 30 files changed, 61 insertions(+), 56 deletions(-) diff --git a/esphomeyaml/components/binary_sensor/__init__.py b/esphomeyaml/components/binary_sensor/__init__.py index e4cf8a264b..9f53a0e2db 100644 --- a/esphomeyaml/components/binary_sensor/__init__.py +++ b/esphomeyaml/components/binary_sensor/__init__.py @@ -150,7 +150,7 @@ def validate_multi_click_timing(value): BINARY_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({ cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTBinarySensorComponent), - vol.Optional(CONF_DEVICE_CLASS): vol.All(vol.Lower, cv.one_of(*DEVICE_CLASSES)), + vol.Optional(CONF_DEVICE_CLASS): cv.one_of(*DEVICE_CLASSES, lower=True), vol.Optional(CONF_FILTERS): FILTERS_SCHEMA, vol.Optional(CONF_ON_PRESS): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PressTrigger), diff --git a/esphomeyaml/components/binary_sensor/remote_receiver.py b/esphomeyaml/components/binary_sensor/remote_receiver.py index 4d66caca44..d91d560430 100644 --- a/esphomeyaml/components/binary_sensor/remote_receiver.py +++ b/esphomeyaml/components/binary_sensor/remote_receiver.py @@ -39,7 +39,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend cv.GenerateID(): cv.declare_variable_id(RemoteReceiver), vol.Optional(CONF_LG): vol.Schema({ vol.Required(CONF_DATA): cv.hex_uint32_t, - vol.Optional(CONF_NBITS, default=28): vol.All(vol.Coerce(int), cv.one_of(28, 32)), + vol.Optional(CONF_NBITS, default=28): cv.one_of(28, 32, int=True), }), vol.Optional(CONF_NEC): vol.Schema({ vol.Required(CONF_ADDRESS): cv.hex_uint16_t, @@ -50,7 +50,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend }), vol.Optional(CONF_SONY): vol.Schema({ vol.Required(CONF_DATA): cv.hex_uint32_t, - vol.Optional(CONF_NBITS, default=12): vol.All(vol.Coerce(int), cv.one_of(12, 15, 20)), + vol.Optional(CONF_NBITS, default=12): cv.one_of(12, 15, 20, int=True), }), vol.Optional(CONF_PANASONIC): vol.Schema({ vol.Required(CONF_ADDRESS): cv.hex_uint16_t, diff --git a/esphomeyaml/components/deep_sleep.py b/esphomeyaml/components/deep_sleep.py index 4b5f57c2f5..2bfd9ae54a 100644 --- a/esphomeyaml/components/deep_sleep.py +++ b/esphomeyaml/components/deep_sleep.py @@ -43,12 +43,12 @@ CONFIG_SCHEMA = vol.Schema({ vol.Optional(CONF_SLEEP_DURATION): cv.positive_time_period_milliseconds, vol.Optional(CONF_WAKEUP_PIN): vol.All(cv.only_on_esp32, pins.internal_gpio_input_pin_schema, validate_pin_number), - vol.Optional(CONF_WAKEUP_PIN_MODE): vol.All(cv.only_on_esp32, vol.Upper, - cv.one_of(*WAKEUP_PIN_MODES)), + vol.Optional(CONF_WAKEUP_PIN_MODE): vol.All(cv.only_on_esp32, + cv.one_of(*WAKEUP_PIN_MODES), upper=True), vol.Optional(CONF_ESP32_EXT1_WAKEUP): vol.All(cv.only_on_esp32, vol.Schema({ vol.Required(CONF_PINS): vol.All(cv.ensure_list, [pins.shorthand_input_pin], [validate_pin_number]), - vol.Required(CONF_MODE): vol.All(vol.Upper, cv.one_of(*EXT1_WAKEUP_MODES)), + vol.Required(CONF_MODE): cv.one_of(*EXT1_WAKEUP_MODES, upper=True), })), vol.Optional(CONF_RUN_CYCLES): cv.positive_int, vol.Optional(CONF_RUN_DURATION): cv.positive_time_period_milliseconds, diff --git a/esphomeyaml/components/display/ssd1306_spi.py b/esphomeyaml/components/display/ssd1306_spi.py index bf47a5e92a..33c3f6b454 100644 --- a/esphomeyaml/components/display/ssd1306_spi.py +++ b/esphomeyaml/components/display/ssd1306_spi.py @@ -27,7 +27,7 @@ MODELS = { 'SH1106_64X48': SSD1306Model.SH1106_MODEL_64_48, } -SSD1306_MODEL = vol.All(vol.Upper, vol.Replace(' ', '_'), cv.one_of(*MODELS)) +SSD1306_MODEL = vol.All(vol.Replace(' ', '_'), cv.one_of(*MODELS, upper=True)) PLATFORM_SCHEMA = display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(SPISSD1306), diff --git a/esphomeyaml/components/display/waveshare_epaper.py b/esphomeyaml/components/display/waveshare_epaper.py index 51723440cf..b7007840e1 100644 --- a/esphomeyaml/components/display/waveshare_epaper.py +++ b/esphomeyaml/components/display/waveshare_epaper.py @@ -43,7 +43,7 @@ PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent), vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, vol.Required(CONF_DC_PIN): pins.gpio_output_pin_schema, - vol.Required(CONF_MODEL): vol.All(vol.Lower, cv.one_of(*MODELS)), + vol.Required(CONF_MODEL): cv.one_of(*MODELS, lower=True), vol.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema, vol.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t, diff --git a/esphomeyaml/components/esp32_ble_beacon.py b/esphomeyaml/components/esp32_ble_beacon.py index 2d9e8d37a4..88eb237157 100644 --- a/esphomeyaml/components/esp32_ble_beacon.py +++ b/esphomeyaml/components/esp32_ble_beacon.py @@ -14,7 +14,7 @@ CONF_MINOR = 'minor' CONFIG_SCHEMA = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(ESP32BLEBeacon), - vol.Required(CONF_TYPE): vol.All(vol.Upper, cv.one_of('IBEACON')), + vol.Required(CONF_TYPE): cv.one_of('IBEACON', upper=True), vol.Required(CONF_UUID): cv.uuid, vol.Optional(CONF_MAJOR): cv.uint16_t, vol.Optional(CONF_MINOR): cv.uint16_t, diff --git a/esphomeyaml/components/fan/__init__.py b/esphomeyaml/components/fan/__init__.py index 9874c4114f..090ec463c4 100644 --- a/esphomeyaml/components/fan/__init__.py +++ b/esphomeyaml/components/fan/__init__.py @@ -47,10 +47,6 @@ FAN_SPEEDS = { } -def validate_fan_speed(value): - return vol.All(vol.Upper, cv.one_of(*FAN_SPEEDS))(value) - - def setup_fan_core_(fan_var, mqtt_var, config): if CONF_INTERNAL in config: add(fan_var.set_internal(config[CONF_INTERNAL])) @@ -111,7 +107,7 @@ CONF_FAN_TURN_ON = 'fan.turn_on' FAN_TURN_ON_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(FanState), vol.Optional(CONF_OSCILLATING): cv.templatable(cv.boolean), - vol.Optional(CONF_SPEED): cv.templatable(validate_fan_speed), + vol.Optional(CONF_SPEED): cv.templatable(cv.one_of(*FAN_SPEEDS, upper=True)), }) diff --git a/esphomeyaml/components/light/fastled_clockless.py b/esphomeyaml/components/light/fastled_clockless.py index c779f4ceed..4ee12dc78d 100644 --- a/esphomeyaml/components/light/fastled_clockless.py +++ b/esphomeyaml/components/light/fastled_clockless.py @@ -58,12 +58,12 @@ MakeFastLEDLight = Application.struct('MakeFastLEDLight') PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeFastLEDLight), - vol.Required(CONF_CHIPSET): vol.All(vol.Upper, cv.one_of(*TYPES)), + vol.Required(CONF_CHIPSET): cv.one_of(*TYPES, upper=True), vol.Required(CONF_PIN): pins.output_pin, vol.Required(CONF_NUM_LEDS): cv.positive_not_null_int, vol.Optional(CONF_MAX_REFRESH_RATE): cv.positive_time_period_microseconds, - vol.Optional(CONF_RGB_ORDER): vol.All(vol.Upper, cv.one_of(*RGB_ORDERS)), + vol.Optional(CONF_RGB_ORDER): cv.one_of(*RGB_ORDERS, upper=True), vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, vol.Optional(CONF_COLOR_CORRECT): vol.All([cv.percentage], vol.Length(min=3, max=3)), diff --git a/esphomeyaml/components/light/fastled_spi.py b/esphomeyaml/components/light/fastled_spi.py index bd4df644e3..70b256bbb9 100644 --- a/esphomeyaml/components/light/fastled_spi.py +++ b/esphomeyaml/components/light/fastled_spi.py @@ -35,12 +35,12 @@ MakeFastLEDLight = Application.struct('MakeFastLEDLight') PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeFastLEDLight), - vol.Required(CONF_CHIPSET): vol.All(vol.Upper, cv.one_of(*CHIPSETS)), + vol.Required(CONF_CHIPSET): cv.one_of(*CHIPSETS, upper=True), vol.Required(CONF_DATA_PIN): pins.output_pin, vol.Required(CONF_CLOCK_PIN): pins.output_pin, vol.Required(CONF_NUM_LEDS): cv.positive_not_null_int, - vol.Optional(CONF_RGB_ORDER): vol.All(vol.Upper, cv.one_of(*RGB_ORDERS)), + vol.Optional(CONF_RGB_ORDER): cv.one_of(*RGB_ORDERS, upper=True), vol.Optional(CONF_MAX_REFRESH_RATE): cv.positive_time_period_microseconds, vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, diff --git a/esphomeyaml/components/logger.py b/esphomeyaml/components/logger.py index 839d371d56..0509864bc0 100644 --- a/esphomeyaml/components/logger.py +++ b/esphomeyaml/components/logger.py @@ -32,7 +32,7 @@ LOG_LEVEL_TO_ESP_LOG = { LOG_LEVEL_SEVERITY = ['NONE', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'VERBOSE', 'VERY_VERBOSE'] # pylint: disable=invalid-name -is_log_level = vol.All(vol.Upper, cv.one_of(*LOG_LEVELS)) +is_log_level = cv.one_of(*LOG_LEVELS, upper=True) def validate_local_no_higher_than_global(value): @@ -109,7 +109,7 @@ CONF_LOGGER_LOG = 'logger.log' LOGGER_LOG_ACTION_SCHEMA = vol.All(maybe_simple_message({ vol.Required(CONF_FORMAT): cv.string, vol.Optional(CONF_ARGS, default=list): vol.All(cv.ensure_list, [cv.lambda_]), - vol.Optional(CONF_LEVEL, default="DEBUG"): vol.All(vol.Upper, cv.one_of(*LOG_LEVEL_TO_ESP_LOG)), + vol.Optional(CONF_LEVEL, default="DEBUG"): cv.one_of(*LOG_LEVEL_TO_ESP_LOG, upper=True), vol.Optional(CONF_TAG, default="main"): cv.string, }), validate_printf) diff --git a/esphomeyaml/components/my9231.py b/esphomeyaml/components/my9231.py index a52e1b1033..a3259d3c68 100644 --- a/esphomeyaml/components/my9231.py +++ b/esphomeyaml/components/my9231.py @@ -20,8 +20,7 @@ MY9231_SCHEMA = vol.Schema({ vol.Range(3, 1020)), vol.Optional(CONF_NUM_CHIPS): vol.All(vol.Coerce(int), vol.Range(1, 255)), - vol.Optional(CONF_BIT_DEPTH): vol.All(vol.Coerce(int), - cv.one_of(8, 12, 14, 16)), + vol.Optional(CONF_BIT_DEPTH): cv.one_of(8, 12, 14, 16, int=True), vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool), }).extend(cv.COMPONENT_SCHEMA.schema) diff --git a/esphomeyaml/components/remote_receiver.py b/esphomeyaml/components/remote_receiver.py index 878e5a6fc5..7e143d4823 100644 --- a/esphomeyaml/components/remote_receiver.py +++ b/esphomeyaml/components/remote_receiver.py @@ -40,7 +40,7 @@ CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({ vol.Required(CONF_PIN): pins.gpio_input_pin_schema, vol.Optional(CONF_DUMP, default=[]): vol.Any(validate_dumpers_all, - vol.All(cv.ensure_list, [vol.All(vol.Lower, cv.one_of(*DUMPERS))])), + vol.All(cv.ensure_list, [cv.one_of(*DUMPERS, lower=True)])), vol.Optional(CONF_TOLERANCE): vol.All(cv.percentage_int, vol.Range(min=0)), vol.Optional(CONF_BUFFER_SIZE): cv.validate_bytes, vol.Optional(CONF_FILTER): cv.positive_time_period_microseconds, diff --git a/esphomeyaml/components/remote_transmitter.py b/esphomeyaml/components/remote_transmitter.py index 144ac2bfdf..49d1abf4b3 100644 --- a/esphomeyaml/components/remote_transmitter.py +++ b/esphomeyaml/components/remote_transmitter.py @@ -61,17 +61,15 @@ RC_SWITCH_TYPE_B_SCHEMA = vol.Schema({ vol.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA, }) RC_SWITCH_TYPE_C_SCHEMA = vol.Schema({ - vol.Required(CONF_FAMILY): vol.All( - cv.string, vol.Lower, - cv.one_of('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p')), + vol.Required(CONF_FAMILY): cv.one_of('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', + 'l', 'm', 'n', 'o', 'p', lower=True), vol.Required(CONF_GROUP): vol.All(cv.uint8_t, vol.Range(min=1, max=4)), vol.Required(CONF_DEVICE): vol.All(cv.uint8_t, vol.Range(min=1, max=4)), vol.Required(CONF_STATE): cv.boolean, vol.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA, }) RC_SWITCH_TYPE_D_SCHEMA = vol.Schema({ - vol.Required(CONF_GROUP): vol.All(cv.string, vol.Lower, cv.one_of('a', 'b', 'c', 'd')), + vol.Required(CONF_GROUP): cv.one_of('a', 'b', 'c', 'd', lower=True), vol.Required(CONF_DEVICE): vol.All(cv.uint8_t, vol.Range(min=1, max=3)), vol.Required(CONF_STATE): cv.boolean, vol.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA, diff --git a/esphomeyaml/components/sensor/adc.py b/esphomeyaml/components/sensor/adc.py index f629ee3d4d..5c3cc1cd3c 100644 --- a/esphomeyaml/components/sensor/adc.py +++ b/esphomeyaml/components/sensor/adc.py @@ -29,7 +29,8 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(ADCSensorComponent), cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeADCSensor), vol.Required(CONF_PIN): validate_adc_pin, - vol.Optional(CONF_ATTENUATION): vol.All(cv.only_on_esp32, cv.one_of(*ATTENUATION_MODES)), + vol.Optional(CONF_ATTENUATION): vol.All(cv.only_on_esp32, cv.one_of(*ATTENUATION_MODES, + lower=True)), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) diff --git a/esphomeyaml/components/sensor/bme280.py b/esphomeyaml/components/sensor/bme280.py index 23e395f6ef..b0d0331aff 100644 --- a/esphomeyaml/components/sensor/bme280.py +++ b/esphomeyaml/components/sensor/bme280.py @@ -28,7 +28,7 @@ IIR_FILTER_OPTIONS = { } BME280_OVERSAMPLING_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({ - vol.Optional(CONF_OVERSAMPLING): vol.All(vol.Upper, cv.one_of(*OVERSAMPLING_OPTIONS)), + vol.Optional(CONF_OVERSAMPLING): cv.one_of(*OVERSAMPLING_OPTIONS, upper=True), }) MakeBME280Sensor = Application.struct('MakeBME280Sensor') @@ -51,7 +51,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ vol.Required(CONF_HUMIDITY): cv.nameable(BME280_OVERSAMPLING_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(BME280HumiditySensor), })), - vol.Optional(CONF_IIR_FILTER): vol.All(vol.Upper, cv.one_of(*IIR_FILTER_OPTIONS)), + vol.Optional(CONF_IIR_FILTER): cv.one_of(*IIR_FILTER_OPTIONS, upper=True), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema) diff --git a/esphomeyaml/components/sensor/bme680.py b/esphomeyaml/components/sensor/bme680.py index 71778574a1..4aeafa3e9e 100644 --- a/esphomeyaml/components/sensor/bme680.py +++ b/esphomeyaml/components/sensor/bme680.py @@ -33,7 +33,7 @@ IIR_FILTER_OPTIONS = { } BME680_OVERSAMPLING_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({ - vol.Optional(CONF_OVERSAMPLING): vol.All(vol.Upper, cv.one_of(*OVERSAMPLING_OPTIONS)), + vol.Optional(CONF_OVERSAMPLING): cv.one_of(*OVERSAMPLING_OPTIONS, upper=True), }) MakeBME680Sensor = Application.struct('MakeBME680Sensor') @@ -61,7 +61,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ vol.Required(CONF_GAS_RESISTANCE): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(BME680GasResistanceSensor), })), - vol.Optional(CONF_IIR_FILTER): vol.All(vol.Upper, cv.one_of(*IIR_FILTER_OPTIONS)), + vol.Optional(CONF_IIR_FILTER): cv.one_of(*IIR_FILTER_OPTIONS, upper=True), vol.Optional(CONF_HEATER): vol.Any(None, vol.All(vol.Schema({ vol.Optional(CONF_TEMPERATURE, default=320): vol.All(vol.Coerce(int), vol.Range(200, 400)), vol.Optional(CONF_DURATION, default='150ms'): vol.All( diff --git a/esphomeyaml/components/sensor/bmp280.py b/esphomeyaml/components/sensor/bmp280.py index 35d30403d8..6101659106 100644 --- a/esphomeyaml/components/sensor/bmp280.py +++ b/esphomeyaml/components/sensor/bmp280.py @@ -28,7 +28,7 @@ IIR_FILTER_OPTIONS = { } BMP280_OVERSAMPLING_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({ - vol.Optional(CONF_OVERSAMPLING): vol.All(vol.Upper, cv.one_of(*OVERSAMPLING_OPTIONS)), + vol.Optional(CONF_OVERSAMPLING): cv.one_of(*OVERSAMPLING_OPTIONS, upper=True), }) MakeBMP280Sensor = Application.struct('MakeBMP280Sensor') @@ -46,7 +46,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ vol.Required(CONF_PRESSURE): cv.nameable(BMP280_OVERSAMPLING_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(BMP280PressureSensor), })), - vol.Optional(CONF_IIR_FILTER): vol.All(vol.Upper, cv.one_of(*IIR_FILTER_OPTIONS)), + vol.Optional(CONF_IIR_FILTER): cv.one_of(*IIR_FILTER_OPTIONS, upper=True), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema) diff --git a/esphomeyaml/components/sensor/dht.py b/esphomeyaml/components/sensor/dht.py index a13d0f0fdd..3d8b4be963 100644 --- a/esphomeyaml/components/sensor/dht.py +++ b/esphomeyaml/components/sensor/dht.py @@ -34,7 +34,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ vol.Required(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(DHTHumiditySensor), })), - vol.Optional(CONF_MODEL): vol.All(vol.Upper, cv.one_of(*DHT_MODELS)), + vol.Optional(CONF_MODEL): cv.one_of(*DHT_MODELS, upper=True), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema) diff --git a/esphomeyaml/components/sensor/hmc5883l.py b/esphomeyaml/components/sensor/hmc5883l.py index a4ed04cf0a..e5ba7ddc5a 100644 --- a/esphomeyaml/components/sensor/hmc5883l.py +++ b/esphomeyaml/components/sensor/hmc5883l.py @@ -37,7 +37,7 @@ def validate_range(value): value = cv.string(value) if value.endswith(u'µT') or value.endswith('uT'): value = value[:-2] - return cv.one_of(*HMC5883L_RANGES)(int(value)) + return cv.one_of(*HMC5883L_RANGES, int=True)(value) SENSOR_KEYS = [CONF_FIELD_STRENGTH_X, CONF_FIELD_STRENGTH_Y, CONF_FIELD_STRENGTH_Z, diff --git a/esphomeyaml/components/sensor/hx711.py b/esphomeyaml/components/sensor/hx711.py index 9f35e31cca..38e32393bc 100644 --- a/esphomeyaml/components/sensor/hx711.py +++ b/esphomeyaml/components/sensor/hx711.py @@ -24,7 +24,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeHX711Sensor), vol.Required(CONF_DOUT_PIN): pins.gpio_input_pin_schema, vol.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema, - vol.Optional(CONF_GAIN): vol.All(cv.int_, cv.one_of(*GAINS)), + vol.Optional(CONF_GAIN): cv.one_of(*GAINS, int=True), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) diff --git a/esphomeyaml/components/sensor/pmsx003.py b/esphomeyaml/components/sensor/pmsx003.py index fe4f2bc089..9858e4a66b 100644 --- a/esphomeyaml/components/sensor/pmsx003.py +++ b/esphomeyaml/components/sensor/pmsx003.py @@ -48,7 +48,7 @@ PMSX003_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(PMSX003Component), cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent), - vol.Required(CONF_TYPE): vol.All(vol.Upper, cv.one_of(*PMSX003_TYPES)), + vol.Required(CONF_TYPE): cv.one_of(*PMSX003_TYPES, upper=True), vol.Optional(CONF_PM_1_0): cv.nameable(PMSX003_SENSOR_SCHEMA), vol.Optional(CONF_PM_2_5): cv.nameable(PMSX003_SENSOR_SCHEMA), diff --git a/esphomeyaml/components/sensor/pulse_counter.py b/esphomeyaml/components/sensor/pulse_counter.py index b73d62123e..95c17102d8 100644 --- a/esphomeyaml/components/sensor/pulse_counter.py +++ b/esphomeyaml/components/sensor/pulse_counter.py @@ -16,7 +16,7 @@ COUNT_MODES = { 'DECREMENT': PulseCounterCountMode.PULSE_COUNTER_DECREMENT, } -COUNT_MODE_SCHEMA = vol.All(vol.Upper, cv.one_of(*COUNT_MODES)) +COUNT_MODE_SCHEMA = cv.one_of(*COUNT_MODES, upper=True) PulseCounterBase = sensor.sensor_ns.class_('PulseCounterBase') MakePulseCounterSensor = Application.struct('MakePulseCounterSensor') diff --git a/esphomeyaml/components/sensor/rotary_encoder.py b/esphomeyaml/components/sensor/rotary_encoder.py index 1be3d44803..4713b2b821 100644 --- a/esphomeyaml/components/sensor/rotary_encoder.py +++ b/esphomeyaml/components/sensor/rotary_encoder.py @@ -27,7 +27,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ vol.Required(CONF_PIN_A): pins.internal_gpio_input_pin_schema, vol.Required(CONF_PIN_B): pins.internal_gpio_input_pin_schema, vol.Optional(CONF_PIN_RESET): pins.internal_gpio_input_pin_schema, - vol.Optional(CONF_RESOLUTION): vol.All(cv.string, cv.one_of(*RESOLUTIONS)), + vol.Optional(CONF_RESOLUTION): cv.one_of(*RESOLUTIONS, string=True), }).extend(cv.COMPONENT_SCHEMA.schema)) diff --git a/esphomeyaml/components/sensor/tcs34725.py b/esphomeyaml/components/sensor/tcs34725.py index 8322e1f054..7082bc1ba1 100644 --- a/esphomeyaml/components/sensor/tcs34725.py +++ b/esphomeyaml/components/sensor/tcs34725.py @@ -62,8 +62,8 @@ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ vol.Optional(CONF_COLOR_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TCS35725ColorTemperatureSensor), })), - vol.Optional(CONF_INTEGRATION_TIME): cv.one_of(*TCS34725_INTEGRATION_TIMES), - vol.Optional(CONF_GAIN): vol.All(vol.Upper, cv.one_of(*TCS34725_GAINS)), + vol.Optional(CONF_INTEGRATION_TIME): cv.one_of(*TCS34725_INTEGRATION_TIMES, lower=True), + vol.Optional(CONF_GAIN): vol.All(vol.Upper, cv.one_of(*TCS34725_GAINS), upper=True), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(*SENSOR_KEYS)) diff --git a/esphomeyaml/components/sensor/tsl2561.py b/esphomeyaml/components/sensor/tsl2561.py index 53112efc46..30b7940d62 100644 --- a/esphomeyaml/components/sensor/tsl2561.py +++ b/esphomeyaml/components/sensor/tsl2561.py @@ -40,7 +40,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTSL2561Sensor), vol.Optional(CONF_ADDRESS, default=0x39): cv.i2c_address, vol.Optional(CONF_INTEGRATION_TIME): validate_integration_time, - vol.Optional(CONF_GAIN): vol.All(vol.Upper, cv.one_of(*GAINS)), + vol.Optional(CONF_GAIN): cv.one_of(*GAINS, upper=True), vol.Optional(CONF_IS_CS_PACKAGE): cv.boolean, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) diff --git a/esphomeyaml/components/switch/remote_transmitter.py b/esphomeyaml/components/switch/remote_transmitter.py index effa4121d5..c6320d2cc8 100644 --- a/esphomeyaml/components/switch/remote_transmitter.py +++ b/esphomeyaml/components/switch/remote_transmitter.py @@ -42,7 +42,7 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(RemoteTransmitter), vol.Optional(CONF_LG): vol.Schema({ vol.Required(CONF_DATA): cv.hex_uint32_t, - vol.Optional(CONF_NBITS, default=28): vol.All(vol.Coerce(int), cv.one_of(28, 32)), + vol.Optional(CONF_NBITS, default=28): cv.one_of(28, 32, int=True), }), vol.Optional(CONF_NEC): vol.Schema({ vol.Required(CONF_ADDRESS): cv.hex_uint16_t, @@ -53,7 +53,7 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ }), vol.Optional(CONF_SONY): vol.Schema({ vol.Required(CONF_DATA): cv.hex_uint32_t, - vol.Optional(CONF_NBITS, default=12): vol.All(vol.Coerce(int), cv.one_of(12, 15, 20)), + vol.Optional(CONF_NBITS, default=12): cv.one_of(12, 15, 20, int=True), }), vol.Optional(CONF_PANASONIC): vol.Schema({ vol.Required(CONF_ADDRESS): cv.hex_uint16_t, diff --git a/esphomeyaml/components/wifi.py b/esphomeyaml/components/wifi.py index a627f9bb73..4f160b366e 100644 --- a/esphomeyaml/components/wifi.py +++ b/esphomeyaml/components/wifi.py @@ -86,7 +86,7 @@ CONFIG_SCHEMA = vol.All(vol.Schema({ vol.Optional(CONF_HOSTNAME): cv.hostname, vol.Optional(CONF_DOMAIN, default='.local'): cv.domain_name, vol.Optional(CONF_REBOOT_TIMEOUT): cv.positive_time_period_milliseconds, - vol.Optional(CONF_POWER_SAVE_MODE): vol.All(vol.Upper, cv.one_of(*WIFI_POWER_SAVE_MODES)), + vol.Optional(CONF_POWER_SAVE_MODE): cv.one_of(*WIFI_POWER_SAVE_MODES, upper=True), }), validate) diff --git a/esphomeyaml/config_validation.py b/esphomeyaml/config_validation.py index dac218c76b..6a6cac907f 100644 --- a/esphomeyaml/config_validation.py +++ b/esphomeyaml/config_validation.py @@ -584,10 +584,22 @@ def valid(value): return value -def one_of(*values): +def one_of(*values, **kwargs): options = u', '.join(u"'{}'".format(x) for x in values) + lower = kwargs.get('lower', False) + upper = kwargs.get('upper', False) + string_ = kwargs.get('string', False) or lower or upper + to_int = kwargs.get('int', False) def validator(value): + if string_: + value = string(value) + if to_int: + value = int_(value) + if lower: + value = vol.Lower(value) + if upper: + value = vol.Upper(value) if value not in values: raise vol.Invalid(u"Unknown value '{}', must be one of {}".format(value, options)) return value diff --git a/esphomeyaml/core_config.py b/esphomeyaml/core_config.py index cbeea9e486..0890b54b04 100644 --- a/esphomeyaml/core_config.py +++ b/esphomeyaml/core_config.py @@ -158,15 +158,15 @@ def default_build_path(): CONFIG_SCHEMA = vol.Schema({ vol.Required(CONF_NAME): cv.valid_name, - vol.Required(CONF_PLATFORM): vol.All(vol.Upper, cv.one_of('ESP8266', 'ESPRESSIF8266', - 'ESP32', 'ESPRESSIF32')), + vol.Required(CONF_PLATFORM): cv.one_of('ESP8266', 'ESPRESSIF8266', 'ESP32', 'ESPRESSIF32', + upper=True), vol.Required(CONF_BOARD): validate_board, vol.Optional(CONF_ESPHOMELIB_VERSION, default='latest'): ESPHOMELIB_VERSION_SCHEMA, vol.Optional(CONF_ARDUINO_VERSION, default='recommended'): validate_arduino_version, vol.Optional(CONF_USE_CUSTOM_CODE, default=False): cv.boolean, vol.Optional(CONF_BUILD_PATH, default=default_build_path): cv.string, - vol.Optional(CONF_BOARD_FLASH_MODE): vol.All(vol.Lower, cv.one_of(*BUILD_FLASH_MODES)), + vol.Optional(CONF_BOARD_FLASH_MODE): cv.one_of(*BUILD_FLASH_MODES, lower=True), vol.Optional(CONF_ON_BOOT): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(StartupTrigger), vol.Optional(CONF_PRIORITY): vol.Coerce(float), diff --git a/esphomeyaml/pins.py b/esphomeyaml/pins.py index 8d736ee9b2..0734a4f8fe 100644 --- a/esphomeyaml/pins.py +++ b/esphomeyaml/pins.py @@ -254,11 +254,10 @@ PIN_MODES_ESP32 = [ def pin_mode(value): - value = vol.All(vol.Coerce(str), vol.Upper)(value) if core.ESP_PLATFORM == ESP_PLATFORM_ESP32: - return cv.one_of(*PIN_MODES_ESP32)(value) + return cv.one_of(*PIN_MODES_ESP32, upper=True)(value) elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266: - return cv.one_of(*PIN_MODES_ESP8266)(value) + return cv.one_of(*PIN_MODES_ESP8266, upper=True)(value) raise vol.Invalid(u"Invalid ESP platform.") @@ -291,12 +290,12 @@ PCF8574Component = io_ns.class_('PCF8574Component', Component, I2CDevice) PCF8574_OUTPUT_PIN_SCHEMA = vol.Schema({ vol.Required(CONF_PCF8574): cv.use_variable_id(PCF8574Component), vol.Required(CONF_NUMBER): vol.Coerce(int), - vol.Optional(CONF_MODE): vol.All(vol.Upper, cv.one_of("OUTPUT")), + vol.Optional(CONF_MODE): cv.one_of("OUTPUT", upper=True), vol.Optional(CONF_INVERTED, default=False): cv.boolean, }) PCF8574_INPUT_PIN_SCHEMA = PCF8574_OUTPUT_PIN_SCHEMA.extend({ - vol.Optional(CONF_MODE): vol.All(vol.Upper, cv.one_of("INPUT", "INPUT_PULLUP")), + vol.Optional(CONF_MODE): cv.one_of("INPUT", "INPUT_PULLUP", upper=True), })