[uart] Validate fixed UART settings at config time for fixed-baud components (#17207)

This commit is contained in:
Jonathan Swoboda
2026-06-25 10:19:05 -04:00
committed by GitHub
parent 4f70f6b2a6
commit 18c7f60410
19 changed files with 77 additions and 13 deletions
+11
View File
@@ -211,6 +211,17 @@ CONFIG_SCHEMA = (
.add_extra(set_reference_values)
)
# BL0940 datasheet: 4800 baud, 8 data bits, no parity (stop bits are 1.5 -- not
# representable in the uart schema, so it isn't asserted).
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"bl0940",
baud_rate=4800,
data_bits=8,
parity="NONE",
require_rx=True,
require_tx=True,
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
+5
View File
@@ -260,6 +260,11 @@ async def power_inv_to_code(var, config, args):
pass
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"midea", baud_rate=9600, require_rx=True, require_tx=True
)
async def to_code(config):
var = await climate.new_climate(config)
await cg.register_component(var, config)
+4
View File
@@ -58,6 +58,10 @@ CONFIG_SCHEMA = (
.extend(uart.UART_DEVICE_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"pzem004t", baud_rate=9600, require_rx=True, require_tx=True
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
+4
View File
@@ -29,6 +29,10 @@ CONFIG_SCHEMA = (
.extend(uart.UART_DEVICE_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"rdm6300", baud_rate=9600, require_rx=True
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
+10
View File
@@ -80,6 +80,16 @@ _CALLBACK_AUTOMATIONS = (
),
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"rf_bridge",
baud_rate=19200,
require_rx=True,
require_tx=True,
data_bits=8,
parity="NONE",
stop_bits=1,
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
+1 -4
View File
@@ -195,10 +195,7 @@ void RFBridgeComponent::learn() {
this->flush();
}
void RFBridgeComponent::dump_config() {
ESP_LOGCONFIG(TAG, "RF_Bridge:");
this->check_uart_settings(19200);
}
void RFBridgeComponent::dump_config() { ESP_LOGCONFIG(TAG, "RF_Bridge:"); }
void RFBridgeComponent::start_advanced_sniffing() {
ESP_LOGI(TAG, "Advanced Sniffing on");
-1
View File
@@ -73,7 +73,6 @@ void SDS011Component::dump_config() {
this->update_interval_min_, ONOFF(this->rx_mode_only_));
LOG_SENSOR(" ", "PM2.5", this->pm_2_5_sensor_);
LOG_SENSOR(" ", "PM10.0", this->pm_10_0_sensor_);
this->check_uart_settings(9600);
}
void SDS011Component::loop() {
+18
View File
@@ -63,6 +63,24 @@ CONFIG_SCHEMA = cv.All(
)
def _final_validate(config):
# In the default mode setup() writes config commands, so tx is required;
# rx_only mode never writes, so tx is optional.
uart.final_validate_device_schema(
"sds011",
baud_rate=9600,
require_rx=True,
require_tx=not config.get(CONF_RX_ONLY, False),
data_bits=8,
parity="NONE",
stop_bits=1,
)(config)
return config
FINAL_VALIDATE_SCHEMA = _final_validate
async def to_code(config):
# Pop update_interval before register_component so it doesn't generate
# a set_update_interval call — sds011 handles this via set_update_interval_min
-1
View File
@@ -146,7 +146,6 @@ bool SenseAirComponent::senseair_write_command_(const uint8_t *command, uint8_t
void SenseAirComponent::dump_config() {
ESP_LOGCONFIG(TAG, "SenseAir:");
LOG_SENSOR(" ", "CO2", this->co2_sensor_);
this->check_uart_settings(9600);
}
} // namespace esphome::senseair
+10
View File
@@ -51,6 +51,16 @@ CONFIG_SCHEMA = (
.extend(uart.UART_DEVICE_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"senseair",
baud_rate=9600,
require_rx=True,
require_tx=True,
data_bits=8,
parity="NONE",
stop_bits=1,
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
@@ -186,6 +186,10 @@ CONFIG_SCHEMA = (
.extend(uart.UART_DEVICE_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"shelly_dimmer", baud_rate=115200, require_rx=True, require_tx=True
)
async def to_code(config):
fw_hex = get_firmware(config[CONF_FIRMWARE])
+4
View File
@@ -88,6 +88,10 @@ CONFIG_SCHEMA = cv.All(
.extend(uart.UART_DEVICE_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"sm300d2", baud_rate=9600, require_rx=True, data_bits=8, parity="NONE", stop_bits=1
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
-1
View File
@@ -100,7 +100,6 @@ void SM300D2Sensor::dump_config() {
LOG_SENSOR(" ", "PM10", this->pm_10_0_sensor_);
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
this->check_uart_settings(9600);
}
} // namespace esphome::sm300d2
+1 -1
View File
@@ -3,6 +3,6 @@ substitutions:
rx_pin: GPIO14
packages:
uart: !include ../../test_build_components/common/uart/esp32-idf.yaml
uart_4800: !include ../../test_build_components/common/uart_4800/esp32-idf.yaml
<<: !include common.yaml
@@ -3,6 +3,6 @@ substitutions:
rx_pin: GPIO3
packages:
uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml
uart_4800: !include ../../test_build_components/common/uart_4800/esp8266-ard.yaml
<<: !include common.yaml
+1 -1
View File
@@ -3,6 +3,6 @@ substitutions:
rx_pin: GPIO5
packages:
uart: !include ../../test_build_components/common/uart/rp2040-ard.yaml
uart_4800: !include ../../test_build_components/common/uart_4800/rp2040-ard.yaml
<<: !include common.yaml
@@ -1,4 +1,4 @@
packages:
uart: !include ../../test_build_components/common/uart/esp32-idf.yaml
uart_19200: !include ../../test_build_components/common/uart_19200/esp32-idf.yaml
<<: !include common.yaml
@@ -1,4 +1,4 @@
packages:
uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml
uart_19200: !include ../../test_build_components/common/uart_19200/esp8266-ard.yaml
<<: !include common.yaml
@@ -1,4 +1,4 @@
packages:
uart: !include ../../test_build_components/common/uart/rp2040-ard.yaml
uart_19200: !include ../../test_build_components/common/uart_19200/rp2040-ard.yaml
<<: !include common.yaml