From c4319a8b395634b24901f2ea138ee9927fa13dc6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 6 Jun 2025 01:00:57 +0100 Subject: [PATCH] remove batch --- esphome/components/api/api_connection.cpp | 15 ++++++-- esphome/components/api/api_connection.h | 45 ----------------------- 2 files changed, 12 insertions(+), 48 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 61207357a3..7197a1ff2a 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1185,9 +1185,18 @@ void APIConnection::set_camera_state(std::shared_ptr this->image_reader_.set_image(std::move(image)); } void APIConnection::send_camera_info(esp32_camera::ESP32Camera *camera) { - ListEntitiesCameraResponse msg; - msg.unique_id = get_default_unique_id("camera", camera); - this->try_send_entity_info_(static_cast(camera), msg); + // Camera doesn't need to capture extra values, so we can use a lambda that creates the message inline + this->deferred_batch_.add_item(camera, [this](EntityBase *entity) -> std::unique_ptr { + auto *cam = static_cast(entity); + auto msg = std::make_unique(); + msg->unique_id = get_default_unique_id("camera", cam); + + // Fill common entity fields + this->fill_entity_info_base_(cam, *msg); + + return msg; + }); + this->schedule_batch_(); } void APIConnection::camera_image(const CameraImageRequest &msg) { if (esp32_camera::global_esp32_camera == nullptr) diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index cf5125abb6..0d634a0acd 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -312,51 +312,6 @@ class APIConnection : public APIServerConnection { std::string get_client_combined_info() const { return this->client_combined_info_; } - /** - * Generic function for generating entity info response messages. - * This is used to reduce duplication in the try_send_*_info functions. - * - * @param entity The entity to generate info for - * @param response The response object - * @param send_response_func Function pointer to send the response - * @return True if the message was sent successfully - */ - template bool try_send_entity_info_(esphome::EntityBase *entity, ResponseT &response) { - // Set common fields that are shared by all entity types - response.key = entity->get_object_id_hash(); - response.object_id = entity->get_object_id(); - - if (entity->has_own_name()) - response.name = entity->get_name(); - - // Set common EntityBase properties - response.icon = entity->get_icon(); - response.disabled_by_default = entity->is_disabled_by_default(); - response.entity_category = static_cast(entity->get_entity_category()); - - // Add to deferred batch with a lambda that creates the message - this->deferred_batch_.add_item(entity, [response](EntityBase *) -> std::unique_ptr { - return std::make_unique(response); - }); - return this->schedule_batch_(); - } - - /** - * Generic function for sending entity state messages. - * - * @param response The state response object with key already set - * @return True if the message was sent successfully - */ - template bool try_send_entity_state(ResponseT &response) { - // Add to deferred batch with a lambda that creates the message - this->deferred_batch_.add_item( - [response]() -> std::unique_ptr { return std::make_unique(response); }); - this->schedule_batch_(); - return true; - } - - bool send_(const void *buf, size_t len, bool force); - protected: // Helper function to fill common entity fields template void fill_entity_info_base_(esphome::EntityBase *entity, ResponseT &response) {