ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::uart::UARTDevice Class Reference

#include <uart.h>

Inheritance diagram for esphome::uart::UARTDevice:
esphome::a01nyub::A01nyubComponent esphome::a02yyuw::A02yyuwComponent esphome::adalight::AdalightLightEffect esphome::apc1::APC1Component esphome::apc_proteous::APCProteousCover esphome::bl0906::BL0906 esphome::bl0939::BL0939 esphome::bl0940::BL0940 esphome::bl0942::BL0942 esphome::cm1106::CM1106Component esphome::cse7761::CSE7761Component esphome::cse7766::CSE7766Component esphome::d01::D01SensorComponent esphome::daly_bms::DalyBmsComponent esphome::dfplayer::DFPlayer esphome::dfrobot_sen0395::DfrobotSen0395Component esphome::dfrobot_sen0465_uart::DFRobotSEN0465UARTComponent esphome::dfrobot_sen0609::DFRobotSEN0609Component esphome::dlms_meter::DlmsMeterComponent esphome::ds1603l::DS1603L esphome::dsmr::Dsmr esphome::duco::Duco esphome::emontx::EmonTx esphome::fingerprint_grow::FingerprintGrowComponent esphome::gcja5::GCJA5Component esphome::gps::GPS esphome::haier::HaierClimateBase esphome::haier_water_heater::HonWaterHeater esphome::hc8::HC8Component esphome::he60r::HE60rCover esphome::hlk_fm22x::HlkFm22xComponent esphome::hlw8032::HLW8032Component esphome::hrxl_maxsonar_wr::HrxlMaxsonarWrComponent esphome::hydreon_rgxx::HydreonRGxxComponent esphome::jsn_sr04t::Jsnsr04tComponent esphome::kamstrup_kmp::KamstrupKMPComponent esphome::ld2410::LD2410Component esphome::ld2410s::LD2410SComponent esphome::ld2412::LD2412Component esphome::ld2420::LD2420Component esphome::ld2450::LD2450Component esphome::ld2460::LD2460Component esphome::ld6002b::LD6002BComponent esphome::mhz19::MHZ19Component esphome::micronova::MicroNova esphome::midea_portasplit::PortaSplitClimate esphome::mitsubishi_cn105::MitsubishiCN105Component esphome::mk2pvrouter::Mk2PVRouter esphome::modbus::Modbus esphome::nextion::Nextion esphome::pipsolar::Pipsolar esphome::pm1006::PM1006Component esphome::pmsx003::PMSX003Component esphome::pylontech::PylontechComponent esphome::pzem004t::PZEM004T esphome::rd03d::RD03DComponent esphome::rdm6300::RDM6300Component esphome::rf_bridge::RFBridgeComponent esphome::sds011::SDS011Component esphome::seeed_mr24hpc1::MR24HPC1Component esphome::seeed_mr60bha2::MR60BHA2Component esphome::seeed_mr60fda2::MR60FDA2Component esphome::senseair::SenseAirComponent esphome::serial_proxy::SerialProxy esphome::shelly_dimmer::ShellyDimmer esphome::sim800l::Sim800LComponent esphome::sm300d2::SM300D2Sensor esphome::sml::Sml esphome::smt100::SMT100Component esphome::sonoff_d1::SonoffD1Output esphome::sun_gtil2::SunGTIL2 esphome::systa_bus::SystaBus esphome::t6615::T6615Component esphome::teleinfo::TeleInfo esphome::tmc22xx::TMC22XXStepper esphome::tormatic::Tormatic esphome::tuya::Tuya esphome::uart::UARTBinarySensorHub esphome::uart::UARTButton esphome::uart::UARTDummyReceiver esphome::uart::UARTEvent esphome::uart::UARTSwitch esphome::uart::UARTTransport esphome::uart::UartPacketInterface esphome::uart_tcp::UartTcp esphome::ufm01::UFM01Component esphome::uponor_smatrix::UponorSmatrixComponent esphome::vbus::VBus esphome::wl_134::Wl134Component esphome::wts01::WTS01Sensor esphome::zwave_proxy::ZWaveProxy

Public Member Functions

 UARTDevice ()=default
 
 UARTDevice (UARTComponent *parent)
 
