mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Allow final validate of uart stop bits and parity (#4376)
This commit is contained in:
parent
0554b06b7e
commit
e95d6041d8
1 changed files with 21 additions and 1 deletions
|
@ -246,11 +246,13 @@ def final_validate_device_schema(
|
|||
baud_rate: Optional[int] = None,
|
||||
require_tx: bool = False,
|
||||
require_rx: bool = False,
|
||||
parity: Optional[str] = None,
|
||||
stop_bits: Optional[int] = None,
|
||||
):
|
||||
def validate_baud_rate(value):
|
||||
if value != baud_rate:
|
||||
raise cv.Invalid(
|
||||
f"Component {name} required baud rate {baud_rate} for the uart bus"
|
||||
f"Component {name} requires baud rate {baud_rate} for the uart bus"
|
||||
)
|
||||
return value
|
||||
|
||||
|
@ -266,6 +268,20 @@ def final_validate_device_schema(
|
|||
|
||||
return validator
|
||||
|
||||
def validate_parity(value):
|
||||
if value != parity:
|
||||
raise cv.Invalid(
|
||||
f"Component {name} requires parity {parity} for the uart bus"
|
||||
)
|
||||
return value
|
||||
|
||||
def validate_stop_bits(value):
|
||||
if value != stop_bits:
|
||||
raise cv.Invalid(
|
||||
f"Component {name} requires stop bits {stop_bits} for the uart bus"
|
||||
)
|
||||
return value
|
||||
|
||||
def validate_hub(hub_config):
|
||||
hub_schema = {}
|
||||
uart_id = hub_config[CONF_ID]
|
||||
|
@ -288,6 +304,10 @@ def final_validate_device_schema(
|
|||
] = validate_pin(CONF_RX_PIN, device)
|
||||
if baud_rate is not None:
|
||||
hub_schema[cv.Required(CONF_BAUD_RATE)] = validate_baud_rate
|
||||
if parity is not None:
|
||||
hub_schema[cv.Required(CONF_PARITY)] = validate_parity
|
||||
if stop_bits is not None:
|
||||
hub_schema[cv.Required(CONF_STOP_BITS)] = validate_stop_bits
|
||||
return cv.Schema(hub_schema, extra=cv.ALLOW_EXTRA)(hub_config)
|
||||
|
||||
return cv.Schema(
|
||||
|
|
Loading…
Reference in a new issue