From cc1abfcdb364e849c95e225ffdbf7a20b9a4718c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 18 Jul 2025 09:24:24 -1000 Subject: [PATCH] fixed unref enum tracking --- esphome/components/api/api.proto | 3 +++ esphome/components/api/api_pb2.h | 9 +++++++++ esphome/components/api/api_pb2_dump.cpp | 23 +++++++++++++++++++++++ script/api_protobuf/api_protobuf.py | 17 +++-------------- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/esphome/components/api/api.proto b/esphome/components/api/api.proto index a77309a2a8..546c498ff3 100644 --- a/esphome/components/api/api.proto +++ b/esphome/components/api/api.proto @@ -422,7 +422,9 @@ message ListEntitiesFanResponse { repeated string supported_preset_modes = 12; uint32 device_id = 13 [(field_ifdef) = "USE_DEVICES"]; } +// Deprecated in API version 1.6 - only used in deprecated fields enum FanSpeed { + option deprecated = true; FAN_SPEED_LOW = 0; FAN_SPEED_MEDIUM = 1; FAN_SPEED_HIGH = 2; @@ -585,6 +587,7 @@ enum SensorStateClass { // Deprecated in API version 1.5 enum SensorLastResetType { + option deprecated = true; LAST_RESET_NONE = 0; LAST_RESET_NEVER = 1; LAST_RESET_AUTO = 2; diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index 9788545e33..1c143818e4 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -185,6 +185,15 @@ enum BluetoothScannerMode : uint32_t { BLUETOOTH_SCANNER_MODE_ACTIVE = 1, }; #endif +enum VoiceAssistantSubscribeFlag : uint32_t { + VOICE_ASSISTANT_SUBSCRIBE_NONE = 0, + VOICE_ASSISTANT_SUBSCRIBE_API_AUDIO = 1, +}; +enum VoiceAssistantRequestFlag : uint32_t { + VOICE_ASSISTANT_REQUEST_NONE = 0, + VOICE_ASSISTANT_REQUEST_USE_VAD = 1, + VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD = 2, +}; #ifdef USE_VOICE_ASSISTANT enum VoiceAssistantEvent : uint32_t { VOICE_ASSISTANT_ERROR = 0, diff --git a/esphome/components/api/api_pb2_dump.cpp b/esphome/components/api/api_pb2_dump.cpp index 9e4a7e91fa..b4da15da0d 100644 --- a/esphome/components/api/api_pb2_dump.cpp +++ b/esphome/components/api/api_pb2_dump.cpp @@ -381,6 +381,29 @@ template<> const char *proto_enum_to_string(enums:: } } #endif +template<> +const char *proto_enum_to_string(enums::VoiceAssistantSubscribeFlag value) { + switch (value) { + case enums::VOICE_ASSISTANT_SUBSCRIBE_NONE: + return "VOICE_ASSISTANT_SUBSCRIBE_NONE"; + case enums::VOICE_ASSISTANT_SUBSCRIBE_API_AUDIO: + return "VOICE_ASSISTANT_SUBSCRIBE_API_AUDIO"; + default: + return "UNKNOWN"; + } +} +template<> const char *proto_enum_to_string(enums::VoiceAssistantRequestFlag value) { + switch (value) { + case enums::VOICE_ASSISTANT_REQUEST_NONE: + return "VOICE_ASSISTANT_REQUEST_NONE"; + case enums::VOICE_ASSISTANT_REQUEST_USE_VAD: + return "VOICE_ASSISTANT_REQUEST_USE_VAD"; + case enums::VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD: + return "VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD"; + default: + return "UNKNOWN"; + } +} #ifdef USE_VOICE_ASSISTANT template<> const char *proto_enum_to_string(enums::VoiceAssistantEvent value) { switch (value) { diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 8c516adcbe..50b264410f 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -971,13 +971,11 @@ class RepeatedTypeInfo(TypeInfo): def build_type_usage_map( file_desc: descriptor.FileDescriptorProto, -) -> tuple[ - dict[str, str | None], dict[str, str | None], dict[str, int], set[str], set[str] -]: +) -> tuple[dict[str, str | None], dict[str, str | None], dict[str, int], set[str]]: """Build mappings for both enums and messages to their ifdefs based on usage. Returns: - tuple: (enum_ifdef_map, message_ifdef_map, message_source_map, used_enums, used_messages) + tuple: (enum_ifdef_map, message_ifdef_map, message_source_map, used_messages) """ enum_ifdef_map: dict[str, str | None] = {} message_ifdef_map: dict[str, str | None] = {} @@ -990,9 +988,6 @@ def build_type_usage_map( message_usage: dict[ str, set[str] ] = {} # message_name -> set of message names that use it - used_enums: set[str] = ( - set() - ) # Track which enums are actually used by non-deprecated fields used_messages: set[str] = set() # Track which messages are actually used # Build message name to ifdef mapping for quick lookup @@ -1018,7 +1013,6 @@ def build_type_usage_map( # Track enum usage (only from non-deprecated fields) if field.type == 14: # TYPE_ENUM enum_usage.setdefault(type_name, set()).add(message.name) - used_enums.add(type_name) # Track message usage elif field.type == 11: # TYPE_MESSAGE message_usage.setdefault(type_name, set()).add(message.name) @@ -1129,7 +1123,6 @@ def build_type_usage_map( enum_ifdef_map, message_ifdef_map, message_source_map, - used_enums, used_messages, ) @@ -1718,7 +1711,7 @@ namespace api { content += "namespace enums {\n\n" # Build dynamic ifdef mappings for both enums and messages - enum_ifdef_map, message_ifdef_map, message_source_map, used_enums, used_messages = ( + enum_ifdef_map, message_ifdef_map, message_source_map, used_messages = ( build_type_usage_map(file) ) @@ -1730,10 +1723,6 @@ namespace api { if enum.options.deprecated: continue - # Skip enums that aren't used by any non-deprecated fields - if enum.name not in used_enums: - continue - s, c, dc = build_enum_type(enum, enum_ifdef_map) enum_ifdef = enum_ifdef_map.get(enum.name)