void set_uart_parent (UARTComponent *parent)
 
void write_byte (uint8_t data)
 
void set_rx_full_threshold (size_t rx_full_threshold)
 
void set_rx_full_threshold_ms (size_t time)
 
size_t get_rx_full_threshold ()
 
void set_rx_timeout (size_t rx_timeout)
 
size_t get_rx_timeout ()
 
void write_array (const uint8_t *data, size_t len)
 
void write_array_progmem (const uint8_t *data, size_t len)
 
void write_array (const std::vector< uint8_t > &data)
 
template<size_t N>
void write_array (const std::array< uint8_t, N > &data)
 
void write_str (const char *str)
 
bool read_byte (uint8_t *data)
 
bool peek_byte (uint8_t *data)
 
bool read_array (uint8_t *data, size_t len)
 
template<size_t N>
optional< std::array< uint8_t, N > > read_array ()
 
size_t available ()
 
template<size_t N = 64, typename F >
bool read_available_chunks (F &&on_chunk)
 Pass the bytes available now to on_chunk(data, len) in N byte chunks; returning false stops.
 
template<size_t N = 64, typename F >
bool read_available_chunks (F &&on_chunk, size_t count)
 Same, reading exactly count bytes; count must not exceed available().
 
template<size_t N = 64, typename F >
bool read_available (F &&on_byte)
 Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
 
template<size_t N = 64, typename F >
bool read_available (F &&on_byte, size_t count)
 
void discard_available ()
 Read and drop every byte waiting in the receive buffer.
 
UARTFlushResult flush ()
 
int read ()
 
size_t write (uint8_t data)
 
int peek ()
 
 ESPDEPRECATED ("Use uart.final_validate_device_schema() in Python instead. Removed in 2027.3.0", "2026.9.0") void check_uart_settings(uint32_t baud_rate
 Check that the configuration of the UART bus matches the provided values and otherwise print a warning.
 

Data Fields

uint8_t stop_bits = 1
 
uint8_t UARTParityOptions parity = UART_CONFIG_PARITY_NONE
 
uint8_t UARTParityOptions uint8_t data_bits = 8)
 

Static Protected Member Functions

template<typename F , typename... A>
static bool continue_after (F &f, A... args)
 Call f(args...) and return its result; a void callback always continues.
 

Protected Attributes

UARTComponent * parent_ {nullptr}
 

Detailed Description

Definition at line 15 of file uart.h.

Constructor & Destructor Documentation

◆ UARTDevice() [1/2]

esphome::uart::UARTDevice::UARTDevice ( )
default

◆ UARTDevice() [2/2]

esphome::uart::UARTDevice::UARTDevice ( UARTComponent * parent)
inline

Definition at line 18 of file uart.h.

Member Function Documentation

◆ available()

size_t esphome::uart::UARTDevice::available ( )
inline

Definition at line 52 of file uart.h.

◆ continue_after()

template<typename F , typename... A>
static bool esphome::uart::UARTDevice::continue_after ( F & f,
A... args )
inlinestaticprotected

Call f(args...) and return its result; a void callback always continues.

Definition at line 123 of file uart.h.

◆ discard_available()

void esphome::uart::UARTDevice::discard_available ( )

Read and drop every byte waiting in the receive buffer.

Definition at line 36 of file uart.cpp.

◆ ESPDEPRECATED()

esphome::uart::UARTDevice::ESPDEPRECATED ( "Use uart.final_validate_device_schema() in Python instead. Removed in 2027.3.0" ,
"2026.9.0"  )

Check that the configuration of the UART bus matches the provided values and otherwise print a warning.

◆ flush()

UARTFlushResult esphome::uart::UARTDevice::flush ( )
inline

Definition at line 96 of file uart.h.

◆ get_rx_full_threshold()

size_t esphome::uart::UARTDevice::get_rx_full_threshold ( )
inline

Definition at line 26 of file uart.h.

◆ get_rx_timeout()

size_t esphome::uart::UARTDevice::get_rx_timeout ( )
inline

Definition at line 28 of file uart.h.

◆ peek()

int esphome::uart::UARTDevice::peek ( )
inline

Definition at line 109 of file uart.h.

◆ peek_byte()

bool esphome::uart::UARTDevice::peek_byte ( uint8_t * data)
inline

