1
0
mirror of https://github.com/esphome/esphome.git synced 2025-06-18 14:25:48 +01:00

preprocess out proto_enum_to_string if not needed ()

This commit is contained in:
Jesse Hills
2022-11-30 08:30:00 +13:00
committed by GitHub
parent 8414bb9a7a
commit eb664b99ba
2 changed files with 45 additions and 1 deletions
esphome/components/api
script/api_protobuf

@ -546,7 +546,8 @@ def build_enum_type(desc):
out += f" {v.name} = {v.number},\n"
out += "};\n"
cpp = f"template<> const char *proto_enum_to_string<enums::{name}>(enums::{name} value) {{\n"
cpp = f"#ifdef HAS_PROTO_MESSAGE_DUMP\n"
cpp += f"template<> const char *proto_enum_to_string<enums::{name}>(enums::{name} value) {{\n"
cpp += f" switch (value) {{\n"
for v in desc.value:
cpp += f" case enums::{v.name}:\n"
@ -555,6 +556,7 @@ def build_enum_type(desc):
cpp += f' return "UNKNOWN";\n'
cpp += f" }}\n"
cpp += f"}}\n"
cpp += f"#endif\n"
return out, cpp