1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 05:12:21 +01:00
This commit is contained in:
J. Nick Koston
2025-07-30 22:06:31 -10:00
parent 37911e84f2
commit 712de79973
2 changed files with 14 additions and 14 deletions

View File

@@ -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