Reduce binary size with field-level conditional compilation for protobuf messages (#9473)

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
J. Nick Koston 2025-07-15 20:36:26 -10:00 committed by GitHub
parent f3c0c0c00c
commit 3ab1ee7a04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 834 additions and 110 deletions

View File

@ -222,37 +222,37 @@ message DeviceInfoResponse {
// The model of the board. For example NodeMCU // The model of the board. For example NodeMCU
string model = 6; string model = 6;
bool has_deep_sleep = 7; bool has_deep_sleep = 7 [(field_ifdef) = "USE_DEEP_SLEEP"];
// The esphome project details if set // The esphome project details if set
string project_name = 8; string project_name = 8 [(field_ifdef) = "ESPHOME_PROJECT_NAME"];
string project_version = 9; string project_version = 9 [(field_ifdef) = "ESPHOME_PROJECT_NAME"];
uint32 webserver_port = 10; uint32 webserver_port = 10 [(field_ifdef) = "USE_WEBSERVER"];
uint32 legacy_bluetooth_proxy_version = 11; uint32 legacy_bluetooth_proxy_version = 11 [(field_ifdef) = "USE_BLUETOOTH_PROXY"];
uint32 bluetooth_proxy_feature_flags = 15; uint32 bluetooth_proxy_feature_flags = 15 [(field_ifdef) = "USE_BLUETOOTH_PROXY"];
string manufacturer = 12; string manufacturer = 12;
string friendly_name = 13; string friendly_name = 13;
uint32 legacy_voice_assistant_version = 14; uint32 legacy_voice_assistant_version = 14 [(field_ifdef) = "USE_VOICE_ASSISTANT"];
uint32 voice_assistant_feature_flags = 17; uint32 voice_assistant_feature_flags = 17 [(field_ifdef) = "USE_VOICE_ASSISTANT"];
string suggested_area = 16; string suggested_area = 16 [(field_ifdef) = "USE_AREAS"];
// The Bluetooth mac address of the device. For example "AC:BC:32:89:0E:AA" // The Bluetooth mac address of the device. For example "AC:BC:32:89:0E:AA"
string bluetooth_mac_address = 18; string bluetooth_mac_address = 18 [(field_ifdef) = "USE_BLUETOOTH_PROXY"];
// Supports receiving and saving api encryption key // Supports receiving and saving api encryption key
bool api_encryption_supported = 19; bool api_encryption_supported = 19 [(field_ifdef) = "USE_API_NOISE"];
repeated DeviceInfo devices = 20; repeated DeviceInfo devices = 20 [(field_ifdef) = "USE_DEVICES"];
repeated AreaInfo areas = 21; repeated AreaInfo areas = 21 [(field_ifdef) = "USE_AREAS"];
// Top-level area info to phase out suggested_area // Top-level area info to phase out suggested_area
AreaInfo area = 22; AreaInfo area = 22 [(field_ifdef) = "USE_AREAS"];
} }
message ListEntitiesRequest { message ListEntitiesRequest {
@ -295,9 +295,9 @@ message ListEntitiesBinarySensorResponse {
string device_class = 5; string device_class = 5;
bool is_status_binary_sensor = 6; bool is_status_binary_sensor = 6;
bool disabled_by_default = 7; bool disabled_by_default = 7;
string icon = 8; string icon = 8 [(field_ifdef) = "USE_ENTITY_ICON"];
EntityCategory entity_category = 9; EntityCategory entity_category = 9;
uint32 device_id = 10; uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
} }
message BinarySensorStateResponse { message BinarySensorStateResponse {
option (id) = 21; option (id) = 21;
@ -311,7 +311,7 @@ message BinarySensorStateResponse {
// If the binary sensor does not have a valid state yet. // If the binary sensor does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller // Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 3; bool missing_state = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== COVER ==================== // ==================== COVER ====================
@ -331,10 +331,10 @@ message ListEntitiesCoverResponse {
bool supports_tilt = 7; bool supports_tilt = 7;
string device_class = 8; string device_class = 8;
bool disabled_by_default = 9; bool disabled_by_default = 9;
string icon = 10; string icon = 10 [(field_ifdef) = "USE_ENTITY_ICON"];
EntityCategory entity_category = 11; EntityCategory entity_category = 11;
bool supports_stop = 12; bool supports_stop = 12;
uint32 device_id = 13; uint32 device_id = 13 [(field_ifdef) = "USE_DEVICES"];
} }
enum LegacyCoverState { enum LegacyCoverState {
@ -361,7 +361,7 @@ message CoverStateResponse {
float position = 3; float position = 3;
float tilt = 4; float tilt = 4;
CoverOperation current_operation = 5; CoverOperation current_operation = 5;
uint32 device_id = 6; uint32 device_id = 6 [(field_ifdef) = "USE_DEVICES"];
} }
enum LegacyCoverCommand { enum LegacyCoverCommand {
@ -388,7 +388,7 @@ message CoverCommandRequest {
bool has_tilt = 6; bool has_tilt = 6;
float tilt = 7; float tilt = 7;
bool stop = 8; bool stop = 8;
uint32 device_id = 9; uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== FAN ==================== // ==================== FAN ====================
@ -408,10 +408,10 @@ message ListEntitiesFanResponse {
bool supports_direction = 7; bool supports_direction = 7;
int32 supported_speed_count = 8; int32 supported_speed_count = 8;
bool disabled_by_default = 9; bool disabled_by_default = 9;
string icon = 10; string icon = 10 [(field_ifdef) = "USE_ENTITY_ICON"];
EntityCategory entity_category = 11; EntityCategory entity_category = 11;
repeated string supported_preset_modes = 12; repeated string supported_preset_modes = 12;
uint32 device_id = 13; uint32 device_id = 13 [(field_ifdef) = "USE_DEVICES"];
} }
enum FanSpeed { enum FanSpeed {
FAN_SPEED_LOW = 0; FAN_SPEED_LOW = 0;
@ -436,7 +436,7 @@ message FanStateResponse {
FanDirection direction = 5; FanDirection direction = 5;
int32 speed_level = 6; int32 speed_level = 6;
string preset_mode = 7; string preset_mode = 7;
uint32 device_id = 8; uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
} }
message FanCommandRequest { message FanCommandRequest {
option (id) = 31; option (id) = 31;
@ -458,7 +458,7 @@ message FanCommandRequest {
int32 speed_level = 11; int32 speed_level = 11;
bool has_preset_mode = 12; bool has_preset_mode = 12;
string preset_mode = 13; string preset_mode = 13;
uint32 device_id = 14; uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== LIGHT ==================== // ==================== LIGHT ====================
@ -496,9 +496,9 @@ message ListEntitiesLightResponse {
float max_mireds = 10; float max_mireds = 10;
repeated string effects = 11; repeated string effects = 11;
bool disabled_by_default = 13; bool disabled_by_default = 13;
string icon = 14; string icon = 14 [(field_ifdef) = "USE_ENTITY_ICON"];
EntityCategory entity_category = 15; EntityCategory entity_category = 15;
uint32 device_id = 16; uint32 device_id = 16 [(field_ifdef) = "USE_DEVICES"];
} }
message LightStateResponse { message LightStateResponse {
option (id) = 24; option (id) = 24;
@ -520,7 +520,7 @@ message LightStateResponse {
float cold_white = 12; float cold_white = 12;
float warm_white = 13; float warm_white = 13;
string effect = 9; string effect = 9;
uint32 device_id = 14; uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
} }
message LightCommandRequest { message LightCommandRequest {
option (id) = 32; option (id) = 32;
@ -556,7 +556,7 @@ message LightCommandRequest {
uint32 flash_length = 17; uint32 flash_length = 17;
bool has_effect = 18; bool has_effect = 18;
string effect = 19; string effect = 19;
uint32 device_id = 28; uint32 device_id = 28 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== SENSOR ==================== // ==================== SENSOR ====================
@ -584,7 +584,7 @@ message ListEntitiesSensorResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
string unit_of_measurement = 6; string unit_of_measurement = 6;
int32 accuracy_decimals = 7; int32 accuracy_decimals = 7;
bool force_update = 8; bool force_update = 8;
@ -594,7 +594,7 @@ message ListEntitiesSensorResponse {
SensorLastResetType legacy_last_reset_type = 11; SensorLastResetType legacy_last_reset_type = 11;
bool disabled_by_default = 12; bool disabled_by_default = 12;
EntityCategory entity_category = 13; EntityCategory entity_category = 13;
uint32 device_id = 14; uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
} }
message SensorStateResponse { message SensorStateResponse {
option (id) = 25; option (id) = 25;
@ -608,7 +608,7 @@ message SensorStateResponse {
// If the sensor does not have a valid state yet. // If the sensor does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller // Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 3; bool missing_state = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== SWITCH ==================== // ==================== SWITCH ====================
@ -623,12 +623,12 @@ message ListEntitiesSwitchResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool assumed_state = 6; bool assumed_state = 6;
bool disabled_by_default = 7; bool disabled_by_default = 7;
EntityCategory entity_category = 8; EntityCategory entity_category = 8;
string device_class = 9; string device_class = 9;
uint32 device_id = 10; uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
} }
message SwitchStateResponse { message SwitchStateResponse {
option (id) = 26; option (id) = 26;
@ -639,7 +639,7 @@ message SwitchStateResponse {
fixed32 key = 1; fixed32 key = 1;
bool state = 2; bool state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
message SwitchCommandRequest { message SwitchCommandRequest {
option (id) = 33; option (id) = 33;
@ -650,7 +650,7 @@ message SwitchCommandRequest {
fixed32 key = 1; fixed32 key = 1;
bool state = 2; bool state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== TEXT SENSOR ==================== // ==================== TEXT SENSOR ====================
@ -665,11 +665,11 @@ message ListEntitiesTextSensorResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
string device_class = 8; string device_class = 8;
uint32 device_id = 9; uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
} }
message TextSensorStateResponse { message TextSensorStateResponse {
option (id) = 27; option (id) = 27;
@ -683,7 +683,7 @@ message TextSensorStateResponse {
// If the text sensor does not have a valid state yet. // If the text sensor does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller // Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 3; bool missing_state = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== SUBSCRIBE LOGS ==================== // ==================== SUBSCRIBE LOGS ====================
@ -855,9 +855,9 @@ message ListEntitiesCameraResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
bool disabled_by_default = 5; bool disabled_by_default = 5;
string icon = 6; string icon = 6 [(field_ifdef) = "USE_ENTITY_ICON"];
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
uint32 device_id = 8; uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
} }
message CameraImageResponse { message CameraImageResponse {
@ -869,7 +869,7 @@ message CameraImageResponse {
fixed32 key = 1; fixed32 key = 1;
bytes data = 2; bytes data = 2;
bool done = 3; bool done = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
message CameraImageRequest { message CameraImageRequest {
option (id) = 45; option (id) = 45;
@ -955,14 +955,14 @@ message ListEntitiesClimateResponse {
repeated ClimatePreset supported_presets = 16; repeated ClimatePreset supported_presets = 16;
repeated string supported_custom_presets = 17; repeated string supported_custom_presets = 17;
bool disabled_by_default = 18; bool disabled_by_default = 18;
string icon = 19; string icon = 19 [(field_ifdef) = "USE_ENTITY_ICON"];
EntityCategory entity_category = 20; EntityCategory entity_category = 20;
float visual_current_temperature_step = 21; float visual_current_temperature_step = 21;
bool supports_current_humidity = 22; bool supports_current_humidity = 22;
bool supports_target_humidity = 23; bool supports_target_humidity = 23;
float visual_min_humidity = 24; float visual_min_humidity = 24;
float visual_max_humidity = 25; float visual_max_humidity = 25;
uint32 device_id = 26; uint32 device_id = 26 [(field_ifdef) = "USE_DEVICES"];
} }
message ClimateStateResponse { message ClimateStateResponse {
option (id) = 47; option (id) = 47;
@ -987,7 +987,7 @@ message ClimateStateResponse {
string custom_preset = 13; string custom_preset = 13;
float current_humidity = 14; float current_humidity = 14;
float target_humidity = 15; float target_humidity = 15;
uint32 device_id = 16; uint32 device_id = 16 [(field_ifdef) = "USE_DEVICES"];
} }
message ClimateCommandRequest { message ClimateCommandRequest {
option (id) = 48; option (id) = 48;
@ -1020,7 +1020,7 @@ message ClimateCommandRequest {
string custom_preset = 21; string custom_preset = 21;
bool has_target_humidity = 22; bool has_target_humidity = 22;
float target_humidity = 23; float target_humidity = 23;
uint32 device_id = 24; uint32 device_id = 24 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== NUMBER ==================== // ==================== NUMBER ====================
@ -1040,7 +1040,7 @@ message ListEntitiesNumberResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
float min_value = 6; float min_value = 6;
float max_value = 7; float max_value = 7;
float step = 8; float step = 8;
@ -1049,7 +1049,7 @@ message ListEntitiesNumberResponse {
string unit_of_measurement = 11; string unit_of_measurement = 11;
NumberMode mode = 12; NumberMode mode = 12;
string device_class = 13; string device_class = 13;
uint32 device_id = 14; uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
} }
message NumberStateResponse { message NumberStateResponse {
option (id) = 50; option (id) = 50;
@ -1063,7 +1063,7 @@ message NumberStateResponse {
// If the number does not have a valid state yet. // If the number does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller // Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 3; bool missing_state = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
message NumberCommandRequest { message NumberCommandRequest {
option (id) = 51; option (id) = 51;
@ -1074,7 +1074,7 @@ message NumberCommandRequest {
fixed32 key = 1; fixed32 key = 1;
float state = 2; float state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== SELECT ==================== // ==================== SELECT ====================
@ -1089,11 +1089,11 @@ message ListEntitiesSelectResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
repeated string options = 6; repeated string options = 6;
bool disabled_by_default = 7; bool disabled_by_default = 7;
EntityCategory entity_category = 8; EntityCategory entity_category = 8;
uint32 device_id = 9; uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
} }
message SelectStateResponse { message SelectStateResponse {
option (id) = 53; option (id) = 53;
@ -1107,7 +1107,7 @@ message SelectStateResponse {
// If the select does not have a valid state yet. // If the select does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller // Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 3; bool missing_state = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
message SelectCommandRequest { message SelectCommandRequest {
option (id) = 54; option (id) = 54;
@ -1118,7 +1118,7 @@ message SelectCommandRequest {
fixed32 key = 1; fixed32 key = 1;
string state = 2; string state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== SIREN ==================== // ==================== SIREN ====================
@ -1133,13 +1133,13 @@ message ListEntitiesSirenResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
repeated string tones = 7; repeated string tones = 7;
bool supports_duration = 8; bool supports_duration = 8;
bool supports_volume = 9; bool supports_volume = 9;
EntityCategory entity_category = 10; EntityCategory entity_category = 10;
uint32 device_id = 11; uint32 device_id = 11 [(field_ifdef) = "USE_DEVICES"];
} }
message SirenStateResponse { message SirenStateResponse {
option (id) = 56; option (id) = 56;
@ -1150,7 +1150,7 @@ message SirenStateResponse {
fixed32 key = 1; fixed32 key = 1;
bool state = 2; bool state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
message SirenCommandRequest { message SirenCommandRequest {
option (id) = 57; option (id) = 57;
@ -1168,7 +1168,7 @@ message SirenCommandRequest {
uint32 duration = 7; uint32 duration = 7;
bool has_volume = 8; bool has_volume = 8;
float volume = 9; float volume = 9;
uint32 device_id = 10; uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== LOCK ==================== // ==================== LOCK ====================
@ -1196,7 +1196,7 @@ message ListEntitiesLockResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
bool assumed_state = 8; bool assumed_state = 8;
@ -1206,7 +1206,7 @@ message ListEntitiesLockResponse {
// Not yet implemented: // Not yet implemented:
string code_format = 11; string code_format = 11;
uint32 device_id = 12; uint32 device_id = 12 [(field_ifdef) = "USE_DEVICES"];
} }
message LockStateResponse { message LockStateResponse {
option (id) = 59; option (id) = 59;
@ -1216,7 +1216,7 @@ message LockStateResponse {
option (no_delay) = true; option (no_delay) = true;
fixed32 key = 1; fixed32 key = 1;
LockState state = 2; LockState state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
message LockCommandRequest { message LockCommandRequest {
option (id) = 60; option (id) = 60;
@ -1230,7 +1230,7 @@ message LockCommandRequest {
// Not yet implemented: // Not yet implemented:
bool has_code = 3; bool has_code = 3;
string code = 4; string code = 4;
uint32 device_id = 5; uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== BUTTON ==================== // ==================== BUTTON ====================
@ -1245,11 +1245,11 @@ message ListEntitiesButtonResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
string device_class = 8; string device_class = 8;
uint32 device_id = 9; uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
} }
message ButtonCommandRequest { message ButtonCommandRequest {
option (id) = 62; option (id) = 62;
@ -1259,7 +1259,7 @@ message ButtonCommandRequest {
option (base_class) = "CommandProtoMessage"; option (base_class) = "CommandProtoMessage";
fixed32 key = 1; fixed32 key = 1;
uint32 device_id = 2; uint32 device_id = 2 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== MEDIA PLAYER ==================== // ==================== MEDIA PLAYER ====================
@ -1300,7 +1300,7 @@ message ListEntitiesMediaPlayerResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
@ -1308,7 +1308,7 @@ message ListEntitiesMediaPlayerResponse {
repeated MediaPlayerSupportedFormat supported_formats = 9; repeated MediaPlayerSupportedFormat supported_formats = 9;
uint32 device_id = 10; uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
} }
message MediaPlayerStateResponse { message MediaPlayerStateResponse {
option (id) = 64; option (id) = 64;
@ -1320,7 +1320,7 @@ message MediaPlayerStateResponse {
MediaPlayerState state = 2; MediaPlayerState state = 2;
float volume = 3; float volume = 3;
bool muted = 4; bool muted = 4;
uint32 device_id = 5; uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
} }
message MediaPlayerCommandRequest { message MediaPlayerCommandRequest {
option (id) = 65; option (id) = 65;
@ -1342,7 +1342,7 @@ message MediaPlayerCommandRequest {
bool has_announcement = 8; bool has_announcement = 8;
bool announcement = 9; bool announcement = 9;
uint32 device_id = 10; uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== BLUETOOTH ==================== // ==================== BLUETOOTH ====================
@ -1846,13 +1846,13 @@ message ListEntitiesAlarmControlPanelResponse {
fixed32 key = 2; fixed32 key = 2;
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
uint32 supported_features = 8; uint32 supported_features = 8;
bool requires_code = 9; bool requires_code = 9;
bool requires_code_to_arm = 10; bool requires_code_to_arm = 10;
uint32 device_id = 11; uint32 device_id = 11 [(field_ifdef) = "USE_DEVICES"];
} }
message AlarmControlPanelStateResponse { message AlarmControlPanelStateResponse {
@ -1863,7 +1863,7 @@ message AlarmControlPanelStateResponse {
option (no_delay) = true; option (no_delay) = true;
fixed32 key = 1; fixed32 key = 1;
AlarmControlPanelState state = 2; AlarmControlPanelState state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
message AlarmControlPanelCommandRequest { message AlarmControlPanelCommandRequest {
@ -1875,7 +1875,7 @@ message AlarmControlPanelCommandRequest {
fixed32 key = 1; fixed32 key = 1;
AlarmControlPanelStateCommand command = 2; AlarmControlPanelStateCommand command = 2;
string code = 3; string code = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
// ===================== TEXT ===================== // ===================== TEXT =====================
@ -1893,7 +1893,7 @@ message ListEntitiesTextResponse {
fixed32 key = 2; fixed32 key = 2;
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
@ -1901,7 +1901,7 @@ message ListEntitiesTextResponse {
uint32 max_length = 9; uint32 max_length = 9;
string pattern = 10; string pattern = 10;
TextMode mode = 11; TextMode mode = 11;
uint32 device_id = 12; uint32 device_id = 12 [(field_ifdef) = "USE_DEVICES"];
} }
message TextStateResponse { message TextStateResponse {
option (id) = 98; option (id) = 98;
@ -1915,7 +1915,7 @@ message TextStateResponse {
// If the Text does not have a valid state yet. // If the Text does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller // Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 3; bool missing_state = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
message TextCommandRequest { message TextCommandRequest {
option (id) = 99; option (id) = 99;
@ -1926,7 +1926,7 @@ message TextCommandRequest {
fixed32 key = 1; fixed32 key = 1;
string state = 2; string state = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
@ -1942,10 +1942,10 @@ message ListEntitiesDateResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
uint32 device_id = 8; uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
} }
message DateStateResponse { message DateStateResponse {
option (id) = 101; option (id) = 101;
@ -1961,7 +1961,7 @@ message DateStateResponse {
uint32 year = 3; uint32 year = 3;
uint32 month = 4; uint32 month = 4;
uint32 day = 5; uint32 day = 5;
uint32 device_id = 6; uint32 device_id = 6 [(field_ifdef) = "USE_DEVICES"];
} }
message DateCommandRequest { message DateCommandRequest {
option (id) = 102; option (id) = 102;
@ -1974,7 +1974,7 @@ message DateCommandRequest {
uint32 year = 2; uint32 year = 2;
uint32 month = 3; uint32 month = 3;
uint32 day = 4; uint32 day = 4;
uint32 device_id = 5; uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== DATETIME TIME ==================== // ==================== DATETIME TIME ====================
@ -1989,10 +1989,10 @@ message ListEntitiesTimeResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
uint32 device_id = 8; uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
} }
message TimeStateResponse { message TimeStateResponse {
option (id) = 104; option (id) = 104;
@ -2008,7 +2008,7 @@ message TimeStateResponse {
uint32 hour = 3; uint32 hour = 3;
uint32 minute = 4; uint32 minute = 4;
uint32 second = 5; uint32 second = 5;
uint32 device_id = 6; uint32 device_id = 6 [(field_ifdef) = "USE_DEVICES"];
} }
message TimeCommandRequest { message TimeCommandRequest {
option (id) = 105; option (id) = 105;
@ -2021,7 +2021,7 @@ message TimeCommandRequest {
uint32 hour = 2; uint32 hour = 2;
uint32 minute = 3; uint32 minute = 3;
uint32 second = 4; uint32 second = 4;
uint32 device_id = 5; uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== EVENT ==================== // ==================== EVENT ====================
@ -2036,13 +2036,13 @@ message ListEntitiesEventResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
string device_class = 8; string device_class = 8;
repeated string event_types = 9; repeated string event_types = 9;
uint32 device_id = 10; uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
} }
message EventResponse { message EventResponse {
option (id) = 108; option (id) = 108;
@ -2052,7 +2052,7 @@ message EventResponse {
fixed32 key = 1; fixed32 key = 1;
string event_type = 2; string event_type = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== VALVE ==================== // ==================== VALVE ====================
@ -2067,7 +2067,7 @@ message ListEntitiesValveResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
string device_class = 8; string device_class = 8;
@ -2075,7 +2075,7 @@ message ListEntitiesValveResponse {
bool assumed_state = 9; bool assumed_state = 9;
bool supports_position = 10; bool supports_position = 10;
bool supports_stop = 11; bool supports_stop = 11;
uint32 device_id = 12; uint32 device_id = 12 [(field_ifdef) = "USE_DEVICES"];
} }
enum ValveOperation { enum ValveOperation {
@ -2093,7 +2093,7 @@ message ValveStateResponse {
fixed32 key = 1; fixed32 key = 1;
float position = 2; float position = 2;
ValveOperation current_operation = 3; ValveOperation current_operation = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
message ValveCommandRequest { message ValveCommandRequest {
@ -2107,7 +2107,7 @@ message ValveCommandRequest {
bool has_position = 2; bool has_position = 2;
float position = 3; float position = 3;
bool stop = 4; bool stop = 4;
uint32 device_id = 5; uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== DATETIME DATETIME ==================== // ==================== DATETIME DATETIME ====================
@ -2122,10 +2122,10 @@ message ListEntitiesDateTimeResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
uint32 device_id = 8; uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
} }
message DateTimeStateResponse { message DateTimeStateResponse {
option (id) = 113; option (id) = 113;
@ -2139,7 +2139,7 @@ message DateTimeStateResponse {
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller // Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 2; bool missing_state = 2;
fixed32 epoch_seconds = 3; fixed32 epoch_seconds = 3;
uint32 device_id = 4; uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
} }
message DateTimeCommandRequest { message DateTimeCommandRequest {
option (id) = 114; option (id) = 114;
@ -2150,7 +2150,7 @@ message DateTimeCommandRequest {
fixed32 key = 1; fixed32 key = 1;
fixed32 epoch_seconds = 2; fixed32 epoch_seconds = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }
// ==================== UPDATE ==================== // ==================== UPDATE ====================
@ -2165,11 +2165,11 @@ message ListEntitiesUpdateResponse {
string name = 3; string name = 3;
reserved 4; // Deprecated: was string unique_id reserved 4; // Deprecated: was string unique_id
string icon = 5; string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7; EntityCategory entity_category = 7;
string device_class = 8; string device_class = 8;
uint32 device_id = 9; uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
} }
message UpdateStateResponse { message UpdateStateResponse {
option (id) = 117; option (id) = 117;
@ -2188,7 +2188,7 @@ message UpdateStateResponse {
string title = 8; string title = 8;
string release_summary = 9; string release_summary = 9;
string release_url = 10; string release_url = 10;
uint32 device_id = 11; uint32 device_id = 11 [(field_ifdef) = "USE_DEVICES"];
} }
enum UpdateCommand { enum UpdateCommand {
UPDATE_COMMAND_NONE = 0; UPDATE_COMMAND_NONE = 0;
@ -2204,5 +2204,5 @@ message UpdateCommandRequest {
fixed32 key = 1; fixed32 key = 1;
UpdateCommand command = 2; UpdateCommand command = 2;
uint32 device_id = 3; uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
} }

View File

@ -1463,7 +1463,9 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
#endif #endif
resp.name = App.get_name(); resp.name = App.get_name();
resp.friendly_name = App.get_friendly_name(); resp.friendly_name = App.get_friendly_name();
#ifdef USE_AREAS
resp.suggested_area = App.get_area(); resp.suggested_area = App.get_area();
#endif
resp.mac_address = get_mac_address_pretty(); resp.mac_address = get_mac_address_pretty();
resp.esphome_version = ESPHOME_VERSION; resp.esphome_version = ESPHOME_VERSION;
resp.compilation_time = App.get_compilation_time(); resp.compilation_time = App.get_compilation_time();

View File

@ -287,7 +287,9 @@ class APIConnection : public APIServerConnection {
response.name = entity->get_name(); response.name = entity->get_name();
// Set common EntityBase properties // Set common EntityBase properties
#ifdef USE_ENTITY_ICON
response.icon = entity->get_icon(); response.icon = entity->get_icon();
#endif
response.disabled_by_default = entity->is_disabled_by_default(); response.disabled_by_default = entity->is_disabled_by_default();
response.entity_category = static_cast<enums::EntityCategory>(entity->get_entity_category()); response.entity_category = static_cast<enums::EntityCategory>(entity->get_entity_category());
#ifdef USE_DEVICES #ifdef USE_DEVICES

View File

@ -23,3 +23,7 @@ extend google.protobuf.MessageOptions {
optional bool no_delay = 1040 [default=false]; optional bool no_delay = 1040 [default=false];
optional string base_class = 1041; optional string base_class = 1041;
} }
extend google.protobuf.FieldOptions {
optional string field_ifdef = 1042;
}

File diff suppressed because it is too large Load Diff

View File

@ -491,22 +491,50 @@ class DeviceInfoResponse : public ProtoMessage {
std::string esphome_version{}; std::string esphome_version{};
std::string compilation_time{}; std::string compilation_time{};
std::string model{}; std::string model{};
#ifdef USE_DEEP_SLEEP
bool has_deep_sleep{false}; bool has_deep_sleep{false};
#endif
#ifdef ESPHOME_PROJECT_NAME
std::string project_name{}; std::string project_name{};
#endif
#ifdef ESPHOME_PROJECT_NAME
std::string project_version{}; std::string project_version{};
#endif
#ifdef USE_WEBSERVER
uint32_t webserver_port{0}; uint32_t webserver_port{0};
#endif
#ifdef USE_BLUETOOTH_PROXY
uint32_t legacy_bluetooth_proxy_version{0}; uint32_t legacy_bluetooth_proxy_version{0};
#endif
#ifdef USE_BLUETOOTH_PROXY
uint32_t bluetooth_proxy_feature_flags{0}; uint32_t bluetooth_proxy_feature_flags{0};
#endif
std::string manufacturer{}; std::string manufacturer{};
std::string friendly_name{}; std::string friendly_name{};
#ifdef USE_VOICE_ASSISTANT
uint32_t legacy_voice_assistant_version{0}; uint32_t legacy_voice_assistant_version{0};
#endif
#ifdef USE_VOICE_ASSISTANT
uint32_t voice_assistant_feature_flags{0}; uint32_t voice_assistant_feature_flags{0};
#endif
#ifdef USE_AREAS
std::string suggested_area{}; std::string suggested_area{};
#endif
#ifdef USE_BLUETOOTH_PROXY
std::string bluetooth_mac_address{}; std::string bluetooth_mac_address{};
#endif
#ifdef USE_API_NOISE
bool api_encryption_supported{false}; bool api_encryption_supported{false};
#endif
#ifdef USE_DEVICES
std::vector<DeviceInfo> devices{}; std::vector<DeviceInfo> devices{};
#endif
#ifdef USE_AREAS
std::vector<AreaInfo> areas{}; std::vector<AreaInfo> areas{};
#endif
#ifdef USE_AREAS
AreaInfo area{}; AreaInfo area{};
#endif
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
void calculate_size(uint32_t &total_size) const override; void calculate_size(uint32_t &total_size) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP

File diff suppressed because it is too large Load Diff

View File

@ -75,6 +75,30 @@ def indent(text: str, padding: str = " ") -> str:
return "\n".join(indent_list(text, padding)) return "\n".join(indent_list(text, padding))
def wrap_with_ifdef(content: str | list[str], ifdef: str | None) -> list[str]:
"""Wrap content with #ifdef directives if ifdef is provided.
Args:
content: Single string or list of strings to wrap
ifdef: The ifdef condition, or None to skip wrapping
Returns:
List of strings with ifdef wrapping if needed
"""
if not ifdef:
if isinstance(content, str):
return [content]
return content
result = [f"#ifdef {ifdef}"]
if isinstance(content, str):
result.append(content)
else:
result.extend(content)
result.append("#endif")
return result
def camel_to_snake(name: str) -> str: def camel_to_snake(name: str) -> str:
# https://stackoverflow.com/a/1176023 # https://stackoverflow.com/a/1176023
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name) s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
@ -1064,26 +1088,62 @@ def build_message_type(
# Skip field declarations for fields that are in the base class # Skip field declarations for fields that are in the base class
# but include their encode/decode logic # but include their encode/decode logic
if field.name not in common_field_names: if field.name not in common_field_names:
protected_content.extend(ti.protected_content) # Check for field_ifdef option
public_content.extend(ti.public_content) field_ifdef = None
if field.options.HasExtension(pb.field_ifdef):
field_ifdef = field.options.Extensions[pb.field_ifdef]
if ti.protected_content:
protected_content.extend(
wrap_with_ifdef(ti.protected_content, field_ifdef)
)
if ti.public_content:
public_content.extend(wrap_with_ifdef(ti.public_content, field_ifdef))
# Only collect encode logic if this message needs it # Only collect encode logic if this message needs it
if needs_encode: if needs_encode:
encode.append(ti.encode_content) # Check for field_ifdef option
size_calc.append(ti.get_size_calculation(f"this->{ti.field_name}")) field_ifdef = None
if field.options.HasExtension(pb.field_ifdef):
field_ifdef = field.options.Extensions[pb.field_ifdef]
encode.extend(wrap_with_ifdef(ti.encode_content, field_ifdef))
size_calc.extend(
wrap_with_ifdef(
ti.get_size_calculation(f"this->{ti.field_name}"), field_ifdef
)
)
# Only collect decode methods if this message needs them # Only collect decode methods if this message needs them
if needs_decode: if needs_decode:
# Check for field_ifdef option for decode as well
field_ifdef = None
if field.options.HasExtension(pb.field_ifdef):
field_ifdef = field.options.Extensions[pb.field_ifdef]
if ti.decode_varint_content: if ti.decode_varint_content:
decode_varint.append(ti.decode_varint_content) decode_varint.extend(
wrap_with_ifdef(ti.decode_varint_content, field_ifdef)
)
if ti.decode_length_content: if ti.decode_length_content:
decode_length.append(ti.decode_length_content) decode_length.extend(
wrap_with_ifdef(ti.decode_length_content, field_ifdef)
)
if ti.decode_32bit_content: if ti.decode_32bit_content:
decode_32bit.append(ti.decode_32bit_content) decode_32bit.extend(
wrap_with_ifdef(ti.decode_32bit_content, field_ifdef)
)
if ti.decode_64bit_content: if ti.decode_64bit_content:
decode_64bit.append(ti.decode_64bit_content) decode_64bit.extend(
wrap_with_ifdef(ti.decode_64bit_content, field_ifdef)
)
if ti.dump_content: if ti.dump_content:
dump.append(ti.dump_content) # Check for field_ifdef option for dump as well
field_ifdef = None
if field.options.HasExtension(pb.field_ifdef):
field_ifdef = field.options.Extensions[pb.field_ifdef]
dump.extend(wrap_with_ifdef(ti.dump_content, field_ifdef))
cpp = "" cpp = ""
if decode_varint: if decode_varint: