mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 10:44:13 +01:00
Add config validation
This commit is contained in:
parent
7efee6d53a
commit
454bd95656
1 changed files with 53 additions and 32 deletions
|
@ -119,7 +119,26 @@ def validate_raw_data(value):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.Schema(
|
def validate_config(config):
|
||||||
|
if config[CONF_PAYLOAD_LENGTH] > 0 and CONF_DIO0_PIN not in config:
|
||||||
|
raise cv.Invalid("Cannot use packet mode without dio0_pin")
|
||||||
|
if config[CONF_PAYLOAD_LENGTH] > 0 and config[CONF_BITRATE] == 0:
|
||||||
|
raise cv.Invalid("Cannot use packet mode without setting bitrate")
|
||||||
|
if config[CONF_RX_DURATION] > TimePeriod() and CONF_DIO0_PIN not in config:
|
||||||
|
raise cv.Invalid("Cannot use rx_duration without dio0_pin")
|
||||||
|
if config[CONF_RX_DURATION] > TimePeriod() and CONF_DIO2_PIN not in config:
|
||||||
|
raise cv.Invalid("Cannot use rx_duration without dio2_pin")
|
||||||
|
if config[CONF_RX_DURATION] > TimePeriod() and config[CONF_PAYLOAD_LENGTH] > 0:
|
||||||
|
raise cv.Invalid("Cannot use rx_duration in packet mode")
|
||||||
|
if config[CONF_PA_PIN] == "RFO" and config[CONF_PA_POWER] > 15:
|
||||||
|
raise cv.Invalid("PA power must be <= 15 dbm when using the RFO pin")
|
||||||
|
if config[CONF_PA_PIN] == "BOOST" and config[CONF_PA_POWER] < 2:
|
||||||
|
raise cv.Invalid("PA power must be >= 2 dbm when using the BOOST pin")
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = cv.All(
|
||||||
|
cv.Schema(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(SX127x),
|
cv.GenerateID(): cv.declare_id(SX127x),
|
||||||
cv.Optional(CONF_DIO0_PIN): pins.internal_gpio_input_pin_schema,
|
cv.Optional(CONF_DIO0_PIN): pins.internal_gpio_input_pin_schema,
|
||||||
|
@ -149,8 +168,10 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
cv.Optional(CONF_PA_PIN, default="BOOST"): cv.enum(PA_PIN),
|
cv.Optional(CONF_PA_PIN, default="BOOST"): cv.enum(PA_PIN),
|
||||||
cv.Optional(CONF_PA_POWER, default=17): cv.int_range(min=0, max=17),
|
cv.Optional(CONF_PA_POWER, default=17): cv.int_range(min=0, max=17),
|
||||||
cv.Optional(CONF_ON_PACKET): automation.validate_automation(single=True),
|
cv.Optional(CONF_ON_PACKET): automation.validate_automation(single=True),
|
||||||
}
|
},
|
||||||
).extend(spi.spi_device_schema(False, 8e6, "mode0"))
|
).extend(spi.spi_device_schema(False, 8e6, "mode0")),
|
||||||
|
validate_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
|
Loading…
Reference in a new issue