Definition at line 40 of file uart.h.

◆ read()

int esphome::uart::UARTDevice::read ( )
inline

Definition at line 99 of file uart.h.

◆ read_array() [1/2]

template<size_t N>
optional< std::array< uint8_t, N > > esphome::uart::UARTDevice::read_array ( )
inline

Definition at line 43 of file uart.h.

◆ read_array() [2/2]

bool esphome::uart::UARTDevice::read_array ( uint8_t * data,
size_t len )
inline

Definition at line 42 of file uart.h.

◆ read_available() [1/2]

template<size_t N = 64, typename F >
bool esphome::uart::UARTDevice::read_available ( F && on_byte)
inline

Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.

Definition at line 77 of file uart.h.

◆ read_available() [2/2]

template<size_t N = 64, typename F >
bool esphome::uart::UARTDevice::read_available ( F && on_byte,
size_t count )
inline

Definition at line 80 of file uart.h.

◆ read_available_chunks() [1/2]

template<size_t N = 64, typename F >
bool esphome::uart::UARTDevice::read_available_chunks ( F && on_chunk)
inline

Pass the bytes available now to on_chunk(data, len) in N byte chunks; returning false stops.

Returns false only on a read error.

Definition at line 56 of file uart.h.

◆ read_available_chunks() [2/2]

template<size_t N = 64, typename F >
bool esphome::uart::UARTDevice::read_available_chunks ( F && on_chunk,
size_t count )
inline

Same, reading exactly count bytes; count must not exceed available().

Definition at line 60 of file uart.h.

◆ read_byte()

bool esphome::uart::UARTDevice::read_byte ( uint8_t * data)
inline

Definition at line 39 of file uart.h.

◆ set_rx_full_threshold()

void esphome::uart::UARTDevice::set_rx_full_threshold ( size_t rx_full_threshold)
inline

Definition at line 24 of file uart.h.

◆ set_rx_full_threshold_ms()

void esphome::uart::UARTDevice::set_rx_full_threshold_ms ( size_t time)
inline

Definition at line 25 of file uart.h.

◆ set_rx_timeout()

void esphome::uart::UARTDevice::set_rx_timeout ( size_t rx_timeout)
inline

Definition at line 27 of file uart.h.

◆ set_uart_parent()

void esphome::uart::UARTDevice::set_uart_parent ( UARTComponent * parent)
inline

Definition at line 20 of file uart.h.

◆ write()

size_t esphome::uart::UARTDevice::write ( uint8_t data)
inline

Definition at line 105 of file uart.h.

◆ write_array() [1/3]

template<size_t N>
void esphome::uart::UARTDevice::write_array ( const std::array< uint8_t, N > & data)
inline

Definition at line 33 of file uart.h.

◆ write_array() [2/3]

void esphome::uart::UARTDevice::write_array ( const std::vector< uint8_t > & data)
inline

Definition at line 32 of file uart.h.

◆ write_array() [3/3]

void esphome::uart::UARTDevice::write_array ( const uint8_t * data,
size_t len )
inline

Definition at line 30 of file uart.h.

◆ write_array_progmem()

void esphome::uart::UARTDevice::write_array_progmem ( const uint8_t * data,
size_t len )
inline

Definition at line 31 of file uart.h.

◆ write_byte()

void esphome::uart::UARTDevice::write_byte ( uint8_t data)
inline

Definition at line 22 of file uart.h.

◆ write_str()

void esphome::uart::UARTDevice::write_str ( const char * str)
inline

Definition at line 37 of file uart.h.

Field Documentation

◆ data_bits

uint8_t UARTParityOptions uint8_t esphome::uart::UARTDevice::data_bits = 8)

Definition at line 119 of file uart.h.

◆ parent_

UARTComponent* esphome::uart::UARTDevice::parent_ {nullptr}
protected

Definition at line 134 of file uart.h.

◆ parity

uint8_t UARTParityOptions esphome::uart::UARTDevice::parity = UART_CONFIG_PARITY_NONE

Definition at line 119 of file uart.h.

◆ stop_bits

uint8_t esphome::uart::UARTDevice::stop_bits = 1

Definition at line 118 of file uart.h.


The documentation for this class was generated from the following files: