From e3736203939e077210750a092040f28686c1e333 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 11 May 2019 11:40:29 +0200 Subject: [PATCH] Use int_range validator (#542) * Use int_range validator Just keeping code clean. * Lint --- esphome/components/dallas/sensor.py | 2 +- esphome/components/esp32_camera/__init__.py | 4 ++-- esphome/components/font/__init__.py | 2 +- esphome/components/ledc/output.py | 4 ++-- esphome/components/max7219/display.py | 4 ++-- esphome/components/my9231/__init__.py | 4 ++-- esphome/components/my9231/output.py | 2 +- esphome/components/pca9685/output.py | 2 +- esphome/components/remote_base/__init__.py | 12 ++++++------ esphome/components/ttp229_lsf/binary_sensor.py | 2 +- esphome/components/uart/__init__.py | 2 +- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/esphome/components/dallas/sensor.py b/esphome/components/dallas/sensor.py index 2236f919f2..df9d561995 100644 --- a/esphome/components/dallas/sensor.py +++ b/esphome/components/dallas/sensor.py @@ -13,7 +13,7 @@ CONFIG_SCHEMA = cv.All(sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1).e cv.Optional(CONF_ADDRESS): cv.hex_int, cv.Optional(CONF_INDEX): cv.positive_int, - cv.Optional(CONF_RESOLUTION, default=12): cv.All(cv.int_, cv.Range(min=9, max=12)), + cv.Optional(CONF_RESOLUTION, default=12): cv.int_range(min=9, max=12), }), cv.has_exactly_one_key(CONF_ADDRESS, CONF_INDEX)) diff --git a/esphome/components/esp32_camera/__init__.py b/esphome/components/esp32_camera/__init__.py index 4e7901571f..c69e0a5710 100644 --- a/esphome/components/esp32_camera/__init__.py +++ b/esphome/components/esp32_camera/__init__.py @@ -55,7 +55,7 @@ CONF_BRIGHTNESS = 'brightness' CONF_SATURATION = 'saturation' CONF_TEST_PATTERN = 'test_pattern' -camera_range_param = cv.All(cv.int_, cv.Range(min=-2, max=2)) +camera_range_param = cv.int_range(min=-2, max=2) CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(ESP32Camera), @@ -81,7 +81,7 @@ CONFIG_SCHEMA = cv.Schema({ cv.Optional(CONF_IDLE_FRAMERATE, default='0.1 fps'): cv.All(cv.framerate, cv.Range(min=0, max=1)), cv.Optional(CONF_RESOLUTION, default='640X480'): cv.enum(FRAME_SIZES, upper=True), - cv.Optional(CONF_JPEG_QUALITY, default=10): cv.All(cv.int_, cv.Range(min=10, max=63)), + cv.Optional(CONF_JPEG_QUALITY, default=10): cv.int_range(min=10, max=63), cv.Optional(CONF_CONTRAST, default=0): camera_range_param, cv.Optional(CONF_BRIGHTNESS, default=0): camera_range_param, cv.Optional(CONF_SATURATION, default=0): camera_range_param, diff --git a/esphome/components/font/__init__.py b/esphome/components/font/__init__.py index 774b49dbc1..e77bd5da8e 100644 --- a/esphome/components/font/__init__.py +++ b/esphome/components/font/__init__.py @@ -70,7 +70,7 @@ FONT_SCHEMA = cv.Schema({ cv.Required(CONF_ID): cv.declare_id(Font), cv.Required(CONF_FILE): validate_truetype_file, cv.Optional(CONF_GLYPHS, default=DEFAULT_GLYPHS): validate_glyphs, - cv.Optional(CONF_SIZE, default=20): cv.All(cv.int_, cv.Range(min=1)), + cv.Optional(CONF_SIZE, default=20): cv.int_range(min=1), cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_id(cg.uint8), }) diff --git a/esphome/components/ledc/output.py b/esphome/components/ledc/output.py index 63b32eedf0..e9e41c398a 100644 --- a/esphome/components/ledc/output.py +++ b/esphome/components/ledc/output.py @@ -25,8 +25,8 @@ CONFIG_SCHEMA = cv.All(output.FLOAT_OUTPUT_SCHEMA.extend({ cv.Required(CONF_ID): cv.declare_id(LEDCOutput), cv.Required(CONF_PIN): pins.internal_gpio_output_pin_schema, cv.Optional(CONF_FREQUENCY, default='1kHz'): cv.frequency, - cv.Optional(CONF_BIT_DEPTH, default=12): cv.All(cv.int_, cv.Range(min=1, max=15)), - cv.Optional(CONF_CHANNEL): cv.All(cv.int_, cv.Range(min=0, max=15)) + cv.Optional(CONF_BIT_DEPTH, default=12): cv.int_range(min=1, max=15), + cv.Optional(CONF_CHANNEL): cv.int_range(min=0, max=15), }).extend(cv.COMPONENT_SCHEMA), validate_frequency_bit_depth) diff --git a/esphome/components/max7219/display.py b/esphome/components/max7219/display.py index b40fbafddb..c96454ce8c 100644 --- a/esphome/components/max7219/display.py +++ b/esphome/components/max7219/display.py @@ -12,8 +12,8 @@ MAX7219ComponentRef = MAX7219Component.operator('ref') CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(MAX7219Component), - cv.Optional(CONF_NUM_CHIPS, default=1): cv.All(cv.uint8_t, cv.Range(min=1)), - cv.Optional(CONF_INTENSITY, default=15): cv.All(cv.uint8_t, cv.Range(min=0, max=15)), + cv.Optional(CONF_NUM_CHIPS, default=1): cv.int_range(min=1, max=255), + cv.Optional(CONF_INTENSITY, default=15): cv.int_range(min=0, max=15), }).extend(cv.polling_component_schema('1s')).extend(spi.SPI_DEVICE_SCHEMA) diff --git a/esphome/components/my9231/__init__.py b/esphome/components/my9231/__init__.py index 82dfe3e083..7ca0a30cab 100644 --- a/esphome/components/my9231/__init__.py +++ b/esphome/components/my9231/__init__.py @@ -13,8 +13,8 @@ CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(MY9231OutputComponent), cv.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema, cv.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema, - cv.Optional(CONF_NUM_CHANNELS, default=6): cv.All(cv.int_, cv.Range(min=3, max=1020)), - cv.Optional(CONF_NUM_CHIPS, default=2): cv.All(cv.int_, cv.Range(min=1, max=255)), + cv.Optional(CONF_NUM_CHANNELS, default=6): cv.int_range(min=3, max=1020), + cv.Optional(CONF_NUM_CHIPS, default=2): cv.int_range(min=1, max=255), cv.Optional(CONF_BIT_DEPTH, default=16): cv.one_of(8, 12, 14, 16, int=True), }).extend(cv.COMPONENT_SCHEMA) diff --git a/esphome/components/my9231/output.py b/esphome/components/my9231/output.py index 62460faec4..9acc8bdcd6 100644 --- a/esphome/components/my9231/output.py +++ b/esphome/components/my9231/output.py @@ -13,7 +13,7 @@ CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend({ cv.GenerateID(CONF_MY9231_ID): cv.use_id(MY9231OutputComponent), cv.Required(CONF_ID): cv.declare_id(Channel), - cv.Required(CONF_CHANNEL): cv.All(cv.int_, cv.Range(min=0, max=65535)), + cv.Required(CONF_CHANNEL): cv.uint16_t, }).extend(cv.COMPONENT_SCHEMA) diff --git a/esphome/components/pca9685/output.py b/esphome/components/pca9685/output.py index 0c6855c1d4..b5f4805611 100644 --- a/esphome/components/pca9685/output.py +++ b/esphome/components/pca9685/output.py @@ -13,7 +13,7 @@ CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend({ cv.Required(CONF_ID): cv.declare_id(PCA9685Channel), cv.GenerateID(CONF_PCA9685_ID): cv.use_id(PCA9685Output), - cv.Required(CONF_CHANNEL): cv.All(cv.Coerce(int), cv.Range(min=0, max=15)), + cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=15), }) diff --git a/esphome/components/remote_base/__init__.py b/esphome/components/remote_base/__init__.py index cfe3ae4c59..29dbba3b48 100644 --- a/esphome/components/remote_base/__init__.py +++ b/esphome/components/remote_base/__init__.py @@ -410,7 +410,7 @@ def rc5_action(var, config, args): RC_SWITCH_TIMING_SCHEMA = cv.All([cv.uint8_t], cv.Length(min=2, max=2)) RC_SWITCH_PROTOCOL_SCHEMA = cv.Any( - cv.All(cv.Coerce(int), cv.Range(min=1, max=7)), + cv.int_range(min=1, max=7), cv.Schema({ cv.Required(CONF_PULSE_LENGTH): cv.uint32_t, cv.Optional(CONF_SYNC, default=[1, 31]): RC_SWITCH_TIMING_SCHEMA, @@ -457,22 +457,22 @@ RC_SWITCH_TYPE_A_SCHEMA = cv.Schema({ cv.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA, }) RC_SWITCH_TYPE_B_SCHEMA = cv.Schema({ - cv.Required(CONF_ADDRESS): cv.All(cv.uint8_t, cv.Range(min=1, max=4)), - cv.Required(CONF_CHANNEL): cv.All(cv.uint8_t, cv.Range(min=1, max=4)), + cv.Required(CONF_ADDRESS): cv.int_range(min=1, max=4), + cv.Required(CONF_CHANNEL): cv.int_range(min=1, max=4), cv.Required(CONF_STATE): cv.boolean, cv.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA, }) RC_SWITCH_TYPE_C_SCHEMA = cv.Schema({ cv.Required(CONF_FAMILY): cv.one_of('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', lower=True), - cv.Required(CONF_GROUP): cv.All(cv.uint8_t, cv.Range(min=1, max=4)), - cv.Required(CONF_DEVICE): cv.All(cv.uint8_t, cv.Range(min=1, max=4)), + cv.Required(CONF_GROUP): cv.int_range(min=1, max=4), + cv.Required(CONF_DEVICE): cv.int_range(min=1, max=4), cv.Required(CONF_STATE): cv.boolean, cv.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA, }) RC_SWITCH_TYPE_D_SCHEMA = cv.Schema({ cv.Required(CONF_GROUP): cv.one_of('a', 'b', 'c', 'd', lower=True), - cv.Required(CONF_DEVICE): cv.All(cv.uint8_t, cv.Range(min=1, max=3)), + cv.Required(CONF_DEVICE): cv.int_range(min=1, max=3), cv.Required(CONF_STATE): cv.boolean, cv.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA, }) diff --git a/esphome/components/ttp229_lsf/binary_sensor.py b/esphome/components/ttp229_lsf/binary_sensor.py index da2f8d2717..870bf16287 100644 --- a/esphome/components/ttp229_lsf/binary_sensor.py +++ b/esphome/components/ttp229_lsf/binary_sensor.py @@ -10,7 +10,7 @@ TTP229Channel = ttp229_lsf_ns.class_('TTP229Channel', binary_sensor.BinarySensor CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(TTP229Channel), cv.GenerateID(CONF_TTP229_ID): cv.use_id(TTP229LSFComponent), - cv.Required(CONF_CHANNEL): cv.All(cv.int_, cv.Range(min=0, max=15)) + cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=15), }) diff --git a/esphome/components/uart/__init__.py b/esphome/components/uart/__init__.py index ef959b69ef..06a0ed94df 100644 --- a/esphome/components/uart/__init__.py +++ b/esphome/components/uart/__init__.py @@ -19,7 +19,7 @@ def validate_rx_pin(value): CONFIG_SCHEMA = cv.All(cv.Schema({ cv.GenerateID(): cv.declare_id(UARTComponent), - cv.Required(CONF_BAUD_RATE): cv.All(cv.int_, cv.Range(min=1, max=115200)), + cv.Required(CONF_BAUD_RATE): cv.int_range(min=1, max=115200), cv.Optional(CONF_TX_PIN): pins.output_pin, cv.Optional(CONF_RX_PIN): validate_rx_pin, }).extend(cv.COMPONENT_SCHEMA), cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN))