mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	Merge branch 'integration' into memory_api
This commit is contained in:
		| @@ -116,8 +116,7 @@ void APIConnection::start() { | |||||||
|  |  | ||||||
|   APIError err = this->helper_->init(); |   APIError err = this->helper_->init(); | ||||||
|   if (err != APIError::OK) { |   if (err != APIError::OK) { | ||||||
|     on_fatal_error(); |     this->fatal_error_with_log_(LOG_STR("Helper init failed"), err); | ||||||
|     this->log_warning_(LOG_STR("Helper init failed"), err); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->client_info_.peername = helper_->getpeername(); |   this->client_info_.peername = helper_->getpeername(); | ||||||
| @@ -147,8 +146,7 @@ void APIConnection::loop() { | |||||||
|  |  | ||||||
|   APIError err = this->helper_->loop(); |   APIError err = this->helper_->loop(); | ||||||
|   if (err != APIError::OK) { |   if (err != APIError::OK) { | ||||||
|     on_fatal_error(); |     this->fatal_error_with_socket_log_(err); | ||||||
|     this->log_socket_operation_failed_(err); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -163,8 +161,7 @@ void APIConnection::loop() { | |||||||
|         // No more data available |         // No more data available | ||||||
|         break; |         break; | ||||||
|       } else if (err != APIError::OK) { |       } else if (err != APIError::OK) { | ||||||
|         on_fatal_error(); |         this->fatal_error_with_log_(LOG_STR("Reading failed"), err); | ||||||
|         this->log_warning_(LOG_STR("Reading failed"), err); |  | ||||||
|         return; |         return; | ||||||
|       } else { |       } else { | ||||||
|         this->last_traffic_ = now; |         this->last_traffic_ = now; | ||||||
| @@ -1580,8 +1577,7 @@ bool APIConnection::try_to_clear_buffer(bool log_out_of_space) { | |||||||
|   delay(0); |   delay(0); | ||||||
|   APIError err = this->helper_->loop(); |   APIError err = this->helper_->loop(); | ||||||
|   if (err != APIError::OK) { |   if (err != APIError::OK) { | ||||||
|     on_fatal_error(); |     this->fatal_error_with_socket_log_(err); | ||||||
|     this->log_socket_operation_failed_(err); |  | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|   if (this->helper_->can_write_without_blocking()) |   if (this->helper_->can_write_without_blocking()) | ||||||
| @@ -1600,8 +1596,7 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) { | |||||||
|   if (err == APIError::WOULD_BLOCK) |   if (err == APIError::WOULD_BLOCK) | ||||||
|     return false; |     return false; | ||||||
|   if (err != APIError::OK) { |   if (err != APIError::OK) { | ||||||
|     on_fatal_error(); |     this->fatal_error_with_log_(LOG_STR("Packet write failed"), err); | ||||||
|     this->log_warning_(LOG_STR("Packet write failed"), err); |  | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|   // Do not set last_traffic_ on send |   // Do not set last_traffic_ on send | ||||||
| @@ -1787,8 +1782,7 @@ void APIConnection::process_batch_() { | |||||||
|   APIError err = this->helper_->write_protobuf_packets(ProtoWriteBuffer{&shared_buf}, |   APIError err = this->helper_->write_protobuf_packets(ProtoWriteBuffer{&shared_buf}, | ||||||
|                                                        std::span<const PacketInfo>(packet_info, packet_count)); |                                                        std::span<const PacketInfo>(packet_info, packet_count)); | ||||||
|   if (err != APIError::OK && err != APIError::WOULD_BLOCK) { |   if (err != APIError::OK && err != APIError::WOULD_BLOCK) { | ||||||
|     on_fatal_error(); |     this->fatal_error_with_log_(LOG_STR("Batch write failed"), err); | ||||||
|     this->log_warning_(LOG_STR("Batch write failed"), err); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
| #ifdef HAS_PROTO_MESSAGE_DUMP | #ifdef HAS_PROTO_MESSAGE_DUMP | ||||||
| @@ -1871,9 +1865,5 @@ void APIConnection::log_warning_(const LogString *message, APIError err) { | |||||||
|            LOG_STR_ARG(message), LOG_STR_ARG(api_error_to_logstr(err)), errno); |            LOG_STR_ARG(message), LOG_STR_ARG(api_error_to_logstr(err)), errno); | ||||||
| } | } | ||||||
|  |  | ||||||
| void APIConnection::log_socket_operation_failed_(APIError err) { |  | ||||||
|   this->log_warning_(LOG_STR("Socket operation failed"), err); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| }  // namespace esphome::api | }  // namespace esphome::api | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -732,8 +732,14 @@ class APIConnection final : public APIServerConnection { | |||||||
|  |  | ||||||
|   // Helper function to log API errors with errno |   // Helper function to log API errors with errno | ||||||
|   void log_warning_(const LogString *message, APIError err); |   void log_warning_(const LogString *message, APIError err); | ||||||
|   // Specific helper for duplicated error message |   // Helper to handle fatal errors with logging | ||||||
|   void log_socket_operation_failed_(APIError err); |   inline void fatal_error_with_log_(const LogString *message, APIError err) { | ||||||
|  |     this->on_fatal_error(); | ||||||
|  |     this->log_warning_(message, err); | ||||||
|  |   } | ||||||
|  |   inline void fatal_error_with_socket_log_(APIError err) { | ||||||
|  |     this->fatal_error_with_log_(LOG_STR("Socket operation failed"), err); | ||||||
|  |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| }  // namespace esphome::api | }  // namespace esphome::api | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user