1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-16 18:22:22 +01:00

[api] Consolidate error handling and remove unused code (#9726)

This commit is contained in:
J. Nick Koston
2025-07-20 12:52:46 -10:00
committed by GitHub
parent e5aed29231
commit 0aabdaa0c7
2 changed files with 96 additions and 109 deletions

View File

@@ -109,11 +109,6 @@ class APIFrameHelper {
bool is_socket_ready() const { return socket_ != nullptr && socket_->ready(); }
protected:
// Struct for holding parsed frame data
struct ParsedFrame {
std::vector<uint8_t> msg;
};
// Buffer containing data to be sent
struct SendBuffer {
std::unique_ptr<uint8_t[]> data;
@@ -133,6 +128,9 @@ class APIFrameHelper {
// Helper method to buffer data from IOVs
void buffer_data_from_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len, uint16_t offset);
// Common socket write error handling
APIError handle_socket_write_error_();
template<typename StateEnum>
APIError write_raw_(const struct iovec *iov, int iovcnt, socket::Socket *socket, std::vector<uint8_t> &tx_buf,
const std::string &info, StateEnum &state, StateEnum failed_state);
@@ -205,11 +203,13 @@ class APINoiseFrameHelper : public APIFrameHelper {
protected:
APIError state_action_();
APIError try_read_frame_(ParsedFrame *frame);
APIError try_read_frame_(std::vector<uint8_t> *frame);
APIError write_frame_(const uint8_t *data, uint16_t len);
APIError init_handshake_();
APIError check_handshake_finished_();
void send_explicit_handshake_reject_(const std::string &reason);
APIError handle_handshake_frame_error_(APIError aerr);
APIError handle_noise_error_(int err, const char *func_name, APIError api_err);
// Pointers first (4 bytes each)
NoiseHandshakeState *handshake_{nullptr};
@@ -257,7 +257,7 @@ class APIPlaintextFrameHelper : public APIFrameHelper {
uint8_t frame_footer_size() override { return frame_footer_size_; }
protected:
APIError try_read_frame_(ParsedFrame *frame);
APIError try_read_frame_(std::vector<uint8_t> *frame);
// Group 2-byte aligned types
uint16_t rx_header_parsed_type_ = 0;