From eb664b99badc3643bd6379fea8a3dad0baf71e89 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Wed, 30 Nov 2022 08:30:00 +1300 Subject: [PATCH] preprocess out proto_enum_to_string if not needed (#4119) --- esphome/components/api/api_pb2.cpp | 42 +++++++++++++++++++++++++++++ script/api_protobuf/api_protobuf.py | 4 ++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index 1401cc00f..f108d38e8 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -19,6 +19,8 @@ template<> const char *proto_enum_to_string(enums::Entity return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::LegacyCoverState value) { switch (value) { case enums::LEGACY_COVER_STATE_OPEN: @@ -29,6 +31,8 @@ template<> const char *proto_enum_to_string(enums::Lega return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::CoverOperation value) { switch (value) { case enums::COVER_OPERATION_IDLE: @@ -41,6 +45,8 @@ template<> const char *proto_enum_to_string(enums::CoverO return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::LegacyCoverCommand value) { switch (value) { case enums::LEGACY_COVER_COMMAND_OPEN: @@ -53,6 +59,8 @@ template<> const char *proto_enum_to_string(enums::Le return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::FanSpeed value) { switch (value) { case enums::FAN_SPEED_LOW: @@ -65,6 +73,8 @@ template<> const char *proto_enum_to_string(enums::FanSpeed val return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::FanDirection value) { switch (value) { case enums::FAN_DIRECTION_FORWARD: @@ -75,6 +85,8 @@ template<> const char *proto_enum_to_string(enums::FanDirec return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::ColorMode value) { switch (value) { case enums::COLOR_MODE_UNKNOWN: @@ -101,6 +113,8 @@ template<> const char *proto_enum_to_string(enums::ColorMode v return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::SensorStateClass value) { switch (value) { case enums::STATE_CLASS_NONE: @@ -115,6 +129,8 @@ template<> const char *proto_enum_to_string(enums::Sens return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::SensorLastResetType value) { switch (value) { case enums::LAST_RESET_NONE: @@ -127,6 +143,8 @@ template<> const char *proto_enum_to_string(enums::S return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::LogLevel value) { switch (value) { case enums::LOG_LEVEL_NONE: @@ -149,6 +167,8 @@ template<> const char *proto_enum_to_string(enums::LogLevel val return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::ServiceArgType value) { switch (value) { case enums::SERVICE_ARG_TYPE_BOOL: @@ -171,6 +191,8 @@ template<> const char *proto_enum_to_string(enums::Servic return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::ClimateMode value) { switch (value) { case enums::CLIMATE_MODE_OFF: @@ -191,6 +213,8 @@ template<> const char *proto_enum_to_string(enums::ClimateMo return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::ClimateFanMode value) { switch (value) { case enums::CLIMATE_FAN_ON: @@ -215,6 +239,8 @@ template<> const char *proto_enum_to_string(enums::Climat return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::ClimateSwingMode value) { switch (value) { case enums::CLIMATE_SWING_OFF: @@ -229,6 +255,8 @@ template<> const char *proto_enum_to_string(enums::Clim return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::ClimateAction value) { switch (value) { case enums::CLIMATE_ACTION_OFF: @@ -247,6 +275,8 @@ template<> const char *proto_enum_to_string(enums::Climate return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::ClimatePreset value) { switch (value) { case enums::CLIMATE_PRESET_NONE: @@ -269,6 +299,8 @@ template<> const char *proto_enum_to_string(enums::Climate return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::NumberMode value) { switch (value) { case enums::NUMBER_MODE_AUTO: @@ -281,6 +313,8 @@ template<> const char *proto_enum_to_string(enums::NumberMode return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::LockState value) { switch (value) { case enums::LOCK_STATE_NONE: @@ -299,6 +333,8 @@ template<> const char *proto_enum_to_string(enums::LockState v return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::LockCommand value) { switch (value) { case enums::LOCK_UNLOCK: @@ -311,6 +347,8 @@ template<> const char *proto_enum_to_string(enums::LockComma return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::MediaPlayerState value) { switch (value) { case enums::MEDIA_PLAYER_STATE_NONE: @@ -325,6 +363,8 @@ template<> const char *proto_enum_to_string(enums::Medi return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::MediaPlayerCommand value) { switch (value) { case enums::MEDIA_PLAYER_COMMAND_PLAY: @@ -341,6 +381,8 @@ template<> const char *proto_enum_to_string(enums::Me return "UNKNOWN"; } } +#endif +#ifdef HAS_PROTO_MESSAGE_DUMP template<> const char *proto_enum_to_string(enums::BluetoothDeviceRequestType value) { switch (value) { diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index ea57b0ddc..dba6f47d4 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -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} value) {{\n" + cpp = f"#ifdef HAS_PROTO_MESSAGE_DUMP\n" + cpp += f"template<> const char *proto_enum_to_string(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