diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 8844aa1e1a..beccf91d27 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -137,7 +137,6 @@ void APIConnection::loop() { // bool done = 3; bool done = this->image_reader_.available() == to_send; buffer.encode_bool(3, done); - this->set_nodelay(false); bool success = this->send_buffer(buffer, 44); if (success) { @@ -558,8 +557,6 @@ bool APIConnection::send_log_message(int level, const char *tag, const char *lin if (this->log_subscription_ < level) return false; - this->set_nodelay(false); - // Send raw so that we don't copy too much auto buffer = this->create_buffer(); // LogLevel level = 1; diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index f9c7ffa28d..3e91ead52c 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -138,12 +138,6 @@ class APIConnection : public APIServerConnection { void on_timeout_(uint32_t time); void on_data_(uint8_t *buf, size_t len); void parse_recv_buffer_(); - void set_nodelay(bool nodelay) override { - if (nodelay == this->current_nodelay_) - return; - this->client_->setNoDelay(nodelay); - this->current_nodelay_ = nodelay; - } enum class ConnectionState { WAITING_FOR_HELLO, diff --git a/esphome/components/api/api_pb2_service.cpp b/esphome/components/api/api_pb2_service.cpp index ea6b647c72..06345296a7 100644 --- a/esphome/components/api/api_pb2_service.cpp +++ b/esphome/components/api/api_pb2_service.cpp @@ -10,69 +10,57 @@ static const char *TAG = "api.service"; bool APIServerConnectionBase::send_hello_response(const HelloResponse &msg) { ESP_LOGVV(TAG, "send_hello_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 2); } bool APIServerConnectionBase::send_connect_response(const ConnectResponse &msg) { ESP_LOGVV(TAG, "send_connect_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 4); } bool APIServerConnectionBase::send_disconnect_request(const DisconnectRequest &msg) { ESP_LOGVV(TAG, "send_disconnect_request: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 5); } bool APIServerConnectionBase::send_disconnect_response(const DisconnectResponse &msg) { ESP_LOGVV(TAG, "send_disconnect_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 6); } bool APIServerConnectionBase::send_ping_request(const PingRequest &msg) { ESP_LOGVV(TAG, "send_ping_request: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 7); } bool APIServerConnectionBase::send_ping_response(const PingResponse &msg) { ESP_LOGVV(TAG, "send_ping_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 8); } bool APIServerConnectionBase::send_device_info_response(const DeviceInfoResponse &msg) { ESP_LOGVV(TAG, "send_device_info_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 10); } bool APIServerConnectionBase::send_list_entities_done_response(const ListEntitiesDoneResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_done_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 19); } #ifdef USE_BINARY_SENSOR bool APIServerConnectionBase::send_list_entities_binary_sensor_response(const ListEntitiesBinarySensorResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_binary_sensor_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 12); } #endif #ifdef USE_BINARY_SENSOR bool APIServerConnectionBase::send_binary_sensor_state_response(const BinarySensorStateResponse &msg) { ESP_LOGVV(TAG, "send_binary_sensor_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 21); } #endif #ifdef USE_COVER bool APIServerConnectionBase::send_list_entities_cover_response(const ListEntitiesCoverResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_cover_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 13); } #endif #ifdef USE_COVER bool APIServerConnectionBase::send_cover_state_response(const CoverStateResponse &msg) { ESP_LOGVV(TAG, "send_cover_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 22); } #endif @@ -81,14 +69,12 @@ bool APIServerConnectionBase::send_cover_state_response(const CoverStateResponse #ifdef USE_FAN bool APIServerConnectionBase::send_list_entities_fan_response(const ListEntitiesFanResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_fan_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 14); } #endif #ifdef USE_FAN bool APIServerConnectionBase::send_fan_state_response(const FanStateResponse &msg) { ESP_LOGVV(TAG, "send_fan_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 23); } #endif @@ -97,14 +83,12 @@ bool APIServerConnectionBase::send_fan_state_response(const FanStateResponse &ms #ifdef USE_LIGHT bool APIServerConnectionBase::send_list_entities_light_response(const ListEntitiesLightResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_light_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 15); } #endif #ifdef USE_LIGHT bool APIServerConnectionBase::send_light_state_response(const LightStateResponse &msg) { ESP_LOGVV(TAG, "send_light_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 24); } #endif @@ -113,28 +97,24 @@ bool APIServerConnectionBase::send_light_state_response(const LightStateResponse #ifdef USE_SENSOR bool APIServerConnectionBase::send_list_entities_sensor_response(const ListEntitiesSensorResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_sensor_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 16); } #endif #ifdef USE_SENSOR bool APIServerConnectionBase::send_sensor_state_response(const SensorStateResponse &msg) { ESP_LOGVV(TAG, "send_sensor_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 25); } #endif #ifdef USE_SWITCH bool APIServerConnectionBase::send_list_entities_switch_response(const ListEntitiesSwitchResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_switch_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 17); } #endif #ifdef USE_SWITCH bool APIServerConnectionBase::send_switch_state_response(const SwitchStateResponse &msg) { ESP_LOGVV(TAG, "send_switch_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 26); } #endif @@ -143,58 +123,48 @@ bool APIServerConnectionBase::send_switch_state_response(const SwitchStateRespon #ifdef USE_TEXT_SENSOR bool APIServerConnectionBase::send_list_entities_text_sensor_response(const ListEntitiesTextSensorResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_text_sensor_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 18); } #endif #ifdef USE_TEXT_SENSOR bool APIServerConnectionBase::send_text_sensor_state_response(const TextSensorStateResponse &msg) { ESP_LOGVV(TAG, "send_text_sensor_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 27); } #endif bool APIServerConnectionBase::send_subscribe_logs_response(const SubscribeLogsResponse &msg) { - this->set_nodelay(false); return this->send_message_(msg, 29); } bool APIServerConnectionBase::send_homeassistant_service_response(const HomeassistantServiceResponse &msg) { ESP_LOGVV(TAG, "send_homeassistant_service_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 35); } bool APIServerConnectionBase::send_subscribe_home_assistant_state_response( const SubscribeHomeAssistantStateResponse &msg) { ESP_LOGVV(TAG, "send_subscribe_home_assistant_state_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 39); } bool APIServerConnectionBase::send_get_time_request(const GetTimeRequest &msg) { ESP_LOGVV(TAG, "send_get_time_request: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 36); } bool APIServerConnectionBase::send_get_time_response(const GetTimeResponse &msg) { ESP_LOGVV(TAG, "send_get_time_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 37); } bool APIServerConnectionBase::send_list_entities_services_response(const ListEntitiesServicesResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_services_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 41); } #ifdef USE_ESP32_CAMERA bool APIServerConnectionBase::send_list_entities_camera_response(const ListEntitiesCameraResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_camera_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 43); } #endif #ifdef USE_ESP32_CAMERA bool APIServerConnectionBase::send_camera_image_response(const CameraImageResponse &msg) { ESP_LOGVV(TAG, "send_camera_image_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 44); } #endif @@ -203,14 +173,12 @@ bool APIServerConnectionBase::send_camera_image_response(const CameraImageRespon #ifdef USE_CLIMATE bool APIServerConnectionBase::send_list_entities_climate_response(const ListEntitiesClimateResponse &msg) { ESP_LOGVV(TAG, "send_list_entities_climate_response: %s", msg.dump().c_str()); - this->set_nodelay(false); return this->send_message_(msg, 46); } #endif #ifdef USE_CLIMATE bool APIServerConnectionBase::send_climate_state_response(const ClimateStateResponse &msg) { ESP_LOGVV(TAG, "send_climate_state_response: %s", msg.dump().c_str()); - this->set_nodelay(true); return this->send_message_(msg, 47); } #endif diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index b0160bf240..f1486a2511 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -266,7 +266,6 @@ class ProtoService { virtual ProtoWriteBuffer create_buffer() = 0; virtual bool send_buffer(ProtoWriteBuffer buffer, uint32_t message_type) = 0; virtual bool read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) = 0; - virtual void set_nodelay(bool nodelay) = 0; template bool send_message_(const C &msg, uint32_t message_type) { auto buffer = this->create_buffer(); diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 2ecaec10bd..e78eff76c7 100644 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -731,7 +731,7 @@ def build_service_message_type(mt): cout += f'bool {class_name}::{func}(const {mt.name} &msg) {{\n' if log: cout += f' ESP_LOGVV(TAG, "{func}: %s", msg.dump().c_str());\n' - cout += f' this->set_nodelay({str(nodelay).lower()});\n' + # cout += f' this->set_nodelay({str(nodelay).lower()});\n' cout += f' return this->send_message_<{mt.name}>(msg, {id_});\n' cout += f'}}\n' if source in (SOURCE_BOTH, SOURCE_CLIENT):