Files
mangavalkandClaude Opus 5.5 a8f6bb3ca5 Fit this lamp: 4 alarms, full data model, knock snooze, server use
Decode DP127 as 48 bytes (4 alarms), plus DP128, DP107 and DP126, from Tuya's
data model. Add day switches, alarm and sunset controls, a knock sensor on PA18,
display schedule, bedtime fade, radio timer and grouped web UI. Pin LibreTiny
v1.14.0 for the OTA restart fix. Ship the patched UART as an external component
so a server needs only a short YAML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 12:27:54 +01:00

80 lines
2.7 KiB
C++

#pragma once
#include <vector>
#include "esphome/core/component.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include "uart_component.h"
namespace esphome::uart {
class UARTDevice {
public:
UARTDevice() = default;
UARTDevice(UARTComponent *parent) : parent_(parent) {}
void set_uart_parent(UARTComponent *parent) { this->parent_ = parent; }
void write_byte(uint8_t data) { this->parent_->write_byte(data); }
void set_rx_full_threshold(size_t rx_full_threshold) { this->parent_->set_rx_full_threshold(rx_full_threshold); }
void set_rx_full_threshold_ms(size_t time) { this->parent_->set_rx_full_threshold_ms(time); }
size_t get_rx_full_threshold() { return this->parent_->get_rx_full_threshold(); }
void set_rx_timeout(size_t rx_timeout) { this->parent_->set_rx_timeout(rx_timeout); }
size_t get_rx_timeout() { return this->parent_->get_rx_timeout(); }
void write_array(const uint8_t *data, size_t len) { this->parent_->write_array(data, len); }
void write_array(const std::vector<uint8_t> &data) { this->parent_->write_array(data); }
template<size_t N> void write_array(const std::array<uint8_t, N> &data) {
this->parent_->write_array(data.data(), data.size());
}
void write_str(const char *str) { this->parent_->write_str(str); }
bool read_byte(uint8_t *data) { return this->parent_->read_byte(data); }
bool peek_byte(uint8_t *data) { return this->parent_->peek_byte(data); }
bool read_array(uint8_t *data, size_t len) { return this->parent_->read_array(data, len); }
template<size_t N> optional<std::array<uint8_t, N>> read_array() { // NOLINT
// One object returned on both paths; a separate empty optional trips GCC's -Wmaybe-uninitialized.
optional<std::array<uint8_t, N>> res(std::in_place);
if (!this->read_array(res->data(), N)) {
res.reset();
}
return res;
}
size_t available() { return this->parent_->available(); }
UARTFlushResult flush() { return this->parent_->flush(); }
// Compat APIs
int read() {
uint8_t data;
if (!this->read_byte(&data))
return -1;
return data;
}
size_t write(uint8_t data) {
this->write_byte(data);
return 1;
}
int peek() {
uint8_t data;
if (!this->peek_byte(&data))
return -1;
return data;
}
/// Check that the configuration of the UART bus matches the provided values and otherwise print a warning
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, uint8_t stop_bits = 1,
UARTParityOptions parity = UART_CONFIG_PARITY_NONE, uint8_t data_bits = 8);
protected:
UARTComponent *parent_{nullptr};
};
} // namespace esphome::uart