9#ifdef USE_API_PLAINTEXT
17#ifdef USE_ESP32_CRASH_HANDLER
20#ifdef USE_RP2040_CRASH_HANDLER
31class ComponentIterator;
37static constexpr uint32_t KEEPALIVE_TIMEOUT_MS = 60000;
41static constexpr size_t MAX_INITIAL_PER_BATCH_LEGACY = 24;
42static constexpr size_t MAX_INITIAL_PER_BATCH = 34;
44static_assert(MAX_MESSAGES_PER_BATCH >= MAX_INITIAL_PER_BATCH,
45 "MAX_MESSAGES_PER_BATCH must be >= MAX_INITIAL_PER_BATCH");
61#ifdef USE_BINARY_SENSOR
98#ifdef USE_DATETIME_DATE
102#ifdef USE_DATETIME_TIME
106#ifdef USE_DATETIME_DATETIME
129#ifdef USE_MEDIA_PLAYER
134#ifdef USE_API_HOMEASSISTANT_SERVICES
140#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
144#ifdef USE_BLUETOOTH_PROXY
160#ifdef USE_HOMEASSISTANT_TIME
167#ifdef USE_VOICE_ASSISTANT
178#ifdef USE_ZWAVE_PROXY
183#ifdef USE_ALARM_CONTROL_PANEL
188#ifdef USE_WATER_HEATER
198#ifdef USE_SERIAL_PROXY
221#ifdef USE_API_HOMEASSISTANT_STATES
224#ifdef USE_HOMEASSISTANT_TIME
244#ifdef USE_ESP32_CRASH_HANDLER
247#ifdef USE_RP2040_CRASH_HANDLER
251#ifdef USE_API_HOMEASSISTANT_SERVICES
254#ifdef USE_API_HOMEASSISTANT_STATES
257#ifdef USE_API_USER_DEFINED_ACTIONS
259#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
261#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
263 const uint8_t *response_data,
size_t response_data_len);
296 if constexpr (T::ESTIMATED_SIZE == 0) {
308 shared_buf.
reserve(total_size);
310 shared_buf.
resize(header_padding);
315 const uint8_t header_padding = this->
helper_->frame_header_padding();
316 const uint8_t footer_size = this->
helper_->frame_footer_size();
323 if (this->
helper_->can_write_without_blocking())
332 return this->
helper_->get_peername_to(buf);
349#ifdef USE_BLUETOOTH_PROXY
352#ifdef USE_VOICE_ASSISTANT
360#ifdef USE_API_HOMEASSISTANT_STATES
366 return static_cast<const T *
>(msg)->calculate_size();
381 if constexpr (T::ESTIMATED_SIZE == 0) {
427#ifdef USE_VOICE_ASSISTANT
451#ifdef USE_BINARY_SENSOR
475#ifdef USE_TEXT_SENSOR
487#ifdef USE_DATETIME_DATE
491#ifdef USE_DATETIME_TIME
495#ifdef USE_DATETIME_DATETIME
518#ifdef USE_MEDIA_PLAYER
522#ifdef USE_ALARM_CONTROL_PANEL
526#ifdef USE_WATER_HEATER
558#if defined(USE_API_NOISE) && defined(USE_API_PLAINTEXT)
560#elif defined(USE_API_NOISE)
562#elif defined(USE_API_PLAINTEXT)
563 std::unique_ptr<APIPlaintextFrameHelper>
helper_;
589#ifdef USE_API_HOMEASSISTANT_STATES
642 std::vector<BatchItem>().swap(
items);
674#ifdef HAS_PROTO_MESSAGE_DUMP
705 this->deferred_batch_.
clear();
713#ifdef HAS_PROTO_MESSAGE_DUMP
748 this->deferred_batch_.
add_item(entity, message_type, estimated_size, aux_data_index);
754 this->deferred_batch_.
add_item_front(entity, message_type, estimated_size);
void schedule_dump_config()
StringRef is a reference to a string owned by something else.
Byte buffer that skips zero-initialization on resize().
void reserve(size_t n) ESPHOME_ALWAYS_INLINE
void resize(size_t n) ESPHOME_ALWAYS_INLINE
struct esphome::api::APIConnection::APIFlags flags_
void on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg) override
void on_subscribe_bluetooth_connections_free_request() override
static uint16_t try_send_text_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_disconnect_request() override
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_serial_proxy_request(const SerialProxyRequest &msg) override
static uint16_t try_send_text_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_z_wave_proxy_request(const ZWaveProxyRequest &msg) override
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_subscribe_logs_request(const SubscribeLogsRequest &msg) override
void on_execute_service_request(const ExecuteServiceRequest &msg) override
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_date_time_command_request(const DateTimeCommandRequest &msg) override
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 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)
uint16_t client_api_version_major_
void on_switch_command_request(const SwitchCommandRequest &msg) override
static uint16_t try_send_date_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_unsubscribe_bluetooth_le_advertisements_request() override
void on_voice_assistant_announce_request(const VoiceAssistantAnnounceRequest &msg) override
void on_lock_command_request(const LockCommandRequest &msg) override
void on_bluetooth_device_request(const BluetoothDeviceRequest &msg) override
static uint16_t try_send_valve_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_z_wave_proxy_frame(const ZWaveProxyFrame &msg) override
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)
void on_time_command_request(const TimeCommandRequest &msg) override
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_subscribe_voice_assistant_request(const SubscribeVoiceAssistantRequest &msg) override
void on_serial_proxy_get_modem_pins_request(const SerialProxyGetModemPinsRequest &msg) override
bool send_fan_state(fan::Fan *fan)
void on_voice_assistant_response(const VoiceAssistantResponse &msg) override
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)
std::unique_ptr< APIFrameHelper > helper_
uint16_t client_api_version_minor_
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)
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)
void(*)(const void *, ProtoWriteBuffer &) MessageEncodeFn
uint32_t get_batch_delay_ms_() const
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)
void on_homeassistant_action_response(const HomeassistantActionResponse &msg) override
static uint16_t try_send_climate_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
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
void on_text_command_request(const TextCommandRequest &msg) override
bool send_binary_sensor_state(binary_sensor::BinarySensor *binary_sensor)
bool send_valve_state(valve::Valve *valve)
bool send_voice_assistant_get_configuration_response_(const VoiceAssistantConfigurationRequest &msg)
bool send_select_state(select::Select *select)
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_disconnect_response() override
void on_ping_response() override
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_media_player_command_request(const MediaPlayerCommandRequest &msg) override
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_serial_proxy_configure_request(const SerialProxyConfigureRequest &msg) override
void log_client_(int level, const LogString *message)
static uint16_t encode_to_buffer(uint32_t calculated_size, MessageEncodeFn encode_fn, const void *msg, APIConnection *conn, uint32_t remaining_size)
void on_hello_request(const HelloRequest &msg) override
static uint16_t try_send_alarm_control_panel_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_infrared_rf_transmit_raw_timings_request(const InfraredRFTransmitRawTimingsRequest &msg) override
void process_state_subscriptions_()
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)
bool send_message(const T &msg)
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 prepare_first_message_buffer(APIBuffer &shared_buf, size_t payload_size)
bool send_update_state(update::UpdateEntity *update)
void on_alarm_control_panel_command_request(const AlarmControlPanelCommandRequest &msg) override
bool is_marked_for_removal() const
void on_voice_assistant_audio(const VoiceAssistantAudio &msg) override
void on_bluetooth_gatt_write_descriptor_request(const BluetoothGATTWriteDescriptorRequest &msg) override
static uint16_t try_send_datetime_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static void encode_msg_noop(const void *, ProtoWriteBuffer &)
void on_fatal_error() override
bool send_ping_response_()
void on_update_command_request(const UpdateCommandRequest &msg) override
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 destroy_active_iterator_()
void log_warning_(const LogString *message, APIError err)
void on_fan_command_request(const FanCommandRequest &msg) override
static uint16_t try_send_select_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void begin_iterator_(ActiveIterator type)
std::unique_ptr< camera::CameraImageReader > image_reader_
void on_bluetooth_gatt_get_services_request(const BluetoothGATTGetServicesRequest &msg) override
void on_bluetooth_gatt_read_descriptor_request(const BluetoothGATTReadDescriptorRequest &msg) override
APIConnection(std::unique_ptr< socket::Socket > socket, APIServer *parent)
void on_serial_proxy_write_request(const SerialProxyWriteRequest &msg) override
void on_select_command_request(const SelectCommandRequest &msg) override
static uint16_t try_send_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool is_authenticated() override
static uint16_t try_send_select_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_camera_image_request(const CameraImageRequest &msg) override
bool send_date_state(datetime::DateEntity *date)
void try_send_camera_image_()
void on_light_command_request(const LightCommandRequest &msg) override
void on_subscribe_home_assistant_states_request() override
bool is_connection_setup() override
void on_bluetooth_gatt_notify_request(const BluetoothGATTNotifyRequest &msg) override
void on_bluetooth_scanner_set_mode_request(const BluetoothScannerSetModeRequest &msg) override
bool send_number_state(number::Number *number)
void on_voice_assistant_configuration_request(const VoiceAssistantConfigurationRequest &msg) override
void on_list_entities_request() override
void on_voice_assistant_timer_event_response(const VoiceAssistantTimerEventResponse &msg) override
std::unique_ptr< APINoiseFrameHelper > helper_
void on_no_setup_connection() override
bool schedule_message_front_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size)
void on_voice_assistant_event_response(const VoiceAssistantEventResponse &msg) override
bool send_hello_response_(const HelloRequest &msg)
void on_cover_command_request(const CoverCommandRequest &msg) override
void send_homeassistant_action(const HomeassistantActionRequest &call)
bool send_light_state(light::LightState *light)
void on_bluetooth_set_connection_params_request(const BluetoothSetConnectionParamsRequest &msg) override
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
DeferredBatch deferred_batch_
void on_home_assistant_state_response(const HomeAssistantStateResponse &msg) override
static uint16_t try_send_time_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
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_get_time_response(const GetTimeResponse &value) override
void on_subscribe_bluetooth_le_advertisements_request(const SubscribeBluetoothLEAdvertisementsRequest &msg) override
void on_water_heater_command_request(const WaterHeaterCommandRequest &msg) override
void on_button_command_request(const ButtonCommandRequest &msg) override
void on_bluetooth_gatt_write_request(const BluetoothGATTWriteRequest &msg) override
bool send_message_(uint32_t payload_size, uint8_t message_type, MessageEncodeFn encode_fn, const void *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_subscribe_states_request() override
void on_serial_proxy_set_modem_pins_request(const SerialProxySetModemPinsRequest &msg) override
bool send_datetime_state(datetime::DateTimeEntity *datetime)
void on_voice_assistant_set_configuration(const VoiceAssistantSetConfiguration &msg) override
void on_subscribe_homeassistant_services_request() override
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 complete_authentication_()
void on_valve_command_request(const ValveCommandRequest &msg) override
void on_date_command_request(const DateCommandRequest &msg) override
bool send_text_state(text::Text *text)
static uint16_t try_send_date_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_number_command_request(const NumberCommandRequest &msg) override
static uint16_t fill_and_encode_entity_info(EntityBase *entity, T &msg, APIConnection *conn, uint32_t remaining_size)
bool send_device_info_response_()
static uint16_t try_send_water_heater_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_time_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
void on_ping_request() override
size_t get_max_batch_size_() const
bool try_send_log_message(int level, const char *tag, const char *line, size_t message_len)
void on_bluetooth_gatt_read_request(const BluetoothGATTReadRequest &msg) override
void process_iterator_batch_(ComponentIterator &iterator)
ActiveIterator active_iterator_
static uint16_t try_send_cover_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
bool send_disconnect_response_()
bool send_list_info_done()
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)
bool send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) override
void on_climate_command_request(const ClimateCommandRequest &msg) override
bool send_climate_state(climate::Climate *climate)
bool try_to_clear_buffer(bool log_out_of_space)
bool send_cover_state(cover::Cover *cover)
void on_device_info_request() override
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 __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)
static constexpr uint8_t MESSAGE_TYPE
static constexpr uint8_t MESSAGE_TYPE
static constexpr uint8_t ESTIMATED_SIZE
static constexpr uint8_t MESSAGE_TYPE
Base class for all binary_sensor-type classes.
ClimateDevice - This is the base class for all climate integrations.
Base class for all cover devices.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Base class for all locks.
Base-class for all numbers.
Base-class for all selects.
Base-class for all sensors.
Base class for all switches.
Base-class for all text inputs.
Base class for all valve devices.
struct @65::@66 __attribute__
void proto_encode_msg(const void *msg, ProtoWriteBuffer &buf)
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.
Providing packet encoding functions for exchanging data with a remote host.
Application App
Global storage of Application pointer - only one Application can exist.
uint8_t batch_first_message
uint8_t state_subscription
uint8_t should_try_send_immediately
uint8_t service_call_subscription
std::vector< BatchItem > items
uint32_t batch_start_time
void push_item(const BatchItem &item)
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)
static constexpr uint8_t AUX_DATA_UNUSED
void add_item(EntityBase *entity, uint8_t message_type, uint8_t estimated_size, uint8_t aux_data_index=AUX_DATA_UNUSED)
ListEntitiesIterator list_entities
InitialStateIterator initial_state