mirror of
https://github.com/esphome/esphome.git
synced 2025-10-23 20:23:50 +01:00
[ruff] Enable RET and fix all violations
This commit is contained in:
@@ -539,8 +539,7 @@ class BoolType(TypeInfo):
|
||||
wire_type = WireType.VARINT # Uses wire type 0
|
||||
|
||||
def dump(self, name: str) -> str:
|
||||
o = f"out.append(YESNO({name}));"
|
||||
return o
|
||||
return f"out.append(YESNO({name}));"
|
||||
|
||||
def get_size_calculation(self, name: str, force: bool = False) -> str:
|
||||
return self._get_simple_size_calculation(name, force, "add_bool_field")
|
||||
@@ -680,8 +679,7 @@ class MessageType(TypeInfo):
|
||||
return f"case {self.number}: value.decode_to_message(this->{self.field_name}); break;"
|
||||
|
||||
def dump(self, name: str) -> str:
|
||||
o = f"{name}.dump_to(out);"
|
||||
return o
|
||||
return f"{name}.dump_to(out);"
|
||||
|
||||
@property
|
||||
def dump_content(self) -> str:
|
||||
@@ -829,8 +827,7 @@ class FixedArrayBytesType(TypeInfo):
|
||||
return f"buffer.encode_bytes({self.number}, this->{self.field_name}, this->{self.field_name}_len);"
|
||||
|
||||
def dump(self, name: str) -> str:
|
||||
o = f"out.append(format_hex_pretty({name}, {name}_len));"
|
||||
return o
|
||||
return f"out.append(format_hex_pretty({name}, {name}_len));"
|
||||
|
||||
@property
|
||||
def dump_content(self) -> str:
|
||||
@@ -847,13 +844,12 @@ class FixedArrayBytesType(TypeInfo):
|
||||
if force:
|
||||
# For repeated fields, always calculate size
|
||||
return f"total_size += {field_id_size} + ProtoSize::varint(static_cast<uint32_t>({length_field})) + {length_field};"
|
||||
else:
|
||||
# For non-repeated fields, skip if length is 0 (matching encode_string behavior)
|
||||
return (
|
||||
f"if ({length_field} != 0) {{\n"
|
||||
f" total_size += {field_id_size} + ProtoSize::varint(static_cast<uint32_t>({length_field})) + {length_field};\n"
|
||||
f"}}"
|
||||
)
|
||||
# For non-repeated fields, skip if length is 0 (matching encode_string behavior)
|
||||
return (
|
||||
f"if ({length_field} != 0) {{\n"
|
||||
f" total_size += {field_id_size} + ProtoSize::varint(static_cast<uint32_t>({length_field})) + {length_field};\n"
|
||||
f"}}"
|
||||
)
|
||||
|
||||
def get_estimated_size(self) -> int:
|
||||
# Estimate based on typical BLE advertisement size
|
||||
@@ -908,8 +904,7 @@ class EnumType(TypeInfo):
|
||||
return f"buffer.{self.encode_func}({self.number}, static_cast<uint32_t>(this->{self.field_name}));"
|
||||
|
||||
def dump(self, name: str) -> str:
|
||||
o = f"out.append(proto_enum_to_string<{self.cpp_type}>({name}));"
|
||||
return o
|
||||
return f"out.append(proto_enum_to_string<{self.cpp_type}>({name}));"
|
||||
|
||||
def dump_field_value(self, value: str) -> str:
|
||||
# Enums need explicit cast for the template
|
||||
@@ -1078,13 +1073,12 @@ class FixedArrayRepeatedType(TypeInfo):
|
||||
def encode_element(element: str) -> str:
|
||||
if isinstance(self._ti, EnumType):
|
||||
return f"buffer.{self._ti.encode_func}({self.number}, static_cast<uint32_t>({element}), true);"
|
||||
else:
|
||||
return f"buffer.{self._ti.encode_func}({self.number}, {element}, true);"
|
||||
return f"buffer.{self._ti.encode_func}({self.number}, {element}, true);"
|
||||
|
||||
# Unroll small arrays for efficiency
|
||||
if self.array_size == 1:
|
||||
return encode_element(f"this->{self.field_name}[0]")
|
||||
elif self.array_size == 2:
|
||||
if self.array_size == 2:
|
||||
return (
|
||||
encode_element(f"this->{self.field_name}[0]")
|
||||
+ "\n "
|
||||
@@ -1240,8 +1234,9 @@ class RepeatedTypeInfo(TypeInfo):
|
||||
if isinstance(self._ti, MessageType):
|
||||
# For repeated messages, use the dedicated helper that handles iteration internally
|
||||
field_id_size = self._ti.calculate_field_id_size()
|
||||
o = f"ProtoSize::add_repeated_message(total_size, {field_id_size}, {name});"
|
||||
return o
|
||||
return (
|
||||
f"ProtoSize::add_repeated_message(total_size, {field_id_size}, {name});"
|
||||
)
|
||||
|
||||
# For other repeated types, use the underlying type's size calculation with force=True
|
||||
o = f"if (!{name}.empty()) {{\n"
|
||||
|
@@ -444,8 +444,7 @@ def get_str_path_schema(strPath):
|
||||
if len(parts) > 2:
|
||||
parts[0] += "." + parts[1]
|
||||
parts[1] = parts[2]
|
||||
s1 = output.get(parts[0], {}).get(S_SCHEMAS, {}).get(parts[1], {})
|
||||
return s1
|
||||
return output.get(parts[0], {}).get(S_SCHEMAS, {}).get(parts[1], {})
|
||||
|
||||
|
||||
def pop_str_path_schema(strPath):
|
||||
|
@@ -42,12 +42,11 @@ CONFIG_NEWLIB_LIBC=y
|
||||
|
||||
def extract_defines(command):
|
||||
define_pattern = re.compile(r"-D\s*([^\s]+)")
|
||||
defines = [
|
||||
return [
|
||||
match
|
||||
for match in define_pattern.findall(command)
|
||||
if match not in ("_ASMLANGUAGE")
|
||||
]
|
||||
return defines
|
||||
|
||||
def find_cxx_path(commands):
|
||||
for entry in commands:
|
||||
@@ -56,6 +55,7 @@ CONFIG_NEWLIB_LIBC=y
|
||||
if not cxx_path.endswith("++"):
|
||||
continue
|
||||
return cxx_path
|
||||
return None
|
||||
|
||||
def get_builtin_include_paths(compiler):
|
||||
result = subprocess.run(
|
||||
@@ -83,11 +83,10 @@ CONFIG_NEWLIB_LIBC=y
|
||||
flag_pattern = re.compile(
|
||||
r"(-O[0-3s]|-g|-std=[^\s]+|-Wall|-Wextra|-Werror|--[^\s]+|-f[^\s]+|-m[^\s]+|-imacros\s*[^\s]+)"
|
||||
)
|
||||
flags = [
|
||||
return [
|
||||
match.replace("-imacros ", "-imacros")
|
||||
for match in flag_pattern.findall(command)
|
||||
]
|
||||
return flags
|
||||
|
||||
def transform_to_idedata_format(compile_commands):
|
||||
cxx_path = find_cxx_path(compile_commands)
|
||||
|
Reference in New Issue
Block a user