ESPHome 2026.8.1
Loading...
Searching...
No Matches
api_connection.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef USE_API
5#include "api_frame_helper.h"
6#ifdef USE_API_NOISE
8#endif
9#ifdef USE_API_PLAINTEXT
11#endif
12#include "api_pb2.h"
13#include "api_pb2_service.h"
14#include "list_entities.h"
15#include "subscribe_state.h"
18#ifdef USE_ESP32_CRASH_HANDLER
20#endif
21#ifdef USE_RP2_CRASH_HANDLER
23#endif
24#ifdef USE_ESP8266_CRASH_HANDLER
26#endif
28#include "esphome/core/log.h"
30
31#include <functional>
32#include <limits>
33#include <vector>
34
35namespace esphome {
36class ComponentIterator;
37} // namespace esphome
38
39namespace esphome::api {
40
41// Forward-declared to break the api_server.h cycle; full-type inlines are in api_connection_buffer.h.
42class APIServer;
43
44// One shared flash string for every refused-frame warning: send_message()
45// fails as soon as the TCP buffer is full, and each caller only pays for its
46// short name. The guard drops the helper and its arguments below WARN.
47#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_WARN
48void log_dropped_message(const char *tag, int line, const LogString *what);
49#define API_LOG_MSG_DROPPED(tag, what) esphome::api::log_dropped_message(tag, __LINE__, LOG_STR(what))
50#else
51#define API_LOG_MSG_DROPPED(tag, what)
52#endif
53
54// Keepalive timeout in milliseconds
55static constexpr uint32_t KEEPALIVE_TIMEOUT_MS = 60000;
56// Deferred batch size cap during initial state/info sync
57static constexpr size_t MAX_INITIAL_BATCH_SIZE = 34;
58// Verify MAX_MESSAGES_PER_BATCH (defined in api_frame_helper.h) can hold the initial batch
59static_assert(MAX_MESSAGES_PER_BATCH >= MAX_INITIAL_BATCH_SIZE,
60 "MAX_MESSAGES_PER_BATCH must be >= MAX_INITIAL_BATCH_SIZE");
61
62#ifdef USE_BENCHMARK
63class APIConnection;
67#endif
68
70 public:
71 friend class APIServer;
73#ifdef USE_BENCHMARK
75 friend void bench_clear_batch(APIConnection *conn);
77#endif
78 APIConnection(std::unique_ptr<socket::Socket> socket, APIServer *parent);
80
81 void start();
82 void loop();
83
84 protected:
85 // read_message_ is defined here (instead of in APIServerConnectionBase) so the
86 // compiler can devirtualize and inline on_* handler calls within this final class.
87 void read_message_(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data);
88
89 // Auth helpers defined here (not in ProtoService) so the compiler can
90 // devirtualize is_connection_setup()/on_no_setup_connection() calls
91 // within this final class.
93 if (!this->is_connection_setup()) {
95 return false;
96 }
97 return true;
98 }
99 inline bool check_authenticated_() { return this->check_connection_setup_(); }
100
101 public:
106#ifdef USE_BINARY_SENSOR
108#endif
109#ifdef USE_COVER
110 bool send_cover_state(cover::Cover *cover);
112#endif
113#ifdef USE_FAN
114 bool send_fan_state(fan::Fan *fan);
116#endif
117#ifdef USE_LIGHT
120#endif
121#ifdef USE_SENSOR
122 bool send_sensor_state(sensor::Sensor *sensor);
123#endif
124#ifdef USE_SWITCH
125 bool send_switch_state(switch_::Switch *a_switch);
127#endif
128#ifdef USE_TEXT_SENSOR
130#endif
131#ifdef USE_CAMERA
132 void set_camera_state(std::shared_ptr<camera::CameraImage> image);
134#endif
135#ifdef USE_CLIMATE
138#endif
139#ifdef USE_NUMBER
140 bool send_number_state(number::Number *number);
142#endif
143#ifdef USE_DATETIME_DATE
146#endif
147#ifdef USE_DATETIME_TIME
150#endif
151#ifdef USE_DATETIME_DATETIME
154#endif
155#ifdef USE_TEXT
156 bool send_text_state(text::Text *text);
158#endif
159#ifdef USE_SELECT
160 bool send_select_state(select::Select *select);
162#endif
163#ifdef USE_BUTTON
165#endif
166#ifdef USE_LOCK
167 bool send_lock_state(lock::Lock *a_lock);
169#endif
170#ifdef USE_VALVE
171 bool send_valve_state(valve::Valve *valve);
173#endif
174#ifdef USE_MEDIA_PLAYER
177#endif
178 bool try_send_log_message(int level, const char *tag, const char *line, size_t message_len);
179#ifdef USE_API_HOMEASSISTANT_SERVICES
180 // Returns whether this client has subscribed to Home Assistant actions; the message
181 // is only handed to the send path when subscribed. A true return does not guarantee
182 // delivery - it lets the caller warn when no connected client has the subscription.
184#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
186#endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES
187#endif // USE_API_HOMEASSISTANT_SERVICES
188#ifdef USE_BLUETOOTH_PROXY
191
192#ifdef USE_BLUETOOTH_PROXY_CONNECTIONS
202#endif
204
205#endif
206#ifdef USE_HOMEASSISTANT_TIME
207 void send_time_request();
208#endif
209
210#ifdef USE_VOICE_ASSISTANT
219#endif
220
221#ifdef USE_ZWAVE_PROXY
222 void on_z_wave_proxy_frame(const ZWaveProxyFrame &msg);
224#endif
225
226#ifdef USE_ALARM_CONTROL_PANEL
229#endif
230
231#ifdef USE_WATER_HEATER
234#endif
235
236#if defined(USE_IR_RF) || defined(USE_RADIO_FREQUENCY)
239#endif
240
241#ifdef USE_SERIAL_PROXY
248#endif
249
250#ifdef USE_EVENT
251 void send_event(event::Event *event);
252#endif
253
254#ifdef USE_UPDATE
257#endif
258
261 // we initiated ping
262 this->flags_.sent_ping = false;
263 }
264#ifdef USE_API_HOMEASSISTANT_STATES
266#endif
267#ifdef USE_HOMEASSISTANT_TIME
268 void on_get_time_response(const GetTimeResponse &value);
269#endif
270 void on_hello_request(const HelloRequest &msg);
272 void on_ping_request();
277 this->flags_.state_subscription = true;
278 // Start initial state iterator only if no iterator is active
279 // If list_entities is running, we'll start initial_state when it completes
282 }
283 }
285 this->flags_.log_subscription = msg.level;
286 if (msg.dump_config)
288#ifdef USE_ESP32_CRASH_HANDLER
291#endif
292#ifdef USE_RP2_CRASH_HANDLER
294#endif
295#ifdef USE_ESP8266_CRASH_HANDLER
297#endif
298 }
299#ifdef USE_API_HOMEASSISTANT_SERVICES
301#endif
302#ifdef USE_API_HOMEASSISTANT_STATES
304#endif
305#ifdef USE_API_USER_DEFINED_ACTIONS
307#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
308 void send_execute_service_response(uint32_t call_id, bool success, StringRef error_message);
309#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
310 void send_execute_service_response(uint32_t call_id, bool success, StringRef error_message,
311 const uint8_t *response_data, size_t response_data_len);
312#endif // USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
313#endif // USE_API_USER_DEFINED_ACTION_RESPONSES
314#endif
315#ifdef USE_API_NOISE
317#endif
318
324 this->is_authenticated();
325 }
326 bool is_marked_for_removal() const { return this->flags_.remove; }
327 uint8_t get_log_subscription_level() const { return this->flags_.log_subscription; }
328
329 // Get client API version for feature detection
330 bool client_supports_api_version(uint16_t major, uint16_t minor) const {
331 return this->client_api_version_major_ > major ||
332 (this->client_api_version_major_ == major && this->client_api_version_minor_ >= minor);
333 }
334
335 void on_fatal_error();
337
338 // Function pointer type for type-erased message encoding
339 using MessageEncodeFn = uint8_t *(*) (const void *, ProtoWriteBuffer &PROTO_ENCODE_DEBUG_PARAM);
340 // Function pointer type for type-erased size calculation
341 using CalculateSizeFn = uint32_t (*)(const void *);
342
345 template<typename T> [[nodiscard]] bool send_message(const T &msg) {
346 if constexpr (T::ESTIMATED_SIZE == 0) {
347 return this->send_message_(0, T::MESSAGE_TYPE, &encode_msg_noop, &msg);
348 } else {
349 return this->send_message_(msg.calculate_size(), T::MESSAGE_TYPE, &proto_encode_msg<T>, &msg);
350 }
351 }
352
353 void prepare_first_message_buffer(APIBuffer &shared_buf, size_t header_padding, size_t total_size) {
354 shared_buf.clear();
355 // Reserve space for header padding + message + footer
356 // - Header padding: space for protocol headers (7 bytes for Noise, 6 for Plaintext)
357 // - Footer: space for MAC (16 bytes for Noise, 0 for Plaintext)
358 // Reserve full size but only set initial size to header padding
359 // so message encoding starts at the correct position
360 shared_buf.reserve_and_resize(total_size, header_padding);
361 }
362
363 // Convenience overload - computes frame overhead internally
365 const uint8_t header_padding = this->helper_->frame_header_padding();
366 const uint8_t footer_size = this->helper_->frame_footer_size();
367 this->prepare_first_message_buffer(shared_buf, header_padding, payload_size + header_padding + footer_size);
368 }
369
370 bool try_to_clear_buffer(bool log_out_of_space) {
371 if (this->flags_.remove)
372 return false;
373 if (this->helper_->can_write_without_blocking())
374 return true;
375 return this->try_to_clear_buffer_slow_(log_out_of_space);
376 }
377 bool send_buffer(ProtoWriteBuffer buffer, uint8_t message_type);
378
379 const char *get_name() const { return this->helper_->get_client_name(); }
381 const char *get_peername_to(std::span<char, socket::SOCKADDR_STR_LEN> buf) const {
382 return this->helper_->get_peername_to(buf);
383 }
384
385 protected:
386 bool try_to_clear_buffer_slow_(bool log_out_of_space);
387
388 // Helper function to handle authentication completion
390
391 // Pattern B helpers: send response and return success/failure
392 bool send_hello_response_(const HelloRequest &msg);
394 bool send_ping_response_();
397#ifdef USE_API_NOISE
399#endif
400#ifdef USE_BLUETOOTH_PROXY_CONNECTIONS
402#endif
403#ifdef USE_VOICE_ASSISTANT
405#endif
406
407#ifdef USE_CAMERA
409#endif
410
411#ifdef USE_API_HOMEASSISTANT_STATES
413#endif
414
415 // Size thunk — converts void* back to concrete type for direct calculate_size() call
416 template<typename T> static uint32_t calc_size(const void *msg) {
417 return static_cast<const T *>(msg)->calculate_size();
418 }
419
420 // Shared no-op encode thunk for empty messages (ESTIMATED_SIZE == 0)
421 static uint8_t *encode_msg_noop(const void *, ProtoWriteBuffer &buf PROTO_ENCODE_DEBUG_PARAM) {
422 return buf.get_pos();
423 }
424
425 // Non-template buffer management for send_message
426 bool send_message_(uint32_t payload_size, uint8_t message_type, MessageEncodeFn encode_fn, const void *msg);
427
428 // Core batch encoding logic. ALWAYS_INLINE so encode_fn devirtualizes at hot call sites.
429 // Defined in api_connection_buffer.h (needs APIServer complete).
430 static uint16_t ESPHOME_ALWAYS_INLINE encode_to_buffer(uint32_t calculated_size, MessageEncodeFn encode_fn,
431 const void *msg, APIConnection *conn, uint32_t remaining_size);
432
433 // Noinline version of encode_to_buffer for cold paths (entity info, zero-payload messages).
434 // All cold callers share this single copy instead of each getting an ALWAYS_INLINE expansion.
435 static uint16_t encode_to_buffer_slow(uint32_t calculated_size, MessageEncodeFn encode_fn, const void *msg,
436 APIConnection *conn, uint32_t remaining_size);
437
438 // Thin template wrapper — uses noinline encode_to_buffer_slow since
439 // encode_message_to_buffer callers are cold paths (zero-payload control messages).
440 // Hot paths (state/info) go through fill_and_encode_entity_state/info instead.
441 // batch_message_type_ is already set by dispatch_message_ before reaching here.
442 template<typename T> static uint16_t encode_message_to_buffer(T &msg, APIConnection *conn, uint32_t remaining_size) {
443 if constexpr (T::ESTIMATED_SIZE == 0) {
444 return encode_to_buffer_slow(0, &encode_msg_noop, &msg, conn, remaining_size);
445 } else {
446 return encode_to_buffer_slow(msg.calculate_size(), &proto_encode_msg<T>, &msg, conn, remaining_size);
447 }
448 }
449
450 // Non-template core — fills state fields and encodes
452 CalculateSizeFn size_fn, MessageEncodeFn encode_fn, APIConnection *conn,
453 uint32_t remaining_size);
454
455 // Thin template wrapper
456 template<typename T>
457 static uint16_t fill_and_encode_entity_state(EntityBase *entity, T &msg, APIConnection *conn,
458 uint32_t remaining_size) {
459 return fill_and_encode_entity_state(entity, msg, &calc_size<T>, &proto_encode_msg<T>, conn, remaining_size);
460 }
461
462 // Non-template core — fills info fields, allocates buffers, and encodes
464 CalculateSizeFn size_fn, MessageEncodeFn encode_fn, APIConnection *conn,
465 uint32_t remaining_size);
466
467 // Thin template wrapper
468 template<typename T>
469 static uint16_t fill_and_encode_entity_info(EntityBase *entity, T &msg, APIConnection *conn,
470 uint32_t remaining_size) {
471 return fill_and_encode_entity_info(entity, msg, &calc_size<T>, &proto_encode_msg<T>, conn, remaining_size);
472 }
473
474 // Non-template core — fills device_class, then delegates to fill_and_encode_entity_info
476 StringRef &device_class_field, CalculateSizeFn size_fn,
477 MessageEncodeFn encode_fn, APIConnection *conn,
478 uint32_t remaining_size);
479
480 // Thin template wrapper
481 template<typename T>
483 StringRef &device_class_field, APIConnection *conn,
484 uint32_t remaining_size) {
485 return fill_and_encode_entity_info_with_device_class(entity, msg, device_class_field, &calc_size<T>,
486 &proto_encode_msg<T>, conn, remaining_size);
487 }
488
489#ifdef USE_VOICE_ASSISTANT
490 // Helper to check voice assistant validity and connection ownership
491 inline bool check_voice_assistant_api_connection_() const;
492#endif
493
494 // Send keepalive ping or disconnect unresponsive client.
495 // Cold path — extracted from loop() to reduce instruction cache pressure.
496 void __attribute__((noinline)) check_keepalive_(uint32_t now);
497
498 // Process active iterator (list_entities/initial_state) during connection setup.
499 // Extracted from loop() — only runs during initial handshake, NONE in steady state.
500 void __attribute__((noinline)) process_active_iterator_();
501
502 // Helper method to process multiple entities from an iterator in a batch.
503 // Takes ComponentIterator base class reference to avoid duplicate template instantiations.
505
506#ifdef USE_BINARY_SENSOR
507 static uint16_t try_send_binary_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
508 static uint16_t try_send_binary_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
509#endif
510#ifdef USE_COVER
511 static uint16_t try_send_cover_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
512 static uint16_t try_send_cover_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
513#endif
514#ifdef USE_FAN
515 static uint16_t try_send_fan_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
516 static uint16_t try_send_fan_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
517#endif
518#ifdef USE_LIGHT
519 static uint16_t try_send_light_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
520 static uint16_t try_send_light_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
521#endif
522#ifdef USE_SENSOR
523 static uint16_t try_send_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
524 static uint16_t try_send_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
525#endif
526#ifdef USE_SWITCH
527 static uint16_t try_send_switch_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
528 static uint16_t try_send_switch_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
529#endif
530#ifdef USE_TEXT_SENSOR
531 static uint16_t try_send_text_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
532 static uint16_t try_send_text_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
533#endif
534#ifdef USE_CLIMATE
535 static uint16_t try_send_climate_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
536 static uint16_t try_send_climate_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
537#endif
538#ifdef USE_NUMBER
539 static uint16_t try_send_number_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
540 static uint16_t try_send_number_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
541#endif
542#ifdef USE_DATETIME_DATE
543 static uint16_t try_send_date_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
544 static uint16_t try_send_date_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
545#endif
546#ifdef USE_DATETIME_TIME
547 static uint16_t try_send_time_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
548 static uint16_t try_send_time_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
549#endif
550#ifdef USE_DATETIME_DATETIME
551 static uint16_t try_send_datetime_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
552 static uint16_t try_send_datetime_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
553#endif
554#ifdef USE_TEXT
555 static uint16_t try_send_text_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
556 static uint16_t try_send_text_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
557#endif
558#ifdef USE_SELECT
559 static uint16_t try_send_select_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
560 static uint16_t try_send_select_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
561#endif
562#ifdef USE_BUTTON
563 static uint16_t try_send_button_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
564#endif
565#ifdef USE_LOCK
566 static uint16_t try_send_lock_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
567 static uint16_t try_send_lock_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
568#endif
569#ifdef USE_VALVE
570 static uint16_t try_send_valve_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
571 static uint16_t try_send_valve_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
572#endif
573#ifdef USE_MEDIA_PLAYER
574 static uint16_t try_send_media_player_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
575 static uint16_t try_send_media_player_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
576#endif
577#ifdef USE_ALARM_CONTROL_PANEL
578 static uint16_t try_send_alarm_control_panel_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
579 static uint16_t try_send_alarm_control_panel_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
580#endif
581#ifdef USE_WATER_HEATER
582 static uint16_t try_send_water_heater_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
583 static uint16_t try_send_water_heater_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
584#endif
585#ifdef USE_INFRARED
586 static uint16_t try_send_infrared_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
587#endif
588#ifdef USE_RADIO_FREQUENCY
589 static uint16_t try_send_radio_frequency_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
590#endif
591#ifdef USE_EVENT
592 static uint16_t try_send_event_response(event::Event *event, StringRef event_type, APIConnection *conn,
593 uint32_t remaining_size);
594 static uint16_t try_send_event_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
595#endif
596#ifdef USE_UPDATE
597 static uint16_t try_send_update_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
598 static uint16_t try_send_update_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
599#endif
600#ifdef USE_CAMERA
601 static uint16_t try_send_camera_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
602#endif
603
604 // Method for ListEntitiesDone batching
605 static uint16_t try_send_list_info_done(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
606
607 // Method for DisconnectRequest batching
608 static uint16_t try_send_disconnect_request(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
609
610 // Batch message method for ping requests
611 static uint16_t try_send_ping_request(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
612
613 // === Optimal member ordering for 32-bit systems ===
614
615 // Group 1: Pointers (4 bytes each on 32-bit)
616#if defined(USE_API_NOISE) && defined(USE_API_PLAINTEXT)
617 std::unique_ptr<APIFrameHelper> helper_;
618#elif defined(USE_API_NOISE)
619 std::unique_ptr<APINoiseFrameHelper> helper_;
620#elif defined(USE_API_PLAINTEXT)
621 std::unique_ptr<APIPlaintextFrameHelper> helper_;
622#endif
624
625 // Group 2: Iterator union (saves ~16 bytes vs separate iterators)
626 // These iterators are never active simultaneously - list_entities runs to completion
627 // before initial_state begins, so we use a union with explicit construction/destruction.
628 enum class ActiveIterator : uint8_t { NONE, LIST_ENTITIES, INITIAL_STATE };
629
633 // Constructor/destructor do nothing - use placement new/explicit destructor
637
638 // Helper methods for iterator lifecycle management
642#if defined(USE_API_NOISE) && defined(USE_API_PLAINTEXT)
643 // Swap the plaintext helper for a Noise helper after the client opened
644 // with a Noise hello on an unprovisioned device (zero-PSK provisioning).
646#endif
647#ifdef USE_CAMERA
648 std::unique_ptr<camera::CameraImageReader> image_reader_;
649#endif
650
651 // Group 3: 4-byte types
653#ifdef USE_API_HOMEASSISTANT_STATES
655#endif
656
657 // Function pointer type for message encoding
658 using MessageCreatorPtr = uint16_t (*)(EntityBase *, APIConnection *, uint32_t remaining_size);
659
660 // Generic batching mechanism for both state updates and entity info
662 // Sentinel value for unused aux_data_index
663 static constexpr uint8_t AUX_DATA_UNUSED = std::numeric_limits<uint8_t>::max();
664
665 struct BatchItem {
666 EntityBase *entity; // 4 bytes - Entity pointer
667 uint8_t message_type; // 1 byte - Message type for protocol and dispatch
668 uint8_t estimated_size; // 1 byte - Estimated message size (max 255 bytes)
669 uint8_t aux_data_index{AUX_DATA_UNUSED}; // 1 byte - For events: index into entity's event_types
670 // 1 byte padding
671 };
672
673 std::vector<BatchItem> items;
675
676 // No pre-allocation - log connections never use batching, and for
677 // connections that do, buffers are released after initial sync anyway
678
679 // Add item to the batch (with deduplication)
680 void add_item(EntityBase *entity, uint8_t message_type, uint8_t estimated_size,
681 uint8_t aux_data_index = AUX_DATA_UNUSED) {
682 // Dedup: O(n) scan but optimized for RAM over performance
683 // Skip deduplication for events - they are edge-triggered, every occurrence matters
684#ifdef USE_EVENT
685 if (message_type != EventResponse::MESSAGE_TYPE)
686#endif
687 {
688 for (const auto &item : this->items) {
689 if (item.entity == entity && item.message_type == message_type)
690 return; // Already queued
691 }
692 }
693 this->items.push_back({entity, message_type, estimated_size, aux_data_index});
694 }
695 // Add item to the front of the batch (for high priority messages like ping)
696 void add_item_front(EntityBase *entity, uint8_t message_type, uint8_t estimated_size) {
697 // Swap to front avoids expensive vector::insert which shifts all elements
698 this->items.push_back({entity, message_type, estimated_size, AUX_DATA_UNUSED});
699 if (this->items.size() > 1) {
700 std::swap(this->items.front(), this->items.back());
701 }
702 }
703
704 // Clear all items
705 void clear() {
706 items.clear();
708 }
709
710 // Remove processed items from the front — noinline to keep memmove out of warm callers
711 void remove_front(size_t count) __attribute__((noinline)) { items.erase(items.begin(), items.begin() + count); }
712
713 bool empty() const { return items.empty(); }
714 size_t size() const { return items.size(); }
715 const BatchItem &operator[](size_t index) const { return items[index]; }
716
717 // Release excess capacity - only releases if items already empty
719 // Safe to call: batch is processed before release_buffer is called,
720 // and if any items remain (partial processing), we must not clear them.
721 // Use swap trick since shrink_to_fit() is non-binding and may be ignored.
722 if (items.empty()) {
723 std::vector<BatchItem>().swap(items);
724 }
725 }
726 };
727
728 // DeferredBatch here (16 bytes, 4-byte aligned)
730
731 // ConnectionState enum for type safety
732 enum class ConnectionState : uint8_t {
734 CONNECTED = 1,
735 AUTHENTICATED = 2,
736 };
737
738 // Group 5: Pack all small members together to minimize padding
739 // This group starts at a 4-byte boundary after DeferredBatch
740 struct APIFlags {
741 // Connection state only needs 2 bits (3 states)
742 uint8_t connection_state : 2;
743 // Log subscription needs 3 bits (log levels 0-7)
744 uint8_t log_subscription : 3;
745 // Boolean flags (1 bit each)
746 uint8_t remove : 1;
748 uint8_t sent_ping : 1;
749
751 uint8_t next_close : 1;
752 uint8_t batch_scheduled : 1;
753 uint8_t batch_first_message : 1; // For batch buffer allocation
754 uint8_t should_try_send_immediately : 1; // True after initial states are sent
755 uint8_t may_have_remaining_data : 1; // Read loop hit limit, retry without ready check
756#ifdef HAS_PROTO_MESSAGE_DUMP
757 uint8_t log_only_mode : 1;
758#endif
759 } flags_{}; // 2 bytes total
760
761 // 2-byte types immediately after flags_ (no padding between them)
764 // 1-byte types to fill remaining space before next 4-byte boundary
766 uint8_t batch_message_type_{0}; // Current message type during batch encoding
767 // Total: 2 (flags) + 2 + 2 + 1 + 1 = 8 bytes, aligned to 4-byte boundary
768
769 // Actual header size used by encode_to_buffer for the current message.
770 // Read by process_batch_multi_ to pass into MessageInfo.
772
773 // Defined in api_connection_buffer.h (needs APIServer complete).
775 // Message will use 8 more bytes than the minimum size, and typical
776 // MTU is 1500. Sometimes users will see as low as 1460 MTU.
777 // If its IPv6 the header is 40 bytes, and if its IPv4
778 // the header is 20 bytes. So we have 1460 - 40 = 1420 bytes
779 // available for the payload. But we also need to add the size of
780 // the protobuf overhead, which is 8 bytes.
781 //
782 // To be safe we pick 1390 bytes as the maximum size
783 // to send in one go. This is the maximum size of a single packet
784 // that can be sent over the network.
785 // This is to avoid fragmentation of the packet.
786 static constexpr size_t MAX_BATCH_PACKET_SIZE = 1390; // MTU
787
788 bool schedule_batch_();
789 void process_batch_();
790 void process_batch_multi_(APIBuffer &shared_buf, size_t num_items, uint8_t header_padding, uint8_t footer_size)
791 __attribute__((noinline));
793 this->deferred_batch_.clear();
794 this->flags_.batch_scheduled = false;
795 }
796
797 // Dispatch message encoding based on message_type - replaces function pointer storage
798 // Switch assigns pointer, single call site for smaller code size
799 uint16_t dispatch_message_(const DeferredBatch::BatchItem &item, uint32_t remaining_size, bool batch_first);
800
801#ifdef HAS_PROTO_MESSAGE_DUMP
803 this->flags_.log_only_mode = true;
804 this->dispatch_message_(item, MAX_BATCH_PACKET_SIZE, true);
805 this->flags_.log_only_mode = false;
806 }
807#endif
808
809 // Helper to check if a message type should bypass batching
810 // Returns true if:
811 // 1. It's an UpdateStateResponse (always send immediately to handle cases where
812 // the main loop is blocked, e.g., during OTA updates)
813 // 2. It's an EventResponse (events are edge-triggered - every occurrence matters)
814 // 3. OR: User has opted into immediate sending (should_try_send_immediately = true
815 // AND batch_delay = 0)
816 inline bool should_send_immediately_(uint8_t message_type) const {
817 return (
818#ifdef USE_UPDATE
819 message_type == UpdateStateResponse::MESSAGE_TYPE ||
820#endif
821#ifdef USE_EVENT
822 message_type == EventResponse::MESSAGE_TYPE ||
823#endif
824 (this->flags_.should_try_send_immediately && this->get_batch_delay_ms_() == 0));
825 }
826
827 // Helper method to send a message either immediately or via batching
828 // Tries immediate send if should_send_immediately_() returns true and buffer has space
829 // Falls back to batching if immediate send fails or isn't applicable
830 bool send_message_smart_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size,
831 uint8_t aux_data_index = DeferredBatch::AUX_DATA_UNUSED);
832
833 // Helper function to schedule a deferred message with known message type
834 bool schedule_message_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size,
835 uint8_t aux_data_index = DeferredBatch::AUX_DATA_UNUSED) {
836 this->deferred_batch_.add_item(entity, message_type, estimated_size, aux_data_index);
837 return this->schedule_batch_();
838 }
839
840 // Helper function to schedule a high priority message at the front of the batch
841 // Out-of-line: callers (on_shutdown, check_keepalive_) are cold paths
842 bool schedule_message_front_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size);
843
844 // Helper function to log client messages with name and peername
845 void log_client_(int level, const LogString *message);
846 // Helper function to log API errors with errno
847 void log_warning_(const LogString *message, APIError err);
848 // Helper to handle fatal errors with logging
849 inline void fatal_error_with_log_(const LogString *message, APIError err) {
850 this->on_fatal_error();
851 this->log_warning_(message, err);
852 }
853};
854
855} // namespace esphome::api
856#endif
StringRef is a reference to a string owned by something else.
Definition string_ref.h:26
Byte buffer that skips zero-initialization on resize().
Definition api_buffer.h:36
void reserve_and_resize(size_t reserve_size, size_t new_size) ESPHOME_ALWAYS_INLINE
Reserve capacity for max(reserve_size, new_size) bytes, then set size to new_size.
Definition api_buffer.h:49
struct esphome::api::APIConnection::APIFlags flags_
static uint16_t try_send_text_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_subscribe_voice_assistant_request(const SubscribeVoiceAssistantRequest &msg)
void on_camera_image_request(const CameraImageRequest &msg)
void on_media_player_command_request(const MediaPlayerCommandRequest &msg)
static uint16_t try_send_event_response(event::Event *event, StringRef event_type, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_water_heater_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_text_command_request(const TextCommandRequest &msg)
static uint16_t try_send_text_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_ping_request(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_infrared_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool send_media_player_state(media_player::MediaPlayer *media_player)
void on_update_command_request(const UpdateCommandRequest &msg)
std::unique_ptr< APIPlaintextFrameHelper > helper_
bool send_time_state(datetime::TimeEntity *time)
bool schedule_message_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size, uint8_t aux_data_index=DeferredBatch::AUX_DATA_UNUSED)
void on_voice_assistant_announce_request(const VoiceAssistantAnnounceRequest &msg)
static uint16_t encode_message_to_buffer(T &msg, APIConnection *conn, uint32_t remaining_size)
static uint16_t fill_and_encode_entity_state(EntityBase *entity, T &msg, APIConnection *conn, uint32_t remaining_size)
void __attribute__((noinline)) process_active_iterator_()
bool send_water_heater_state(water_heater::WaterHeater *water_heater)
void on_subscribe_bluetooth_le_advertisements_request(const SubscribeBluetoothLEAdvertisementsRequest &msg)
void send_execute_service_response(uint32_t call_id, bool success, StringRef error_message)
static uint16_t try_send_binary_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_button_command_request(const ButtonCommandRequest &msg)
void on_bluetooth_gatt_get_services_request(const BluetoothGATTGetServicesRequest &msg)
void on_bluetooth_gatt_notify_request(const BluetoothGATTNotifyRequest &msg)
static uint16_t try_send_date_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_valve_command_request(const ValveCommandRequest &msg)
void on_bluetooth_device_request(const BluetoothDeviceRequest &msg)
static uint16_t try_send_valve_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_number_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
uint16_t dispatch_message_(const DeferredBatch::BatchItem &item, uint32_t remaining_size, bool batch_first)
static uint32_t calc_size(const void *msg)
bool send_text_sensor_state(text_sensor::TextSensor *text_sensor)
static uint16_t try_send_fan_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_bluetooth_gatt_read_descriptor_request(const BluetoothGATTReadDescriptorRequest &msg)
bool send_fan_state(fan::Fan *fan)
void on_bluetooth_gatt_write_request(const BluetoothGATTWriteRequest &msg)
bool check_voice_assistant_api_connection_() const
void send_serial_proxy_data(const SerialProxyDataReceived &msg)
bool send_message_smart_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size, uint8_t aux_data_index=DeferredBatch::AUX_DATA_UNUSED)
static uint16_t try_send_button_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
union esphome::api::APIConnection::IteratorUnion iterator_storage_
static uint16_t try_send_list_info_done(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_lock_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_cover_command_request(const CoverCommandRequest &msg)
std::unique_ptr< APIFrameHelper > helper_
static uint16_t try_send_alarm_control_panel_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void set_camera_state(std::shared_ptr< camera::CameraImage > image)
static uint16_t try_send_event_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_z_wave_proxy_frame(const ZWaveProxyFrame &msg)
static uint16_t fill_and_encode_entity_info_with_device_class(EntityBase *entity, T &msg, StringRef &device_class_field, APIConnection *conn, uint32_t remaining_size)
bool send_sensor_state(sensor::Sensor *sensor)
const char * get_peername_to(std::span< char, socket::SOCKADDR_STR_LEN > buf) const
Get peer name (IP address) into caller-provided buffer, returns buf for convenience.
static constexpr size_t MAX_BATCH_PACKET_SIZE
void log_batch_item_(const DeferredBatch::BatchItem &item)
static uint16_t try_send_climate_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_fan_command_request(const FanCommandRequest &msg)
static uint16_t try_send_number_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_text_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
const char * get_name() const
friend void bench_clear_batch(APIConnection *conn)
void on_disconnect_request(const DisconnectRequest &msg)
void on_climate_command_request(const ClimateCommandRequest &msg)
bool send_binary_sensor_state(binary_sensor::BinarySensor *binary_sensor)
void on_bluetooth_scanner_set_mode_request(const BluetoothScannerSetModeRequest &msg)
bool send_valve_state(valve::Valve *valve)
bool send_voice_assistant_get_configuration_response_(const VoiceAssistantConfigurationRequest &msg)
bool send_select_state(select::Select *select)
void on_voice_assistant_configuration_request(const VoiceAssistantConfigurationRequest &msg)
bool send_switch_state(switch_::Switch *a_switch)
void send_event(event::Event *event)
static uint16_t try_send_climate_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_z_wave_proxy_request(const ZWaveProxyRequest &msg)
static uint16_t try_send_cover_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool send_noise_encryption_set_key_response_(const NoiseEncryptionSetKeyRequest &msg)
void on_bluetooth_set_connection_params_request(const BluetoothSetConnectionParamsRequest &msg)
static uint16_t try_send_disconnect_request(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t fill_and_encode_entity_state(EntityBase *entity, StateResponseProtoMessage &msg, CalculateSizeFn size_fn, MessageEncodeFn encode_fn, APIConnection *conn, uint32_t remaining_size)
static uint16_t fill_and_encode_entity_info_with_device_class(EntityBase *entity, InfoResponseProtoMessage &msg, StringRef &device_class_field, CalculateSizeFn size_fn, MessageEncodeFn encode_fn, APIConnection *conn, uint32_t remaining_size)
void on_date_command_request(const DateCommandRequest &msg)
void log_client_(int level, const LogString *message)
void on_subscribe_logs_request(const SubscribeLogsRequest &msg)
static uint16_t try_send_alarm_control_panel_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_serial_proxy_get_modem_pins_request(const SerialProxyGetModemPinsRequest &msg)
uint8_t *(*)(const void *, ProtoWriteBuffer &PROTO_ENCODE_DEBUG_PARAM) MessageEncodeFn
void send_infrared_rf_receive_event(const InfraredRFReceiveEvent &msg)
bool should_send_immediately_(uint8_t message_type) const
bool send_lock_state(lock::Lock *a_lock)
void on_voice_assistant_timer_event_response(const VoiceAssistantTimerEventResponse &msg)
void on_select_command_request(const SelectCommandRequest &msg)
bool send_message(const T &msg)
Returns false as soon as the TCP buffer is full.
static uint16_t try_send_valve_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_lock_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_update_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_infrared_rf_transmit_raw_timings_request(const InfraredRFTransmitRawTimingsRequest &msg)
void on_serial_proxy_set_modem_pins_request(const SerialProxySetModemPinsRequest &msg)
void on_homeassistant_action_response(const HomeassistantActionResponse &msg)
void prepare_first_message_buffer(APIBuffer &shared_buf, size_t payload_size)
void on_switch_command_request(const SwitchCommandRequest &msg)
bool send_update_state(update::UpdateEntity *update)
bool send_homeassistant_action(const HomeassistantActionRequest &call)
static uint16_t try_send_datetime_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_get_time_response(const GetTimeResponse &value)
void fatal_error_with_log_(const LogString *message, APIError err)
static uint16_t try_send_media_player_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_switch_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg)
void log_warning_(const LogString *message, APIError err)
void on_serial_proxy_request(const SerialProxyRequest &msg)
static uint16_t try_send_select_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_lock_command_request(const LockCommandRequest &msg)
void begin_iterator_(ActiveIterator type)
void on_bluetooth_gatt_write_descriptor_request(const BluetoothGATTWriteDescriptorRequest &msg)
std::unique_ptr< camera::CameraImageReader > image_reader_
void on_execute_service_request(const ExecuteServiceRequest &msg)
APIConnection(std::unique_ptr< socket::Socket > socket, APIServer *parent)
static uint16_t try_send_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_select_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool send_date_state(datetime::DateEntity *date)
friend void bench_enable_immediate_send(APIConnection *conn)
void on_number_command_request(const NumberCommandRequest &msg)
bool send_number_state(number::Number *number)
static uint16_t encode_to_buffer_slow(uint32_t calculated_size, MessageEncodeFn encode_fn, const void *msg, APIConnection *conn, uint32_t remaining_size)
std::unique_ptr< APINoiseFrameHelper > helper_
bool schedule_message_front_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size)
static uint16_t try_send_radio_frequency_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool send_hello_response_(const HelloRequest &msg)
bool send_light_state(light::LightState *light)
static uint8_t * encode_msg_noop(const void *, ProtoWriteBuffer &buf PROTO_ENCODE_DEBUG_PARAM)
friend void bench_process_batch(APIConnection *conn)
static uint16_t try_send_text_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
uint16_t(*)(EntityBase *, APIConnection *, uint32_t remaining_size) MessageCreatorPtr
static uint16_t try_send_time_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_serial_proxy_configure_request(const SerialProxyConfigureRequest &msg)
void on_time_command_request(const TimeCommandRequest &msg)
uint8_t get_log_subscription_level() const
static uint16_t try_send_datetime_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_camera_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool send_message_(uint32_t payload_size, uint8_t message_type, MessageEncodeFn encode_fn, const void *msg)
void on_bluetooth_gatt_read_request(const BluetoothGATTReadRequest &msg)
bool send_subscribe_bluetooth_connections_free_response_()
void prepare_first_message_buffer(APIBuffer &shared_buf, size_t header_padding, size_t total_size)
void on_hello_request(const HelloRequest &msg)
void on_voice_assistant_audio(const VoiceAssistantAudio &msg)
bool send_datetime_state(datetime::DateTimeEntity *datetime)
void on_serial_proxy_write_request(const SerialProxyWriteRequest &msg)
void on_light_command_request(const LightCommandRequest &msg)
bool send_alarm_control_panel_state(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel)
static uint16_t try_send_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_binary_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_light_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t fill_and_encode_entity_info(EntityBase *entity, InfoResponseProtoMessage &msg, CalculateSizeFn size_fn, MessageEncodeFn encode_fn, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_update_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_voice_assistant_set_configuration(const VoiceAssistantSetConfiguration &msg)
bool send_text_state(text::Text *text)
static uint16_t try_send_date_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t fill_and_encode_entity_info(EntityBase *entity, T &msg, APIConnection *conn, uint32_t remaining_size)
void on_date_time_command_request(const DateTimeCommandRequest &msg)
void read_message_(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data)
static uint16_t ESPHOME_ALWAYS_INLINE encode_to_buffer(uint32_t calculated_size, MessageEncodeFn encode_fn, const void *msg, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_water_heater_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_voice_assistant_event_response(const VoiceAssistantEventResponse &msg)
static uint16_t try_send_time_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_alarm_control_panel_command_request(const AlarmControlPanelCommandRequest &msg)
bool try_send_log_message(int level, const char *tag, const char *line, size_t message_len)
void process_iterator_batch_(ComponentIterator &iterator)
static uint16_t try_send_cover_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_unsubscribe_bluetooth_le_advertisements_request()
bool send_buffer(ProtoWriteBuffer buffer, uint8_t message_type)
bool client_supports_api_version(uint16_t major, uint16_t minor) const
void process_batch_multi_(APIBuffer &shared_buf, size_t num_items, uint8_t header_padding, uint8_t footer_size) __attribute__((noinline))
static uint16_t try_send_light_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_water_heater_command_request(const WaterHeaterCommandRequest &msg)
bool send_climate_state(climate::Climate *climate)
bool try_to_clear_buffer(bool log_out_of_space)
bool send_cover_state(cover::Cover *cover)
static uint16_t try_send_switch_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool try_to_clear_buffer_slow_(bool log_out_of_space)
void on_home_assistant_state_response(const HomeAssistantStateResponse &msg)
void __attribute__((noinline)) check_keepalive_(uint32_t now)
uint32_t(*)(const void *) CalculateSizeFn
static uint16_t try_send_media_player_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_fan_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_voice_assistant_response(const VoiceAssistantResponse &msg)
static constexpr uint8_t MESSAGE_TYPE
Definition api_pb2.h:2915
static constexpr uint8_t MESSAGE_TYPE
Definition api_pb2.h:675
static constexpr uint8_t ESTIMATED_SIZE
Definition api_pb2.h:676
static constexpr uint8_t MESSAGE_TYPE
Definition api_pb2.h:3055
Base class for all binary_sensor-type classes.
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:187
Base class for all cover devices.
Definition cover.h:110
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
Base class for all locks.
Definition lock.h:112
Base-class for all numbers.
Definition number.h:29
Base-class for all selects.
Definition select.h:29
Base-class for all sensors.
Definition sensor.h:47
Base class for all switches.
Definition switch.h:38
Base-class for all text inputs.
Definition text.h:21
Base class for all valve devices.
Definition valve.h:103
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
const LogString * message
Definition component.cpp:35
uint16_t type
uint8_t * proto_encode_msg(const void *msg, ProtoWriteBuffer &buf PROTO_ENCODE_DEBUG_PARAM)
Definition proto.h:885
void bench_process_batch(APIConnection *conn)
void log_dropped_message(const char *tag, int line, const LogString *what)
void bench_enable_immediate_send(APIConnection *conn)
void bench_clear_batch(APIConnection *conn)
void crash_handler_log()
Log crash data if a crash was detected on previous boot.
void crash_handler_clear()
Clear the magic marker and mark crash data as consumed.
void crash_handler_log()
Log crash data if a crash was detected on previous boot.
void crash_handler_log()
Log crash data if a crash was detected on previous boot.
const char int line
Definition log.h:74
const char * tag
Definition log.h:74
Application App
Global storage of Application pointer - only one Application can exist.
static void uint32_t
void remove_front(size_t count) __attribute__((noinline))
const BatchItem & operator[](size_t index) const
void add_item_front(EntityBase *entity, uint8_t message_type, uint8_t estimated_size)
void add_item(EntityBase *entity, uint8_t message_type, uint8_t estimated_size, uint8_t aux_data_index=AUX_DATA_UNUSED)
uint32_t payload_size()