19class ComponentIterator;
25static constexpr uint32_t KEEPALIVE_TIMEOUT_MS = 60000;
29static constexpr size_t MAX_INITIAL_PER_BATCH_LEGACY = 24;
30static constexpr size_t MAX_INITIAL_PER_BATCH = 34;
32static_assert(MAX_MESSAGES_PER_BATCH >= MAX_INITIAL_PER_BATCH,
33 "MAX_MESSAGES_PER_BATCH must be >= MAX_INITIAL_PER_BATCH");
49#ifdef USE_BINARY_SENSOR
86#ifdef USE_DATETIME_DATE
90#ifdef USE_DATETIME_TIME
94#ifdef USE_DATETIME_DATETIME
117#ifdef USE_MEDIA_PLAYER
122#ifdef USE_API_HOMEASSISTANT_SERVICES
128#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
132#ifdef USE_BLUETOOTH_PROXY
147#ifdef USE_HOMEASSISTANT_TIME
154#ifdef USE_VOICE_ASSISTANT
165#ifdef USE_ZWAVE_PROXY
170#ifdef USE_ALARM_CONTROL_PANEL
175#ifdef USE_WATER_HEATER
199#ifdef USE_API_HOMEASSISTANT_STATES
202#ifdef USE_HOMEASSISTANT_TIME
223#ifdef USE_API_HOMEASSISTANT_SERVICES
226#ifdef USE_API_HOMEASSISTANT_STATES
229#ifdef USE_API_USER_DEFINED_ACTIONS
231#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
233#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
235 const uint8_t *response_data,
size_t response_data_len);
267 shared_buf.reserve(total_size);
269 shared_buf.resize(header_padding);
274 const uint8_t header_padding = this->
helper_->frame_header_padding();
275 const uint8_t footer_size = this->
helper_->frame_footer_size();
285 return this->
helper_->get_peername_to(buf);
300#ifdef USE_BLUETOOTH_PROXY
303#ifdef USE_VOICE_ASSISTANT
311#ifdef USE_API_HOMEASSISTANT_STATES
317 uint32_t remaining_size);
340 char object_id_buf[OBJECT_ID_MAX_LEN];
350#ifdef USE_ENTITY_ICON
361#ifdef USE_VOICE_ASSISTANT
381#ifdef USE_BINARY_SENSOR
405#ifdef USE_TEXT_SENSOR
417#ifdef USE_DATETIME_DATE
421#ifdef USE_DATETIME_TIME
425#ifdef USE_DATETIME_DATETIME
448#ifdef USE_MEDIA_PLAYER
452#ifdef USE_ALARM_CONTROL_PANEL
456#ifdef USE_WATER_HEATER
465 uint32_t remaining_size);
513#ifdef USE_API_HOMEASSISTANT_STATES
564 std::vector<BatchItem>().swap(
items);
596#ifdef HAS_PROTO_MESSAGE_DUMP
624 void process_batch_multi_(std::vector<uint8_t> &shared_buf,
size_t num_items, uint8_t header_padding,
627 this->deferred_batch_.
clear();
633 uint16_t
dispatch_message_(
const DeferredBatch::BatchItem &item, uint32_t remaining_size,
bool batch_first);
635#ifdef HAS_PROTO_MESSAGE_DUMP
670 this->deferred_batch_.
add_item(entity, message_type, estimated_size, aux_data_index);
676 this->deferred_batch_.
add_item_front(entity, message_type, estimated_size);
void schedule_dump_config()
bool has_own_name() const
ESPDEPRECATED("object_id mangles names and all object_id methods are planned for removal " "(see https://github.com/esphome/backlog/issues/76). " "Now is the time to stop using object_id. If still needed, use get_object_id_to() " "which will remain available longer. get_object_id() will be removed in 2026.7.0", "2025.12.0") std uint32_t get_object_id_hash()
const StringRef & get_name() const
StringRef get_icon_ref() const
uint32_t get_device_id() const
bool is_disabled_by_default() const
EntityCategory get_entity_category() const
StringRef get_object_id_to(std::span< char, OBJECT_ID_MAX_LEN > buf) const
Get object_id with zero heap allocation For static case: returns StringRef to internal storage (buffe...
StringRef is a reference to a string owned by something else.
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
void process_batch_multi_(std::vector< uint8_t > &shared_buf, size_t num_items, uint8_t header_padding, uint8_t footer_size) __attribute__((noinline))
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)
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
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
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
void prepare_first_message_buffer(std::vector< uint8_t > &shared_buf, size_t header_padding, size_t total_size)
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)
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
bool send_fan_state(fan::Fan *fan)
void on_voice_assistant_response(const VoiceAssistantResponse &msg) override
bool check_voice_assistant_api_connection_() const
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_
bool send_message_impl(const ProtoMessage &msg, uint8_t message_type) override
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)
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)
void prepare_first_message_buffer(std::vector< uint8_t > &shared_buf, size_t payload_size)
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)
void log_client_(int level, const LogString *message)
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)
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)
bool send_update_state(update::UpdateEntity *update)
void on_alarm_control_panel_command_request(const AlarmControlPanelCommandRequest &msg) override
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)
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_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
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)
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_subscribe_bluetooth_connections_free_response_()
void on_subscribe_states_request() 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 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
bool send_device_info_response_()
static uint16_t try_send_water_heater_state(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
static uint16_t fill_and_encode_entity_state(EntityBase *entity, StateResponseProtoMessage &msg, uint8_t message_type, 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
static uint16_t encode_message_to_buffer(ProtoMessage &msg, uint8_t message_type, APIConnection *conn, uint32_t remaining_size)
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
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 fill_and_encode_entity_info(EntityBase *entity, InfoResponseProtoMessage &msg, uint8_t message_type, APIConnection *conn, uint32_t remaining_size)
static uint16_t try_send_switch_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size)
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)
bool send_message(const ProtoMessage &msg, uint8_t message_type)
static constexpr uint8_t MESSAGE_TYPE
static constexpr uint8_t MESSAGE_TYPE
static constexpr uint8_t MESSAGE_TYPE
enums::EntityCategory entity_category
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__
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 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