diff --git a/esphome/components/uart/__init__.py b/esphome/components/uart/__init__.py index 088227afe5..b036288078 100644 --- a/esphome/components/uart/__init__.py +++ b/esphome/components/uart/__init__.py @@ -258,6 +258,7 @@ KEY_UART_DEVICES = "uart_devices" def final_validate_device_schema( name: str, *, + uart_bus: str = CONF_UART_ID, baud_rate: Optional[int] = None, require_tx: bool = False, require_rx: bool = False, @@ -268,7 +269,7 @@ def final_validate_device_schema( def validate_baud_rate(value): if value != baud_rate: raise cv.Invalid( - f"Component {name} requires baud rate {baud_rate} for the uart bus" + f"Component {name} requires baud rate {baud_rate} for the uart referenced by {uart_bus}" ) return value @@ -287,21 +288,21 @@ def final_validate_device_schema( def validate_data_bits(value): if value != data_bits: raise cv.Invalid( - f"Component {name} requires {data_bits} data bits for the uart bus" + f"Component {name} requires {data_bits} data bits for the uart referenced by {uart_bus}" ) return value def validate_parity(value): if value != parity: raise cv.Invalid( - f"Component {name} requires parity {parity} for the uart bus" + f"Component {name} requires parity {parity} for the uart referenced by {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" + f"Component {name} requires {stop_bits} stop bits for the uart referenced by {uart_bus}" ) return value @@ -316,14 +317,14 @@ def final_validate_device_schema( hub_schema[ cv.Required( CONF_TX_PIN, - msg=f"Component {name} requires this uart bus to declare a tx_pin", + msg=f"Component {name} requires uart referenced by {uart_bus} to declare a tx_pin", ) ] = validate_pin(CONF_TX_PIN, device) if require_rx and uart_id_type_str in NATIVE_UART_CLASSES: hub_schema[ cv.Required( CONF_RX_PIN, - msg=f"Component {name} requires this uart bus to declare a rx_pin", + msg=f"Component {name} requires uart referenced by {uart_bus} to declare a rx_pin", ) ] = validate_pin(CONF_RX_PIN, device) if baud_rate is not None: @@ -337,7 +338,7 @@ def final_validate_device_schema( return cv.Schema(hub_schema, extra=cv.ALLOW_EXTRA)(hub_config) return cv.Schema( - {cv.Required(CONF_UART_ID): fv.id_declaration_match_schema(validate_hub)}, + {cv.Required(uart_bus): fv.id_declaration_match_schema(validate_hub)}, extra=cv.ALLOW_EXTRA, )