ESPHome 2026.10.0-dev
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 // Stored versions saturate at 255 (see send_hello_response_), so requesting
331 // a minimum above that can never match.
332 bool client_supports_api_version(uint8_t major, uint8_t minor) const {
333 return this->client_api_version_major_ > major ||
334 (this->client_api_version_major_ == major && this->client_api_version_minor_ >= minor);
335 }
336
337 void on_fatal_error();
339
340 // Function pointer type for type-erased message encoding
341 using MessageEncodeFn = uint8_t *(*) (const void *, ProtoWriteBuffer &PROTO_ENCODE_DEBUG_PARAM);
342 // Function pointer type for type-erased size calculation
343 using CalculateSizeFn = uint32_t (*)(const void *);
344
347 template<typename T> [[nodiscard]] bool send_message(const T &msg) {
348 if constexpr (T::ESTIMATED_SIZE == 0) {
349 return this->send_message_(0, T::MESSAGE_TYPE, &encode_msg_noop, &msg);
350 } else {
351 return this->send_message_(msg.calculate_size(), T::MESSAGE_TYPE, &proto_encode_msg<T>, &msg);
352 }
353 }
354
358 [[nodiscard]] bool prepare_first_message_buffer(size_t header_padding, size_t total_size);
359
360 // Convenience overload - computes frame overhead internally
361 [[nodiscard]] bool prepare_first_message_buffer(size_t payload_size);
362
363 bool try_to_clear_buffer(bool log_out_of_space) {
364 if (this->flags_.remove)
365 return false;
366 if (this->helper_->can_write_without_blocking())
367 return true;
368 return this->try_to_clear_buffer_slow_(log_out_of_space);
369 }
370 bool send_buffer(ProtoWriteBuffer buffer, uint16_t message_type);
371
372 const char *get_name() const { return this->helper_->get_client_name(); }
374 const char *get_peername_to(std::span<char, socket::SOCKADDR_STR_LEN> buf) const {
375 return this->helper_->get_peername_to(buf);
376 }
377
378 protected:
379 bool try_to_clear_buffer_slow_(bool log_out_of_space);
380
381 // Helper function to handle authentication completion
383
384 // Pattern B helpers: send response and return success/failure
385 bool send_hello_response_(const HelloRequest &msg);
387 bool send_ping_response_();
390#ifdef USE_API_NOISE
392#endif
393#ifdef USE_BLUETOOTH_PROXY_CONNECTIONS
395#endif
396#ifdef USE_VOICE_ASSISTANT
398#endif
399
400#ifdef USE_CAMERA
402#endif
403
404#ifdef USE_API_HOMEASSISTANT_STATES
406#endif
407
408 // Size thunk — converts void* back to concrete type for direct calculate_size() call
409 template<typename T> static uint32_t calc_size(const void *msg) {
410 return static_cast<const T *>(msg)->calculate_size();
411 }
412
413 // Shared no-op encode thunk for empty messages (ESTIMATED_SIZE == 0)
414 static uint8_t *encode_msg_noop(const void *, ProtoWriteBuffer &buf PROTO_ENCODE_DEBUG_PARAM) {
415 return buf.get_pos();
416 }
417
418 // Non-template buffer management for send_message
419 bool send_message_(uint32_t payload_size, uint16_t message_type, MessageEncodeFn encode_fn, const void *msg);
420
421 // Core batch encoding logic. ALWAYS_INLINE so encode_fn devirtualizes at hot call sites.
422 // Defined in api_connection_buffer.h (needs APIServer complete).
423 static uint16_t ESPHOME_ALWAYS_INLINE encode_to_buffer(uint32_t calculated_size, MessageEncodeFn encode_fn,
424 const void *msg, APIConnection *conn, uint32_t remaining_size);
425
426 // Noinline version of encode_to_buffer for cold paths (entity info, zero-payload messages).
427 // All cold callers share this single copy instead of each getting an ALWAYS_INLINE expansion.
428 static uint16_t encode_to_buffer_slow(uint32_t calculated_size, MessageEncodeFn encode_fn, const void *msg,
429 APIConnection *conn, uint32_t remaining_size);
430
431 // Thin template wrapper — uses noinline encode_to_buffer_slow since
432 // encode_message_to_buffer callers are cold paths (zero-payload control messages).
433 // Hot paths (state/info) go through fill_and_encode_entity_state/info instead.
434 // batch_message_type_ is already set by dispatch_message_ before reaching here.
435 template<typename T> static uint16_t encode_message_to_buffer(T &msg, APIConnection *conn, uint32_t remaining_size) {
436 if constexpr (T::ESTIMATED_SIZE == 0) {
437 return encode_to_buffer_slow(0, &encode_msg_noop, &msg, conn, remaining_size);
438 } else {
439 return encode_to_buffer_slow(msg.calculate_size(), &proto_encode_msg<T>, &msg, conn, remaining_size);
440 }
441 }
442
443 // Non-template core — fills state fields and encodes
445 CalculateSizeFn size_fn, MessageEncodeFn encode_fn, APIConnection *conn,
446 uint32_t remaining_size);
447
448 // Thin template wrapper
449 template<typename T>
450 static uint16_t fill_and_encode_entity_state(EntityBase *entity, T &msg, APIConnection *conn,
451 uint32_t remaining_size) {
452 return fill_and_encode_entity_state(entity, msg, &calc_size<T>, &proto_encode_msg<T>, conn, remaining_size);
453 }
454
455 // Non-template core — fills info fields, allocates buffers, and encodes
457 CalculateSizeFn size_fn, MessageEncodeFn encode_fn, APIConnection *conn,
458 uint32_t remaining_size);
459
460 // Thin template wrapper
461 template<typename T>
462 static uint16_t fill_and_encode_entity_info(EntityBase *entity, T &msg, APIConnection *conn,
463 uint32_t remaining_size) {
464 return fill_and_encode_entity_info(entity, msg, &calc_size<T>, &proto_encode_msg<T>, conn, remaining_size);
465 }
466
467 // Non-template core — fills device_class, then delegates to fill_and_encode_entity_info
469 StringRef &device_class_field, CalculateSizeFn size_fn,
470 MessageEncodeFn encode_fn, APIConnection *conn,
471 uint32_t remaining_size);
472
473 // Thin template wrapper
474 template<typename T>
476 StringRef &device_class_field, APIConnection *conn,
477 uint32_t remaining_size) {
478 return fill_and_encode_entity_info_with_device_class(entity, msg, device_class_field, &calc_size<T>,
479 &proto_encode_msg<T>, conn, remaining_size);
480 }
481
482#ifdef USE_VOICE_ASSISTANT
483 // Helper to check voice assistant validity and connection ownership
484 inline bool check_voice_assistant_api_connection_() const;
485#endif
486
487 // Send keepalive ping or disconnect unresponsive client.
488 // Cold path — extracted from loop() to reduce instruction cache pressure.
489 void __attribute__((noinline)) check_keepalive_(uint32_t now);
490
491 // Process active iterator (list_entities/initial_state) during connection setup.
492 // Extracted from loop() — only runs during initial handshake, NONE in steady state.
493 void __attribute__((noinline)) process_active_iterator_();
494
495 // Helper method to process multiple entities from an iterator in a batch.
496 // Takes ComponentIterator base class reference to avoid duplicate template instantiations.
498
499#ifdef USE_BINARY_SENSOR
500 static uint16_t try_send_binary_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
501 static uint16_t try_send_binary_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
502#endif
503#ifdef USE_COVER
504 static uint16_t try_send_cover_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
505 static uint16_t try_send_cover_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
506#endif
507#ifdef USE_FAN
508 static uint16_t try_send_fan_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
509 static uint16_t try_send_fan_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
510#endif
511#ifdef USE_LIGHT
512 static uint16_t try_send_light_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
513 static uint16_t try_send_light_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
514#endif
515#ifdef USE_SENSOR
516 static uint16_t try_send_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
517 static uint16_t try_send_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
518#endif
519#ifdef USE_SWITCH
520 static uint16_t try_send_switch_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
521 static uint16_t try_send_switch_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
522#endif
523#ifdef USE_TEXT_SENSOR
524 static uint16_t try_send_text_sensor_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
525 static uint16_t try_send_text_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
526#endif
527#ifdef USE_CLIMATE
528 static uint16_t try_send_climate_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
529 static uint16_t try_send_climate_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
530#endif
531#ifdef USE_NUMBER
532 static uint16_t try_send_number_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
533 static uint16_t try_send_number_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
534#endif
535#ifdef USE_DATETIME_DATE
536 static uint16_t try_send_date_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
537 static uint16_t try_send_date_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
538#endif
539#ifdef USE_DATETIME_TIME
540 static uint16_t try_send_time_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
541 static uint16_t try_send_time_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
542#endif
543#ifdef USE_DATETIME_DATETIME
544 static uint16_t try_send_datetime_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
545 static uint16_t try_send_datetime_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
546#endif
547#ifdef USE_TEXT
548 static uint16_t try_send_text_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
549 static uint16_t try_send_text_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
550#endif
551#ifdef USE_SELECT
552 static uint16_t try_send_select_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
553 static uint16_t try_send_select_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
554#endif
555#ifdef USE_BUTTON
556 static uint16_t try_send_button_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
557#endif
558#ifdef USE_LOCK
559 static uint16_t try_send_lock_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
560 static uint16_t try_send_lock_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
561#endif
562#ifdef USE_VALVE
563 static uint16_t try_send_valve_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
564 static uint16_t try_send_valve_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
565#endif
566#ifdef USE_MEDIA_PLAYER
567 static uint16_t try_send_media_player_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
568 static uint16_t try_send_media_player_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
569#endif
570#ifdef USE_ALARM_CONTROL_PANEL
571 static uint16_t try_send_alarm_control_panel_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
572 static uint16_t try_send_alarm_control_panel_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
573#endif
574#ifdef USE_WATER_HEATER
575 static uint16_t try_send_water_heater_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
576 static uint16_t try_send_water_heater_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
577#endif
578#ifdef USE_INFRARED
579 static uint16_t try_send_infrared_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
580#endif
581#ifdef USE_RADIO_FREQUENCY
582 static uint16_t try_send_radio_frequency_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
583#endif
584#ifdef USE_EVENT
585 static uint16_t try_send_event_response(event::Event *event, StringRef event_type, APIConnection *conn,
586 uint32_t remaining_size);
587 static uint16_t try_send_event_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
588#endif
589#ifdef USE_UPDATE
590 static uint16_t try_send_update_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
591 static uint16_t try_send_update_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
592#endif
593#ifdef USE_CAMERA
594 static uint16_t try_send_camera_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
595#endif
596
597 // Method for ListEntitiesDone batching
598 static uint16_t try_send_list_info_done(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
599
600 // Method for DisconnectRequest batching
601 static uint16_t try_send_disconnect_request(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
602
603 // Batch message method for ping requests
604 static uint16_t try_send_ping_request(EntityBase *entity, APIConnection *conn, uint32_t remaining_size);
605
606 // === Optimal member ordering for 32-bit systems ===
607
608 // Group 1: Pointers (4 bytes each on 32-bit)
609#if defined(USE_API_NOISE) && defined(USE_API_PLAINTEXT)
610 std::unique_ptr<APIFrameHelper> helper_;
611#elif defined(USE_API_NOISE)
612 std::unique_ptr<APINoiseFrameHelper> helper_;
613#elif defined(USE_API_PLAINTEXT)
614 std::unique_ptr<APIPlaintextFrameHelper> helper_;
615#endif
617
618 // Group 2: Iterator union (saves ~16 bytes vs separate iterators)
619 // These iterators are never active simultaneously - list_entities runs to completion
620 // before initial_state begins, so we use a union with explicit construction/destruction.
621 enum class ActiveIterator : uint8_t { NONE, LIST_ENTITIES, INITIAL_STATE };
622
626 // Constructor/destructor do nothing - use placement new/explicit destructor
630
631 // Helper methods for iterator lifecycle management
635#if defined(USE_API_NOISE) && defined(USE_API_PLAINTEXT)
636 // Swap the plaintext helper for a Noise helper after the client opened
637 // with a Noise hello on an unprovisioned device (zero-PSK provisioning).
639#endif
640#ifdef USE_CAMERA
641 std::unique_ptr<camera::CameraImageReader> image_reader_;
642#endif
643
644 // Group 3: 4-byte types
646#ifdef USE_API_HOMEASSISTANT_STATES
648#endif
649
650 // Function pointer type for message encoding
651 using MessageCreatorPtr = uint16_t (*)(EntityBase *, APIConnection *, uint32_t remaining_size);
652
653 // Generic batching mechanism for both state updates and entity info
655 // Sentinel value for unused aux_data_index
656 static constexpr uint8_t AUX_DATA_UNUSED = std::numeric_limits<uint8_t>::max();
657
658 struct BatchItem {
659 EntityBase *entity; // 4 bytes - Entity pointer
660 uint16_t message_type; // 2 bytes - Message type for protocol and dispatch
661 uint8_t estimated_size; // 1 byte - Estimated message size (max 255 bytes)
662 uint8_t aux_data_index{AUX_DATA_UNUSED}; // 1 byte - For events: index into entity's event_types
663 };
664
665 std::vector<BatchItem> items;
667
668 // No pre-allocation - log connections never use batching, and for
669 // connections that do, buffers are released after initial sync anyway
670
671 // Add item to the batch (with deduplication)
672 void add_item(EntityBase *entity, uint16_t message_type, uint8_t estimated_size,
673 uint8_t aux_data_index = AUX_DATA_UNUSED) {
674 // Dedup: O(n) scan but optimized for RAM over performance
675 // Skip deduplication for events - they are edge-triggered, every occurrence matters
676#ifdef USE_EVENT
677 if (message_type != EventResponse::MESSAGE_TYPE)
678#endif
679 {
680 for (const auto &item : this->items) {
681 if (item.entity == entity && item.message_type == message_type)
682 return; // Already queued
683 }
684 }
685 this->items.push_back({entity, message_type, estimated_size, aux_data_index});
686 }
687 // Add item to the front of the batch (for high priority messages like ping)
688 void add_item_front(EntityBase *entity, uint16_t message_type, uint8_t estimated_size) {
689 // Swap to front avoids expensive vector::insert which shifts all elements
690 this->items.push_back({entity, message_type, estimated_size, AUX_DATA_UNUSED});
691 if (this->items.size() > 1) {
692 std::swap(this->items.front(), this->items.back());
693 }
694 }
695
696 // Clear all items
697 void clear() {
698 items.clear();
700 }
701
702 // Remove processed items from the front — noinline to keep memmove out of warm callers
703 void remove_front(size_t count) __attribute__((noinline)) { items.erase(items.begin(), items.begin() + count); }
704
705 bool empty() const { return items.empty(); }
706 size_t size() const { return items.size(); }
707 const BatchItem &operator[](size_t index) const { return items[index]; }
708
709 // Release excess capacity - only releases if items already empty
711 // Safe to call: batch is processed before release_buffer is called,
712 // and if any items remain (partial processing), we must not clear them.
713 // Use swap trick since shrink_to_fit() is non-binding and may be ignored.
714 if (items.empty()) {
715 std::vector<BatchItem>().swap(items);
716 }
717 }
718 };
719
720 // DeferredBatch here (16 bytes, 4-byte aligned)
722
723 // ConnectionState enum for type safety
724 enum class ConnectionState : uint8_t {
726 CONNECTED = 1,
727 AUTHENTICATED = 2,
728 };
729
730 // Group 5: Pack all small members together to minimize padding
731 // This group starts at a 4-byte boundary after DeferredBatch
732 struct APIFlags {
733 // Connection state only needs 2 bits (3 states)
734 uint8_t connection_state : 2;
735 // Log subscription needs 3 bits (log levels 0-7)
736 uint8_t log_subscription : 3;
737 // Boolean flags (1 bit each)
738 uint8_t remove : 1;
740 uint8_t sent_ping : 1;
741
743 uint8_t next_close : 1;
744 uint8_t batch_scheduled : 1;
745 uint8_t batch_first_message : 1; // For batch buffer allocation
746 uint8_t should_try_send_immediately : 1; // True after initial states are sent
747 uint8_t may_have_remaining_data : 1; // Read loop hit limit, retry without ready check
748#ifdef HAS_PROTO_MESSAGE_DUMP
749 uint8_t log_only_mode : 1;
750#endif
751 } flags_{}; // 2 bytes total
752
753 // 2-byte type immediately after flags_ (no padding between them)
754 uint16_t batch_message_type_{0}; // Current message type during batch encoding
755 // 1-byte types to fill remaining space before next 4-byte boundary
756 // Client API versions are clamped to 255 on receive (see send_hello_response_)
760 // Total: 2 (flags) + 2 + 1 + 1 + 1 + 1 (batch_header_size_ below) = 8 bytes,
761 // aligned to 4-byte boundary
762
763 // Actual header size used by encode_to_buffer for the current message.
764 // Read by process_batch_multi_ to pass into MessageInfo.
766
767 // Defined in api_connection_buffer.h (needs APIServer complete).
769 // Message will use 8 more bytes than the minimum size, and typical
770 // MTU is 1500. Sometimes users will see as low as 1460 MTU.
771 // If its IPv6 the header is 40 bytes, and if its IPv4
772 // the header is 20 bytes. So we have 1460 - 40 = 1420 bytes
773 // available for the payload. But we also need to add the size of
774 // the protobuf overhead, which is 8 bytes.
775 //
776 // To be safe we pick 1390 bytes as the maximum size
777 // to send in one go. This is the maximum size of a single packet
778 // that can be sent over the network.
779 // This is to avoid fragmentation of the packet.
780 static constexpr size_t MAX_BATCH_PACKET_SIZE = 1390; // MTU
781
782 bool schedule_batch_();
783 void process_batch_();
784 void process_batch_multi_(APIBuffer &shared_buf, size_t num_items, uint8_t header_padding, uint8_t footer_size)
785 __attribute__((noinline));
787 this->deferred_batch_.clear();
788 this->flags_.batch_scheduled = false;
789 }
790
791 // Dispatch message encoding based on message_type - replaces function pointer storage
792 // Switch assigns pointer, single call site for smaller code size
793 uint16_t dispatch_message_(const DeferredBatch::BatchItem &item, uint32_t remaining_size, bool batch_first);
794
795#ifdef HAS_PROTO_MESSAGE_DUMP
797 this->flags_.log_only_mode = true;
798 this->dispatch_message_(item, MAX_BATCH_PACKET_SIZE, true);
799 this->flags_.log_only_mode = false;
800 }
801#endif
802
803 // Helper to check if a message type should bypass batching
804 // Returns true if:
805 // 1. It's an UpdateStateResponse (always send immediately to handle cases where
806 // the main loop is blocked, e.g., during OTA updates)
807 // 2. It's an EventResponse (events are edge-triggered - every occurrence matters)
808 // 3. OR: User has opted into immediate sending (should_try_send_immediately = true
809 // AND batch_delay = 0)
810 inline bool should_send_immediately_(uint16_t message_type) const {
811 return (
812#ifdef USE_UPDATE
813 message_type == UpdateStateResponse::MESSAGE_TYPE ||
814#endif
815#ifdef USE_EVENT
816 message_type == EventResponse::MESSAGE_TYPE ||
817#endif
818 (this->flags_.should_try_send_immediately && this->get_batch_delay_ms_() == 0));
819 }
820
821 // Helper method to send a message either immediately or via batching
822 // Tries immediate send if should_send_immediately_() returns true and buffer has space
823 // Falls back to batching if immediate send fails or isn't applicable
824 bool send_message_smart_(EntityBase *entity, uint16_t message_type, uint8_t estimated_size,
825 uint8_t aux_data_index = DeferredBatch::AUX_DATA_UNUSED);
826
827 // Helper function to schedule a deferred message with known message type
828 bool schedule_message_(EntityBase *entity, uint16_t message_type, uint8_t estimated_size,
829 uint8_t aux_data_index = DeferredBatch::AUX_DATA_UNUSED) {
830 this->deferred_batch_.add_item(entity, message_type, estimated_size, aux_data_index);
831 return this->schedule_batch_();
832 }
833
834 // Helper function to schedule a high priority message at the front of the batch
835 // Out-of-line: callers (on_shutdown, check_keepalive_) are cold paths
836 bool schedule_message_front_(EntityBase *entity, uint16_t message_type, uint8_t estimated_size);
837
838 // Helper function to log client messages with name and peername
839 void log_client_(int level, const LogString *message);
840 // Helper function to log API errors with errno
841 void log_warning_(const LogString *message, APIError err);
842 // Helper to handle fatal errors with logging
843 inline void fatal_error_with_log_(const LogString *message, APIError err) {
844 this->on_fatal_error();
845 this->log_warning_(message, err);
846 }
847 // Shared cold path for buffer allocation failures — noinline keeps the
848 // OOM handling out of the hot send paths
849 void __attribute__((noinline)) fatal_out_of_memory_();
850};
851
852} // namespace esphome::api
853#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:26
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)
bool send_buffer(ProtoWriteBuffer buffer, uint16_t message_type)
std::unique_ptr< APIPlaintextFrameHelper > helper_
bool send_time_state(datetime::TimeEntity *time)
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)
bool prepare_first_message_buffer(size_t header_padding, size_t total_size)
Clear the shared write buffer and reserve space for the first message.
void on_valve_command_request(const ValveCommandRequest &msg)
void on_bluetooth_device_request(const BluetoothDeviceRequest &msg)
bool client_supports_api_version(uint8_t major, uint8_t minor) const
void __attribute__((noinline)) fatal_out_of_memory_()
static uint16_t try_send_valve_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool should_send_immediately_(uint16_t message_type) const
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 schedule_message_(EntityBase *entity, uint16_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)
bool send_message_smart_(EntityBase *entity, uint16_t message_type, uint8_t estimated_size, uint8_t aux_data_index=DeferredBatch::AUX_DATA_UNUSED)
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 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 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)
bool schedule_message_front_(EntityBase *entity, uint16_t message_type, uint8_t estimated_size)
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)
bool send_message_(uint32_t payload_size, uint16_t message_type, MessageEncodeFn encode_fn, const void *msg)
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_
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)
void on_bluetooth_gatt_read_request(const BluetoothGATTReadRequest &msg)
bool send_subscribe_bluetooth_connections_free_response_()
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()
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 uint16_t MESSAGE_TYPE
Definition api_pb2.h:2937
static constexpr uint16_t MESSAGE_TYPE
Definition api_pb2.h:689
static constexpr uint8_t ESTIMATED_SIZE
Definition api_pb2.h:690
static constexpr uint16_t MESSAGE_TYPE
Definition api_pb2.h:3077
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:880
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.
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(EntityBase *entity, uint16_t message_type, uint8_t estimated_size, uint8_t aux_data_index=AUX_DATA_UNUSED)
void add_item_front(EntityBase *entity, uint16_t message_type, uint8_t estimated_size)
uint32_t payload_size()