From 712de7997306185530f641dd1b6f9599c438c4ba Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 30 Jul 2025 22:06:31 -1000 Subject: [PATCH] tidy --- esphome/components/api/api_pb2.cpp | 12 ++++++------ script/api_protobuf/api_protobuf.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index ac0808f2c3..b797aa3ca6 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -1888,7 +1888,7 @@ bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarI return true; } void BluetoothGATTDescriptor::encode(ProtoWriteBuffer buffer) const { - if (!(this->uuid[0] == 0 && this->uuid[1] == 0)) { + if (this->uuid[0] != 0 || this->uuid[1] != 0) { buffer.encode_uint64(1, this->uuid[0], true); buffer.encode_uint64(1, this->uuid[1], true); } @@ -1897,7 +1897,7 @@ void BluetoothGATTDescriptor::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->uuid32); } void BluetoothGATTDescriptor::calculate_size(ProtoSize &size) const { - if (!(this->uuid[0] == 0 && this->uuid[1] == 0)) { + if (this->uuid[0] != 0 || this->uuid[1] != 0) { size.add_uint64_force(1, this->uuid[0]); size.add_uint64_force(1, this->uuid[1]); } @@ -1906,7 +1906,7 @@ void BluetoothGATTDescriptor::calculate_size(ProtoSize &size) const { size.add_uint32(1, this->uuid32); } void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const { - if (!(this->uuid[0] == 0 && this->uuid[1] == 0)) { + if (this->uuid[0] != 0 || this->uuid[1] != 0) { buffer.encode_uint64(1, this->uuid[0], true); buffer.encode_uint64(1, this->uuid[1], true); } @@ -1919,7 +1919,7 @@ void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(6, this->uuid32); } void BluetoothGATTCharacteristic::calculate_size(ProtoSize &size) const { - if (!(this->uuid[0] == 0 && this->uuid[1] == 0)) { + if (this->uuid[0] != 0 || this->uuid[1] != 0) { size.add_uint64_force(1, this->uuid[0]); size.add_uint64_force(1, this->uuid[1]); } @@ -1930,7 +1930,7 @@ void BluetoothGATTCharacteristic::calculate_size(ProtoSize &size) const { size.add_uint32(1, this->uuid32); } void BluetoothGATTService::encode(ProtoWriteBuffer buffer) const { - if (!(this->uuid[0] == 0 && this->uuid[1] == 0)) { + if (this->uuid[0] != 0 || this->uuid[1] != 0) { buffer.encode_uint64(1, this->uuid[0], true); buffer.encode_uint64(1, this->uuid[1], true); } @@ -1942,7 +1942,7 @@ void BluetoothGATTService::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(5, this->uuid32); } void BluetoothGATTService::calculate_size(ProtoSize &size) const { - if (!(this->uuid[0] == 0 && this->uuid[1] == 0)) { + if (this->uuid[0] != 0 || this->uuid[1] != 0) { size.add_uint64_force(1, this->uuid[0]); size.add_uint64_force(1, this->uuid[1]); } diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 464d3e047e..03f8d0f8bc 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -1120,15 +1120,15 @@ class FixedArrayRepeatedType(TypeInfo): # If skip_zero is enabled, wrap encoding in a zero check if self.skip_zero: - # Build the condition to check if all elements are zero - zero_checks = " && ".join( - [f"this->{self.field_name}[{i}] == 0" for i in range(self.array_size)] + # Build the condition to check if at least one element is non-zero + non_zero_checks = " || ".join( + [f"this->{self.field_name}[{i}] != 0" for i in range(self.array_size)] ) encode_lines = [ f" {encode_element(f'this->{self.field_name}[{i}]')}" for i in range(self.array_size) ] - return f"if (!({zero_checks})) {{\n" + "\n".join(encode_lines) + "\n}" + return f"if ({non_zero_checks}) {{\n" + "\n".join(encode_lines) + "\n}" # Unroll small arrays for efficiency if self.array_size == 1: @@ -1160,15 +1160,15 @@ class FixedArrayRepeatedType(TypeInfo): def get_size_calculation(self, name: str, force: bool = False) -> str: # If skip_zero is enabled, wrap size calculation in a zero check if self.skip_zero: - # Build the condition to check if all elements are zero - zero_checks = " && ".join( - [f"{name}[{i}] == 0" for i in range(self.array_size)] + # Build the condition to check if at least one element is non-zero + non_zero_checks = " || ".join( + [f"{name}[{i}] != 0" for i in range(self.array_size)] ) size_lines = [ f" {self._ti.get_size_calculation(f'{name}[{i}]', True)}" for i in range(self.array_size) ] - return f"if (!({zero_checks})) {{\n" + "\n".join(size_lines) + "\n}" + return f"if ({non_zero_checks}) {{\n" + "\n".join(size_lines) + "\n}" # For fixed arrays, we always encode all elements