From ffa2cbeb3ff899268768f5dde709fe615b9eb87f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 6 Jun 2025 06:10:50 +0100 Subject: [PATCH] fixes --- esphome/components/api/api_pb2_service.cpp | 128 ----------------- esphome/components/api/api_pb2_service.h | 159 ++++----------------- script/api_protobuf/api_protobuf.py | 14 +- 3 files changed, 40 insertions(+), 261 deletions(-) diff --git a/esphome/components/api/api_pb2_service.cpp b/esphome/components/api/api_pb2_service.cpp index e6ad086f22..7245bc2ef6 100644 --- a/esphome/components/api/api_pb2_service.cpp +++ b/esphome/components/api/api_pb2_service.cpp @@ -8,90 +8,30 @@ namespace api { static const char *const TAG = "api.service"; -#ifdef USE_BINARY_SENSOR -#endif -#ifdef USE_BINARY_SENSOR -#endif #ifdef USE_COVER #endif -#ifdef USE_COVER -#endif -#ifdef USE_COVER -#endif -#ifdef USE_FAN -#endif -#ifdef USE_FAN -#endif #ifdef USE_FAN #endif #ifdef USE_LIGHT #endif -#ifdef USE_LIGHT -#endif -#ifdef USE_LIGHT -#endif -#ifdef USE_SENSOR -#endif -#ifdef USE_SENSOR -#endif #ifdef USE_SWITCH #endif -#ifdef USE_SWITCH -#endif -#ifdef USE_SWITCH -#endif -#ifdef USE_TEXT_SENSOR -#endif -#ifdef USE_TEXT_SENSOR -#endif -#ifdef USE_API_NOISE -#endif #ifdef USE_API_NOISE #endif #ifdef USE_ESP32_CAMERA #endif -#ifdef USE_ESP32_CAMERA -#endif -#ifdef USE_ESP32_CAMERA -#endif #ifdef USE_CLIMATE #endif -#ifdef USE_CLIMATE -#endif -#ifdef USE_CLIMATE -#endif -#ifdef USE_NUMBER -#endif -#ifdef USE_NUMBER -#endif #ifdef USE_NUMBER #endif #ifdef USE_SELECT #endif -#ifdef USE_SELECT -#endif -#ifdef USE_SELECT -#endif #ifdef USE_SIREN #endif -#ifdef USE_SIREN -#endif -#ifdef USE_SIREN -#endif -#ifdef USE_LOCK -#endif -#ifdef USE_LOCK -#endif #ifdef USE_LOCK #endif #ifdef USE_BUTTON #endif -#ifdef USE_BUTTON -#endif -#ifdef USE_MEDIA_PLAYER -#endif -#ifdef USE_MEDIA_PLAYER -#endif #ifdef USE_MEDIA_PLAYER #endif #ifdef USE_BLUETOOTH_PROXY @@ -116,42 +56,6 @@ static const char *const TAG = "api.service"; #endif #ifdef USE_BLUETOOTH_PROXY #endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_VOICE_ASSISTANT -#endif -#ifdef USE_VOICE_ASSISTANT -#endif -#ifdef USE_VOICE_ASSISTANT -#endif #ifdef USE_VOICE_ASSISTANT #endif #ifdef USE_VOICE_ASSISTANT @@ -170,48 +74,16 @@ static const char *const TAG = "api.service"; #endif #ifdef USE_ALARM_CONTROL_PANEL #endif -#ifdef USE_ALARM_CONTROL_PANEL -#endif -#ifdef USE_ALARM_CONTROL_PANEL -#endif #ifdef USE_TEXT #endif -#ifdef USE_TEXT -#endif -#ifdef USE_TEXT -#endif -#ifdef USE_DATETIME_DATE -#endif -#ifdef USE_DATETIME_DATE -#endif #ifdef USE_DATETIME_DATE #endif #ifdef USE_DATETIME_TIME #endif -#ifdef USE_DATETIME_TIME -#endif -#ifdef USE_DATETIME_TIME -#endif -#ifdef USE_EVENT -#endif -#ifdef USE_EVENT -#endif -#ifdef USE_VALVE -#endif -#ifdef USE_VALVE -#endif #ifdef USE_VALVE #endif #ifdef USE_DATETIME_DATETIME #endif -#ifdef USE_DATETIME_DATETIME -#endif -#ifdef USE_DATETIME_DATETIME -#endif -#ifdef USE_UPDATE -#endif -#ifdef USE_UPDATE -#endif #ifdef USE_UPDATE #endif bool APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) { diff --git a/esphome/components/api/api_pb2_service.h b/esphome/components/api/api_pb2_service.h index 42abe45ad2..fe38bff31a 100644 --- a/esphome/components/api/api_pb2_service.h +++ b/esphome/components/api/api_pb2_service.h @@ -30,53 +30,29 @@ class APIServerConnectionBase : public ProtoService { virtual void on_list_entities_request(const ListEntitiesRequest &value){}; virtual void on_subscribe_states_request(const SubscribeStatesRequest &value){}; -#ifdef USE_BINARY_SENSOR -#endif -#ifdef USE_BINARY_SENSOR -#endif -#ifdef USE_COVER -#endif -#ifdef USE_COVER -#endif + #ifdef USE_COVER virtual void on_cover_command_request(const CoverCommandRequest &value){}; #endif -#ifdef USE_FAN -#endif -#ifdef USE_FAN -#endif + #ifdef USE_FAN virtual void on_fan_command_request(const FanCommandRequest &value){}; #endif -#ifdef USE_LIGHT -#endif -#ifdef USE_LIGHT -#endif + #ifdef USE_LIGHT virtual void on_light_command_request(const LightCommandRequest &value){}; #endif -#ifdef USE_SENSOR -#endif -#ifdef USE_SENSOR -#endif -#ifdef USE_SWITCH -#endif -#ifdef USE_SWITCH -#endif + #ifdef USE_SWITCH virtual void on_switch_command_request(const SwitchCommandRequest &value){}; #endif -#ifdef USE_TEXT_SENSOR -#endif -#ifdef USE_TEXT_SENSOR -#endif + virtual void on_subscribe_logs_request(const SubscribeLogsRequest &value){}; #ifdef USE_API_NOISE virtual void on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &value){}; #endif -#ifdef USE_API_NOISE -#endif + virtual void on_subscribe_homeassistant_services_request(const SubscribeHomeassistantServicesRequest &value){}; virtual void on_subscribe_home_assistant_states_request(const SubscribeHomeAssistantStatesRequest &value){}; @@ -86,57 +62,35 @@ class APIServerConnectionBase : public ProtoService { virtual void on_get_time_response(const GetTimeResponse &value){}; virtual void on_execute_service_request(const ExecuteServiceRequest &value){}; -#ifdef USE_ESP32_CAMERA -#endif -#ifdef USE_ESP32_CAMERA -#endif + #ifdef USE_ESP32_CAMERA virtual void on_camera_image_request(const CameraImageRequest &value){}; #endif -#ifdef USE_CLIMATE -#endif -#ifdef USE_CLIMATE -#endif + #ifdef USE_CLIMATE virtual void on_climate_command_request(const ClimateCommandRequest &value){}; #endif -#ifdef USE_NUMBER -#endif -#ifdef USE_NUMBER -#endif + #ifdef USE_NUMBER virtual void on_number_command_request(const NumberCommandRequest &value){}; #endif -#ifdef USE_SELECT -#endif -#ifdef USE_SELECT -#endif + #ifdef USE_SELECT virtual void on_select_command_request(const SelectCommandRequest &value){}; #endif -#ifdef USE_SIREN -#endif -#ifdef USE_SIREN -#endif + #ifdef USE_SIREN virtual void on_siren_command_request(const SirenCommandRequest &value){}; #endif -#ifdef USE_LOCK -#endif -#ifdef USE_LOCK -#endif + #ifdef USE_LOCK virtual void on_lock_command_request(const LockCommandRequest &value){}; #endif -#ifdef USE_BUTTON -#endif + #ifdef USE_BUTTON virtual void on_button_command_request(const ButtonCommandRequest &value){}; #endif -#ifdef USE_MEDIA_PLAYER -#endif -#ifdef USE_MEDIA_PLAYER -#endif + #ifdef USE_MEDIA_PLAYER virtual void on_media_player_command_request(const MediaPlayerCommandRequest &value){}; #endif @@ -144,27 +98,19 @@ class APIServerConnectionBase : public ProtoService { virtual void on_subscribe_bluetooth_le_advertisements_request( const SubscribeBluetoothLEAdvertisementsRequest &value){}; #endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif + #ifdef USE_BLUETOOTH_PROXY virtual void on_bluetooth_device_request(const BluetoothDeviceRequest &value){}; #endif -#ifdef USE_BLUETOOTH_PROXY -#endif + #ifdef USE_BLUETOOTH_PROXY virtual void on_bluetooth_gatt_get_services_request(const BluetoothGATTGetServicesRequest &value){}; #endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif + #ifdef USE_BLUETOOTH_PROXY virtual void on_bluetooth_gatt_read_request(const BluetoothGATTReadRequest &value){}; #endif -#ifdef USE_BLUETOOTH_PROXY -#endif + #ifdef USE_BLUETOOTH_PROXY virtual void on_bluetooth_gatt_write_request(const BluetoothGATTWriteRequest &value){}; #endif @@ -177,39 +123,23 @@ class APIServerConnectionBase : public ProtoService { #ifdef USE_BLUETOOTH_PROXY virtual void on_bluetooth_gatt_notify_request(const BluetoothGATTNotifyRequest &value){}; #endif -#ifdef USE_BLUETOOTH_PROXY -#endif + #ifdef USE_BLUETOOTH_PROXY virtual void on_subscribe_bluetooth_connections_free_request(const SubscribeBluetoothConnectionsFreeRequest &value){}; #endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif + #ifdef USE_BLUETOOTH_PROXY virtual void on_unsubscribe_bluetooth_le_advertisements_request( const UnsubscribeBluetoothLEAdvertisementsRequest &value){}; #endif -#ifdef USE_BLUETOOTH_PROXY -#endif -#ifdef USE_BLUETOOTH_PROXY -#endif + #ifdef USE_BLUETOOTH_PROXY virtual void on_bluetooth_scanner_set_mode_request(const BluetoothScannerSetModeRequest &value){}; #endif #ifdef USE_VOICE_ASSISTANT virtual void on_subscribe_voice_assistant_request(const SubscribeVoiceAssistantRequest &value){}; #endif -#ifdef USE_VOICE_ASSISTANT -#endif + #ifdef USE_VOICE_ASSISTANT virtual void on_voice_assistant_response(const VoiceAssistantResponse &value){}; #endif @@ -225,66 +155,39 @@ class APIServerConnectionBase : public ProtoService { #ifdef USE_VOICE_ASSISTANT virtual void on_voice_assistant_announce_request(const VoiceAssistantAnnounceRequest &value){}; #endif -#ifdef USE_VOICE_ASSISTANT -#endif + #ifdef USE_VOICE_ASSISTANT virtual void on_voice_assistant_configuration_request(const VoiceAssistantConfigurationRequest &value){}; #endif -#ifdef USE_VOICE_ASSISTANT -#endif + #ifdef USE_VOICE_ASSISTANT virtual void on_voice_assistant_set_configuration(const VoiceAssistantSetConfiguration &value){}; #endif -#ifdef USE_ALARM_CONTROL_PANEL -#endif -#ifdef USE_ALARM_CONTROL_PANEL -#endif + #ifdef USE_ALARM_CONTROL_PANEL virtual void on_alarm_control_panel_command_request(const AlarmControlPanelCommandRequest &value){}; #endif -#ifdef USE_TEXT -#endif -#ifdef USE_TEXT -#endif + #ifdef USE_TEXT virtual void on_text_command_request(const TextCommandRequest &value){}; #endif -#ifdef USE_DATETIME_DATE -#endif -#ifdef USE_DATETIME_DATE -#endif + #ifdef USE_DATETIME_DATE virtual void on_date_command_request(const DateCommandRequest &value){}; #endif -#ifdef USE_DATETIME_TIME -#endif -#ifdef USE_DATETIME_TIME -#endif + #ifdef USE_DATETIME_TIME virtual void on_time_command_request(const TimeCommandRequest &value){}; #endif -#ifdef USE_EVENT -#endif -#ifdef USE_EVENT -#endif -#ifdef USE_VALVE -#endif -#ifdef USE_VALVE -#endif + #ifdef USE_VALVE virtual void on_valve_command_request(const ValveCommandRequest &value){}; #endif -#ifdef USE_DATETIME_DATETIME -#endif -#ifdef USE_DATETIME_DATETIME -#endif + #ifdef USE_DATETIME_DATETIME virtual void on_date_time_command_request(const DateTimeCommandRequest &value){}; #endif -#ifdef USE_UPDATE -#endif -#ifdef USE_UPDATE -#endif + #ifdef USE_UPDATE virtual void on_update_command_request(const UpdateCommandRequest &value){}; #endif diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index c8eb2e5b4e..57279c4aee 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -956,16 +956,19 @@ def build_service_message_type( hout = "" cout = "" + # Store ifdef for later use if ifdef is not None: ifdefs[str(mt.name)] = ifdef - hout += f"#ifdef {ifdef}\n" - cout += f"#ifdef {ifdef}\n" if source in (SOURCE_BOTH, SOURCE_SERVER): # Don't generate individual send methods anymore # The generic send_message method will be used instead pass if source in (SOURCE_BOTH, SOURCE_CLIENT): + # Only add ifdef when we're actually generating content + if ifdef is not None: + hout += f"#ifdef {ifdef}\n" + cout += f"#ifdef {ifdef}\n" # Generate receive func = f"on_{snake}" hout += f"virtual void {func}(const {mt.name} &value){{}};\n" @@ -984,9 +987,10 @@ def build_service_message_type( case += "break;" RECEIVE_CASES[id_] = case - if ifdef is not None: - hout += "#endif\n" - cout += "#endif\n" + # Only close ifdef if we opened it + if ifdef is not None: + hout += "#endif\n" + cout += "#endif\n" return hout, cout