mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 11:37:27 +01:00
Skip gpio validation (#5615)
This commit is contained in:
parent
7d804bf90f
commit
f0ec900e48
@ -1,5 +1,6 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
import logging
|
||||||
|
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
@ -8,6 +9,7 @@ from esphome.const import (
|
|||||||
CONF_NUMBER,
|
CONF_NUMBER,
|
||||||
CONF_OPEN_DRAIN,
|
CONF_OPEN_DRAIN,
|
||||||
CONF_OUTPUT,
|
CONF_OUTPUT,
|
||||||
|
CONF_IGNORE_PIN_VALIDATION_ERROR,
|
||||||
CONF_IGNORE_STRAPPING_WARNING,
|
CONF_IGNORE_STRAPPING_WARNING,
|
||||||
PLATFORM_ESP32,
|
PLATFORM_ESP32,
|
||||||
)
|
)
|
||||||
@ -42,6 +44,9 @@ from .gpio_esp32_h2 import esp32_h2_validate_gpio_pin, esp32_h2_validate_support
|
|||||||
ESP32InternalGPIOPin = esp32_ns.class_("ESP32InternalGPIOPin", cg.InternalGPIOPin)
|
ESP32InternalGPIOPin = esp32_ns.class_("ESP32InternalGPIOPin", cg.InternalGPIOPin)
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _lookup_pin(value):
|
def _lookup_pin(value):
|
||||||
board = CORE.data[KEY_ESP32][KEY_BOARD]
|
board = CORE.data[KEY_ESP32][KEY_BOARD]
|
||||||
board_pins = boards.ESP32_BOARD_PINS.get(board, {})
|
board_pins = boards.ESP32_BOARD_PINS.get(board, {})
|
||||||
@ -111,7 +116,7 @@ _esp32_validations = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def validate_gpio_pin(value):
|
def gpio_pin_number_validator(value):
|
||||||
value = _translate_pin(value)
|
value = _translate_pin(value)
|
||||||
board = CORE.data[KEY_ESP32][KEY_BOARD]
|
board = CORE.data[KEY_ESP32][KEY_BOARD]
|
||||||
board_pins = boards.ESP32_BOARD_PINS.get(board, {})
|
board_pins = boards.ESP32_BOARD_PINS.get(board, {})
|
||||||
@ -127,7 +132,33 @@ def validate_gpio_pin(value):
|
|||||||
if variant not in _esp32_validations:
|
if variant not in _esp32_validations:
|
||||||
raise cv.Invalid(f"Unsupported ESP32 variant {variant}")
|
raise cv.Invalid(f"Unsupported ESP32 variant {variant}")
|
||||||
|
|
||||||
return _esp32_validations[variant].pin_validation(value)
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def validate_gpio_pin(pin):
|
||||||
|
variant = CORE.data[KEY_ESP32][KEY_VARIANT]
|
||||||
|
if variant not in _esp32_validations:
|
||||||
|
raise cv.Invalid(f"Unsupported ESP32 variant {variant}")
|
||||||
|
|
||||||
|
ignore_pin_validation_warning = pin[CONF_IGNORE_PIN_VALIDATION_ERROR]
|
||||||
|
try:
|
||||||
|
pin[CONF_NUMBER] = _esp32_validations[variant].pin_validation(pin[CONF_NUMBER])
|
||||||
|
except cv.Invalid as exc:
|
||||||
|
if not ignore_pin_validation_warning:
|
||||||
|
raise
|
||||||
|
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Ignoring validation error on pin %d; error: %s",
|
||||||
|
pin[CONF_NUMBER],
|
||||||
|
exc,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Throw an exception if used for a pin that would not have resulted
|
||||||
|
# in a validation error anyway!
|
||||||
|
if ignore_pin_validation_warning:
|
||||||
|
raise cv.Invalid(f"GPIO{pin[CONF_NUMBER]} is not a reserved pin")
|
||||||
|
|
||||||
|
return pin
|
||||||
|
|
||||||
|
|
||||||
def validate_supports(value):
|
def validate_supports(value):
|
||||||
@ -158,9 +189,11 @@ DRIVE_STRENGTHS = {
|
|||||||
gpio_num_t = cg.global_ns.enum("gpio_num_t")
|
gpio_num_t = cg.global_ns.enum("gpio_num_t")
|
||||||
|
|
||||||
CONF_DRIVE_STRENGTH = "drive_strength"
|
CONF_DRIVE_STRENGTH = "drive_strength"
|
||||||
|
|
||||||
ESP32_PIN_SCHEMA = cv.All(
|
ESP32_PIN_SCHEMA = cv.All(
|
||||||
pins.gpio_base_schema(ESP32InternalGPIOPin, validate_gpio_pin).extend(
|
pins.gpio_base_schema(ESP32InternalGPIOPin, gpio_pin_number_validator).extend(
|
||||||
{
|
{
|
||||||
|
cv.Optional(CONF_IGNORE_PIN_VALIDATION_ERROR, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_IGNORE_STRAPPING_WARNING, default=False): cv.boolean,
|
cv.Optional(CONF_IGNORE_STRAPPING_WARNING, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_DRIVE_STRENGTH, default="20mA"): cv.All(
|
cv.Optional(CONF_DRIVE_STRENGTH, default="20mA"): cv.All(
|
||||||
cv.float_with_unit("current", "mA", optional_unit=True),
|
cv.float_with_unit("current", "mA", optional_unit=True),
|
||||||
@ -168,6 +201,7 @@ ESP32_PIN_SCHEMA = cv.All(
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
validate_gpio_pin,
|
||||||
validate_supports,
|
validate_supports,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ TOUCH_PAD_WATERPROOF_SHIELD_DRIVER = {
|
|||||||
|
|
||||||
|
|
||||||
def validate_touch_pad(value):
|
def validate_touch_pad(value):
|
||||||
value = gpio.validate_gpio_pin(value)
|
value = gpio.gpio_pin_number_validator(value)
|
||||||
variant = get_esp32_variant()
|
variant = get_esp32_variant()
|
||||||
if variant not in TOUCH_PADS:
|
if variant not in TOUCH_PADS:
|
||||||
raise cv.Invalid(f"ESP32 variant {variant} does not support touch pads.")
|
raise cv.Invalid(f"ESP32 variant {variant} does not support touch pads.")
|
||||||
|
@ -367,6 +367,7 @@ CONF_IDLE_TIME = "idle_time"
|
|||||||
CONF_IF = "if"
|
CONF_IF = "if"
|
||||||
CONF_IGNORE_EFUSE_MAC_CRC = "ignore_efuse_mac_crc"
|
CONF_IGNORE_EFUSE_MAC_CRC = "ignore_efuse_mac_crc"
|
||||||
CONF_IGNORE_OUT_OF_RANGE = "ignore_out_of_range"
|
CONF_IGNORE_OUT_OF_RANGE = "ignore_out_of_range"
|
||||||
|
CONF_IGNORE_PIN_VALIDATION_ERROR = "ignore_pin_validation_error"
|
||||||
CONF_IGNORE_STRAPPING_WARNING = "ignore_strapping_warning"
|
CONF_IGNORE_STRAPPING_WARNING = "ignore_strapping_warning"
|
||||||
CONF_IIR_FILTER = "iir_filter"
|
CONF_IIR_FILTER = "iir_filter"
|
||||||
CONF_ILLUMINANCE = "illuminance"
|
CONF_ILLUMINANCE = "illuminance"
|
||||||
|
@ -327,6 +327,8 @@ def gpio_base_schema(
|
|||||||
cv.Optional(CONF_MODE, default={}): cv.All(mode_dict, mode_validator),
|
cv.Optional(CONF_MODE, default={}): cv.All(mode_dict, mode_validator),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if invertable:
|
if invertable:
|
||||||
return schema.extend({cv.Optional(CONF_INVERTED, default=False): cv.boolean})
|
return schema.extend({cv.Optional(CONF_INVERTED, default=False): cv.boolean})
|
||||||
|
|
||||||
return schema
|
return schema
|
||||||
|
@ -38,6 +38,11 @@ light:
|
|||||||
id: rgb_led
|
id: rgb_led
|
||||||
name: "RGB LED"
|
name: "RGB LED"
|
||||||
data_rate: 8MHz
|
data_rate: 8MHz
|
||||||
|
- platform: binary
|
||||||
|
name: "Red Info Light"
|
||||||
|
output: board_info_ed
|
||||||
|
entity_category: diagnostic
|
||||||
|
restore_mode: ALWAYS_OFF
|
||||||
|
|
||||||
spi:
|
spi:
|
||||||
id: spi_id_1
|
id: spi_id_1
|
||||||
@ -73,6 +78,14 @@ i2c:
|
|||||||
scl: GPIO18
|
scl: GPIO18
|
||||||
sda: GPIO8
|
sda: GPIO8
|
||||||
|
|
||||||
|
output:
|
||||||
|
- platform: gpio
|
||||||
|
id: board_info_ed
|
||||||
|
pin:
|
||||||
|
# This pin is reserved on the ESP32S3!
|
||||||
|
number: 26
|
||||||
|
ignore_pin_validation_error: true
|
||||||
|
|
||||||
touchscreen:
|
touchscreen:
|
||||||
- platform: tt21100
|
- platform: tt21100
|
||||||
display: displ8
|
display: displ8
|
||||||
|
Loading…
Reference in New Issue
Block a user