diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 722f8a02ac..6fc0004fbd 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1442,9 +1442,8 @@ bool APIConnection::try_to_clear_buffer(bool log_out_of_space) { return false; } bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint16_t message_type) { - // If we're in batch mode, just capture the message type and return success + // If we're in batch mode, just return success (message already encoded) if (this->batch_mode_) { - this->captured_message_type_ = message_type; return true; } @@ -1481,18 +1480,9 @@ void APIConnection::on_fatal_error() { this->remove_ = true; } -void APIConnection::DeferredBatch::add_item(void *entity, send_message_t send_func) { - // Check if we already have an item for this entity - for (auto &item : items) { - if (item.entity == entity && item.send_func == send_func) { - // Update timestamp to latest - item.timestamp = App.get_loop_component_start_time(); - return; - } - } - - // Add new item - items.push_back({entity, send_func, App.get_loop_component_start_time()}); +void APIConnection::DeferredBatch::add_item(std::unique_ptr message) { + // Add new item without deduplication + items.push_back({std::move(message), App.get_loop_component_start_time()}); } void APIConnection::schedule_batch_() { @@ -1512,11 +1502,7 @@ void APIConnection::process_batch_() { // Try to clear buffer first if (!this->helper_->can_write_without_blocking()) { - // Can't write now, defer everything to the regular deferred queue - for (const auto &item : this->deferred_batch_.items) { - this->deferred_message_queue_.defer(item.entity, item.send_func); - } - this->deferred_batch_.clear(); + // Can't write now, we'll try again later return; } @@ -1553,7 +1539,6 @@ void APIConnection::process_batch_() { // Save current buffer position before extending uint32_t msg_offset = 0; uint32_t msg_content_start = 0; - this->captured_message_type_ = 0; // For messages after the first, extend the buffer with padding if (processed_count > 0) { @@ -1566,16 +1551,18 @@ void APIConnection::process_batch_() { msg_content_start = this->helper_->frame_header_padding(); } - // Try to encode the message - if (!(this->*item.send_func)(item.entity)) { + // Get the message type before encoding + uint16_t message_type = item.message->get_message_type(); + + // Encode the message directly from the stored ProtoMessage + bool success = item.message->encode(batch_buffer); + + if (!success) { // Encoding failed, revert buffer to previous size this->proto_write_buffer_.resize(msg_offset); continue; } - // Get the captured message type - uint16_t message_type = this->captured_message_type_; - // Calculate message length - from content start to current buffer end uint16_t msg_len = static_cast(this->proto_write_buffer_.size() - msg_content_start); diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 94a64b4e44..0c396a3436 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -385,8 +385,10 @@ class APIConnection : public APIServerConnection { response.disabled_by_default = entity->is_disabled_by_default(); response.entity_category = static_cast(entity->get_entity_category()); - // Send the response using the generic send_message method - return this->send_message(response); + // Add to deferred batch + this->deferred_batch_.add_item(std::make_unique(response)); + this->schedule_batch_(); + return true; } /** @@ -395,7 +397,12 @@ class APIConnection : public APIServerConnection { * @param response The state response object with key already set * @return True if the message was sent successfully */ - template bool try_send_entity_state(ResponseT &response) { return this->send_message(response); } + template bool try_send_entity_state(ResponseT &response) { + // Add to deferred batch + this->deferred_batch_.add_item(std::make_unique(response)); + this->schedule_batch_(); + return true; + } bool send_(const void *buf, size_t len, bool force); @@ -438,8 +445,7 @@ class APIConnection : public APIServerConnection { // Generic batching mechanism for both state updates and entity info struct DeferredBatch { struct BatchItem { - void *entity; - send_message_t send_func; + std::unique_ptr message; uint32_t timestamp; // When this update was queued }; @@ -447,8 +453,8 @@ class APIConnection : public APIServerConnection { uint32_t batch_start_time{0}; bool batch_scheduled{false}; - // Add item with deduplication - newer updates replace older ones for same entity - void add_item(void *entity, send_message_t send_func); + // Add item to the batch + void add_item(std::unique_ptr message); void clear() { items.clear(); batch_scheduled = false; diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index 81fd399f06..6a577d5d20 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -255,7 +255,7 @@ enum UpdateCommand : uint32_t { class HelloRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 1; } + uint16_t get_message_type() const override { return 1; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "hello_request"; } #endif @@ -274,7 +274,7 @@ class HelloRequest : public ProtoMessage { }; class HelloResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 2; } + uint16_t get_message_type() const override { return 2; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "hello_response"; } #endif @@ -294,7 +294,7 @@ class HelloResponse : public ProtoMessage { }; class ConnectRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 3; } + uint16_t get_message_type() const override { return 3; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "connect_request"; } #endif @@ -310,7 +310,7 @@ class ConnectRequest : public ProtoMessage { }; class ConnectResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 4; } + uint16_t get_message_type() const override { return 4; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "connect_response"; } #endif @@ -326,7 +326,7 @@ class ConnectResponse : public ProtoMessage { }; class DisconnectRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 5; } + uint16_t get_message_type() const override { return 5; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "disconnect_request"; } #endif @@ -340,7 +340,7 @@ class DisconnectRequest : public ProtoMessage { }; class DisconnectResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 6; } + uint16_t get_message_type() const override { return 6; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "disconnect_response"; } #endif @@ -354,7 +354,7 @@ class DisconnectResponse : public ProtoMessage { }; class PingRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 7; } + uint16_t get_message_type() const override { return 7; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "ping_request"; } #endif @@ -368,7 +368,7 @@ class PingRequest : public ProtoMessage { }; class PingResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 8; } + uint16_t get_message_type() const override { return 8; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "ping_response"; } #endif @@ -382,7 +382,7 @@ class PingResponse : public ProtoMessage { }; class DeviceInfoRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 9; } + uint16_t get_message_type() const override { return 9; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "device_info_request"; } #endif @@ -396,7 +396,7 @@ class DeviceInfoRequest : public ProtoMessage { }; class DeviceInfoResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 10; } + uint16_t get_message_type() const override { return 10; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "device_info_response"; } #endif @@ -431,7 +431,7 @@ class DeviceInfoResponse : public ProtoMessage { }; class ListEntitiesRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 11; } + uint16_t get_message_type() const override { return 11; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_request"; } #endif @@ -445,7 +445,7 @@ class ListEntitiesRequest : public ProtoMessage { }; class ListEntitiesDoneResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 19; } + uint16_t get_message_type() const override { return 19; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_done_response"; } #endif @@ -459,7 +459,7 @@ class ListEntitiesDoneResponse : public ProtoMessage { }; class SubscribeStatesRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 20; } + uint16_t get_message_type() const override { return 20; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_states_request"; } #endif @@ -473,7 +473,7 @@ class SubscribeStatesRequest : public ProtoMessage { }; class ListEntitiesBinarySensorResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 12; } + uint16_t get_message_type() const override { return 12; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_binary_sensor_response"; } #endif @@ -499,7 +499,7 @@ class ListEntitiesBinarySensorResponse : public ProtoMessage { }; class BinarySensorStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 21; } + uint16_t get_message_type() const override { return 21; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "binary_sensor_state_response"; } #endif @@ -518,7 +518,7 @@ class BinarySensorStateResponse : public ProtoMessage { }; class ListEntitiesCoverResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 13; } + uint16_t get_message_type() const override { return 13; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_cover_response"; } #endif @@ -547,7 +547,7 @@ class ListEntitiesCoverResponse : public ProtoMessage { }; class CoverStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 22; } + uint16_t get_message_type() const override { return 22; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "cover_state_response"; } #endif @@ -568,7 +568,7 @@ class CoverStateResponse : public ProtoMessage { }; class CoverCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 30; } + uint16_t get_message_type() const override { return 30; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "cover_command_request"; } #endif @@ -592,7 +592,7 @@ class CoverCommandRequest : public ProtoMessage { }; class ListEntitiesFanResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 14; } + uint16_t get_message_type() const override { return 14; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_fan_response"; } #endif @@ -621,7 +621,7 @@ class ListEntitiesFanResponse : public ProtoMessage { }; class FanStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 23; } + uint16_t get_message_type() const override { return 23; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "fan_state_response"; } #endif @@ -645,7 +645,7 @@ class FanStateResponse : public ProtoMessage { }; class FanCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 31; } + uint16_t get_message_type() const override { return 31; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "fan_command_request"; } #endif @@ -675,7 +675,7 @@ class FanCommandRequest : public ProtoMessage { }; class ListEntitiesLightResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 15; } + uint16_t get_message_type() const override { return 15; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_light_response"; } #endif @@ -707,7 +707,7 @@ class ListEntitiesLightResponse : public ProtoMessage { }; class LightStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 24; } + uint16_t get_message_type() const override { return 24; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "light_state_response"; } #endif @@ -737,7 +737,7 @@ class LightStateResponse : public ProtoMessage { }; class LightCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 32; } + uint16_t get_message_type() const override { return 32; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "light_command_request"; } #endif @@ -781,7 +781,7 @@ class LightCommandRequest : public ProtoMessage { }; class ListEntitiesSensorResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 16; } + uint16_t get_message_type() const override { return 16; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_sensor_response"; } #endif @@ -811,7 +811,7 @@ class ListEntitiesSensorResponse : public ProtoMessage { }; class SensorStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 25; } + uint16_t get_message_type() const override { return 25; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "sensor_state_response"; } #endif @@ -830,7 +830,7 @@ class SensorStateResponse : public ProtoMessage { }; class ListEntitiesSwitchResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 17; } + uint16_t get_message_type() const override { return 17; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_switch_response"; } #endif @@ -856,7 +856,7 @@ class ListEntitiesSwitchResponse : public ProtoMessage { }; class SwitchStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 26; } + uint16_t get_message_type() const override { return 26; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "switch_state_response"; } #endif @@ -874,7 +874,7 @@ class SwitchStateResponse : public ProtoMessage { }; class SwitchCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 33; } + uint16_t get_message_type() const override { return 33; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "switch_command_request"; } #endif @@ -892,7 +892,7 @@ class SwitchCommandRequest : public ProtoMessage { }; class ListEntitiesTextSensorResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 18; } + uint16_t get_message_type() const override { return 18; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_text_sensor_response"; } #endif @@ -917,7 +917,7 @@ class ListEntitiesTextSensorResponse : public ProtoMessage { }; class TextSensorStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 27; } + uint16_t get_message_type() const override { return 27; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "text_sensor_state_response"; } #endif @@ -937,7 +937,7 @@ class TextSensorStateResponse : public ProtoMessage { }; class SubscribeLogsRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 28; } + uint16_t get_message_type() const override { return 28; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_logs_request"; } #endif @@ -954,7 +954,7 @@ class SubscribeLogsRequest : public ProtoMessage { }; class SubscribeLogsResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 29; } + uint16_t get_message_type() const override { return 29; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_logs_response"; } #endif @@ -973,7 +973,7 @@ class SubscribeLogsResponse : public ProtoMessage { }; class NoiseEncryptionSetKeyRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 124; } + uint16_t get_message_type() const override { return 124; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "noise_encryption_set_key_request"; } #endif @@ -989,7 +989,7 @@ class NoiseEncryptionSetKeyRequest : public ProtoMessage { }; class NoiseEncryptionSetKeyResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 125; } + uint16_t get_message_type() const override { return 125; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "noise_encryption_set_key_response"; } #endif @@ -1005,7 +1005,7 @@ class NoiseEncryptionSetKeyResponse : public ProtoMessage { }; class SubscribeHomeassistantServicesRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 34; } + uint16_t get_message_type() const override { return 34; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_homeassistant_services_request"; } #endif @@ -1032,7 +1032,7 @@ class HomeassistantServiceMap : public ProtoMessage { }; class HomeassistantServiceResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 35; } + uint16_t get_message_type() const override { return 35; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "homeassistant_service_response"; } #endif @@ -1053,7 +1053,7 @@ class HomeassistantServiceResponse : public ProtoMessage { }; class SubscribeHomeAssistantStatesRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 38; } + uint16_t get_message_type() const override { return 38; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_home_assistant_states_request"; } #endif @@ -1067,7 +1067,7 @@ class SubscribeHomeAssistantStatesRequest : public ProtoMessage { }; class SubscribeHomeAssistantStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 39; } + uint16_t get_message_type() const override { return 39; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_home_assistant_state_response"; } #endif @@ -1086,7 +1086,7 @@ class SubscribeHomeAssistantStateResponse : public ProtoMessage { }; class HomeAssistantStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 40; } + uint16_t get_message_type() const override { return 40; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "home_assistant_state_response"; } #endif @@ -1104,7 +1104,7 @@ class HomeAssistantStateResponse : public ProtoMessage { }; class GetTimeRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 36; } + uint16_t get_message_type() const override { return 36; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "get_time_request"; } #endif @@ -1118,7 +1118,7 @@ class GetTimeRequest : public ProtoMessage { }; class GetTimeResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 37; } + uint16_t get_message_type() const override { return 37; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "get_time_response"; } #endif @@ -1148,7 +1148,7 @@ class ListEntitiesServicesArgument : public ProtoMessage { }; class ListEntitiesServicesResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 41; } + uint16_t get_message_type() const override { return 41; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_services_response"; } #endif @@ -1189,7 +1189,7 @@ class ExecuteServiceArgument : public ProtoMessage { }; class ExecuteServiceRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 42; } + uint16_t get_message_type() const override { return 42; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "execute_service_request"; } #endif @@ -1207,7 +1207,7 @@ class ExecuteServiceRequest : public ProtoMessage { }; class ListEntitiesCameraResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 43; } + uint16_t get_message_type() const override { return 43; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_camera_response"; } #endif @@ -1231,7 +1231,7 @@ class ListEntitiesCameraResponse : public ProtoMessage { }; class CameraImageResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 44; } + uint16_t get_message_type() const override { return 44; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "camera_image_response"; } #endif @@ -1251,7 +1251,7 @@ class CameraImageResponse : public ProtoMessage { }; class CameraImageRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 45; } + uint16_t get_message_type() const override { return 45; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "camera_image_request"; } #endif @@ -1268,7 +1268,7 @@ class CameraImageRequest : public ProtoMessage { }; class ListEntitiesClimateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 46; } + uint16_t get_message_type() const override { return 46; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_climate_response"; } #endif @@ -1310,7 +1310,7 @@ class ListEntitiesClimateResponse : public ProtoMessage { }; class ClimateStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 47; } + uint16_t get_message_type() const override { return 47; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "climate_state_response"; } #endif @@ -1342,7 +1342,7 @@ class ClimateStateResponse : public ProtoMessage { }; class ClimateCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 48; } + uint16_t get_message_type() const override { return 48; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "climate_command_request"; } #endif @@ -1382,7 +1382,7 @@ class ClimateCommandRequest : public ProtoMessage { }; class ListEntitiesNumberResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 49; } + uint16_t get_message_type() const override { return 49; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_number_response"; } #endif @@ -1412,7 +1412,7 @@ class ListEntitiesNumberResponse : public ProtoMessage { }; class NumberStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 50; } + uint16_t get_message_type() const override { return 50; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "number_state_response"; } #endif @@ -1431,7 +1431,7 @@ class NumberStateResponse : public ProtoMessage { }; class NumberCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 51; } + uint16_t get_message_type() const override { return 51; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "number_command_request"; } #endif @@ -1448,7 +1448,7 @@ class NumberCommandRequest : public ProtoMessage { }; class ListEntitiesSelectResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 52; } + uint16_t get_message_type() const override { return 52; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_select_response"; } #endif @@ -1473,7 +1473,7 @@ class ListEntitiesSelectResponse : public ProtoMessage { }; class SelectStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 53; } + uint16_t get_message_type() const override { return 53; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "select_state_response"; } #endif @@ -1493,7 +1493,7 @@ class SelectStateResponse : public ProtoMessage { }; class SelectCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 54; } + uint16_t get_message_type() const override { return 54; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "select_command_request"; } #endif @@ -1511,7 +1511,7 @@ class SelectCommandRequest : public ProtoMessage { }; class ListEntitiesSirenResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 55; } + uint16_t get_message_type() const override { return 55; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_siren_response"; } #endif @@ -1538,7 +1538,7 @@ class ListEntitiesSirenResponse : public ProtoMessage { }; class SirenStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 56; } + uint16_t get_message_type() const override { return 56; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "siren_state_response"; } #endif @@ -1556,7 +1556,7 @@ class SirenStateResponse : public ProtoMessage { }; class SirenCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 57; } + uint16_t get_message_type() const override { return 57; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "siren_command_request"; } #endif @@ -1582,7 +1582,7 @@ class SirenCommandRequest : public ProtoMessage { }; class ListEntitiesLockResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 58; } + uint16_t get_message_type() const override { return 58; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_lock_response"; } #endif @@ -1610,7 +1610,7 @@ class ListEntitiesLockResponse : public ProtoMessage { }; class LockStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 59; } + uint16_t get_message_type() const override { return 59; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "lock_state_response"; } #endif @@ -1628,7 +1628,7 @@ class LockStateResponse : public ProtoMessage { }; class LockCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 60; } + uint16_t get_message_type() const override { return 60; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "lock_command_request"; } #endif @@ -1649,7 +1649,7 @@ class LockCommandRequest : public ProtoMessage { }; class ListEntitiesButtonResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 61; } + uint16_t get_message_type() const override { return 61; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_button_response"; } #endif @@ -1674,7 +1674,7 @@ class ListEntitiesButtonResponse : public ProtoMessage { }; class ButtonCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 62; } + uint16_t get_message_type() const override { return 62; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "button_command_request"; } #endif @@ -1707,7 +1707,7 @@ class MediaPlayerSupportedFormat : public ProtoMessage { }; class ListEntitiesMediaPlayerResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 63; } + uint16_t get_message_type() const override { return 63; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_media_player_response"; } #endif @@ -1733,7 +1733,7 @@ class ListEntitiesMediaPlayerResponse : public ProtoMessage { }; class MediaPlayerStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 64; } + uint16_t get_message_type() const override { return 64; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "media_player_state_response"; } #endif @@ -1753,7 +1753,7 @@ class MediaPlayerStateResponse : public ProtoMessage { }; class MediaPlayerCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 65; } + uint16_t get_message_type() const override { return 65; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "media_player_command_request"; } #endif @@ -1779,7 +1779,7 @@ class MediaPlayerCommandRequest : public ProtoMessage { }; class SubscribeBluetoothLEAdvertisementsRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 66; } + uint16_t get_message_type() const override { return 66; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_bluetooth_le_advertisements_request"; } #endif @@ -1810,7 +1810,7 @@ class BluetoothServiceData : public ProtoMessage { }; class BluetoothLEAdvertisementResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 67; } + uint16_t get_message_type() const override { return 67; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_le_advertisement_response"; } #endif @@ -1849,7 +1849,7 @@ class BluetoothLERawAdvertisement : public ProtoMessage { }; class BluetoothLERawAdvertisementsResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 93; } + uint16_t get_message_type() const override { return 93; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_le_raw_advertisements_response"; } #endif @@ -1865,7 +1865,7 @@ class BluetoothLERawAdvertisementsResponse : public ProtoMessage { }; class BluetoothDeviceRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 68; } + uint16_t get_message_type() const override { return 68; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_device_request"; } #endif @@ -1884,7 +1884,7 @@ class BluetoothDeviceRequest : public ProtoMessage { }; class BluetoothDeviceConnectionResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 69; } + uint16_t get_message_type() const override { return 69; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_device_connection_response"; } #endif @@ -1903,7 +1903,7 @@ class BluetoothDeviceConnectionResponse : public ProtoMessage { }; class BluetoothGATTGetServicesRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 70; } + uint16_t get_message_type() const override { return 70; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_get_services_request"; } #endif @@ -1963,7 +1963,7 @@ class BluetoothGATTService : public ProtoMessage { }; class BluetoothGATTGetServicesResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 71; } + uint16_t get_message_type() const override { return 71; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_get_services_response"; } #endif @@ -1981,7 +1981,7 @@ class BluetoothGATTGetServicesResponse : public ProtoMessage { }; class BluetoothGATTGetServicesDoneResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 72; } + uint16_t get_message_type() const override { return 72; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_get_services_done_response"; } #endif @@ -1997,7 +1997,7 @@ class BluetoothGATTGetServicesDoneResponse : public ProtoMessage { }; class BluetoothGATTReadRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 73; } + uint16_t get_message_type() const override { return 73; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_read_request"; } #endif @@ -2014,7 +2014,7 @@ class BluetoothGATTReadRequest : public ProtoMessage { }; class BluetoothGATTReadResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 74; } + uint16_t get_message_type() const override { return 74; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_read_response"; } #endif @@ -2033,7 +2033,7 @@ class BluetoothGATTReadResponse : public ProtoMessage { }; class BluetoothGATTWriteRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 75; } + uint16_t get_message_type() const override { return 75; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_write_request"; } #endif @@ -2053,7 +2053,7 @@ class BluetoothGATTWriteRequest : public ProtoMessage { }; class BluetoothGATTReadDescriptorRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 76; } + uint16_t get_message_type() const override { return 76; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_read_descriptor_request"; } #endif @@ -2070,7 +2070,7 @@ class BluetoothGATTReadDescriptorRequest : public ProtoMessage { }; class BluetoothGATTWriteDescriptorRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 77; } + uint16_t get_message_type() const override { return 77; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_write_descriptor_request"; } #endif @@ -2089,7 +2089,7 @@ class BluetoothGATTWriteDescriptorRequest : public ProtoMessage { }; class BluetoothGATTNotifyRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 78; } + uint16_t get_message_type() const override { return 78; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_notify_request"; } #endif @@ -2107,7 +2107,7 @@ class BluetoothGATTNotifyRequest : public ProtoMessage { }; class BluetoothGATTNotifyDataResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 79; } + uint16_t get_message_type() const override { return 79; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_notify_data_response"; } #endif @@ -2126,7 +2126,7 @@ class BluetoothGATTNotifyDataResponse : public ProtoMessage { }; class SubscribeBluetoothConnectionsFreeRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 80; } + uint16_t get_message_type() const override { return 80; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_bluetooth_connections_free_request"; } #endif @@ -2140,7 +2140,7 @@ class SubscribeBluetoothConnectionsFreeRequest : public ProtoMessage { }; class BluetoothConnectionsFreeResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 81; } + uint16_t get_message_type() const override { return 81; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_connections_free_response"; } #endif @@ -2158,7 +2158,7 @@ class BluetoothConnectionsFreeResponse : public ProtoMessage { }; class BluetoothGATTErrorResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 82; } + uint16_t get_message_type() const override { return 82; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_error_response"; } #endif @@ -2176,7 +2176,7 @@ class BluetoothGATTErrorResponse : public ProtoMessage { }; class BluetoothGATTWriteResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 83; } + uint16_t get_message_type() const override { return 83; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_write_response"; } #endif @@ -2193,7 +2193,7 @@ class BluetoothGATTWriteResponse : public ProtoMessage { }; class BluetoothGATTNotifyResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 84; } + uint16_t get_message_type() const override { return 84; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_gatt_notify_response"; } #endif @@ -2210,7 +2210,7 @@ class BluetoothGATTNotifyResponse : public ProtoMessage { }; class BluetoothDevicePairingResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 85; } + uint16_t get_message_type() const override { return 85; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_device_pairing_response"; } #endif @@ -2228,7 +2228,7 @@ class BluetoothDevicePairingResponse : public ProtoMessage { }; class BluetoothDeviceUnpairingResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 86; } + uint16_t get_message_type() const override { return 86; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_device_unpairing_response"; } #endif @@ -2246,7 +2246,7 @@ class BluetoothDeviceUnpairingResponse : public ProtoMessage { }; class UnsubscribeBluetoothLEAdvertisementsRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 87; } + uint16_t get_message_type() const override { return 87; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "unsubscribe_bluetooth_le_advertisements_request"; } #endif @@ -2260,7 +2260,7 @@ class UnsubscribeBluetoothLEAdvertisementsRequest : public ProtoMessage { }; class BluetoothDeviceClearCacheResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 88; } + uint16_t get_message_type() const override { return 88; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_device_clear_cache_response"; } #endif @@ -2278,7 +2278,7 @@ class BluetoothDeviceClearCacheResponse : public ProtoMessage { }; class BluetoothScannerStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 126; } + uint16_t get_message_type() const override { return 126; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_scanner_state_response"; } #endif @@ -2295,7 +2295,7 @@ class BluetoothScannerStateResponse : public ProtoMessage { }; class BluetoothScannerSetModeRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 127; } + uint16_t get_message_type() const override { return 127; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "bluetooth_scanner_set_mode_request"; } #endif @@ -2311,7 +2311,7 @@ class BluetoothScannerSetModeRequest : public ProtoMessage { }; class SubscribeVoiceAssistantRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 89; } + uint16_t get_message_type() const override { return 89; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "subscribe_voice_assistant_request"; } #endif @@ -2343,7 +2343,7 @@ class VoiceAssistantAudioSettings : public ProtoMessage { }; class VoiceAssistantRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 90; } + uint16_t get_message_type() const override { return 90; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_request"; } #endif @@ -2364,7 +2364,7 @@ class VoiceAssistantRequest : public ProtoMessage { }; class VoiceAssistantResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 91; } + uint16_t get_message_type() const override { return 91; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_response"; } #endif @@ -2394,7 +2394,7 @@ class VoiceAssistantEventData : public ProtoMessage { }; class VoiceAssistantEventResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 92; } + uint16_t get_message_type() const override { return 92; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_event_response"; } #endif @@ -2412,7 +2412,7 @@ class VoiceAssistantEventResponse : public ProtoMessage { }; class VoiceAssistantAudio : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 106; } + uint16_t get_message_type() const override { return 106; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_audio"; } #endif @@ -2430,7 +2430,7 @@ class VoiceAssistantAudio : public ProtoMessage { }; class VoiceAssistantTimerEventResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 115; } + uint16_t get_message_type() const override { return 115; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_timer_event_response"; } #endif @@ -2452,7 +2452,7 @@ class VoiceAssistantTimerEventResponse : public ProtoMessage { }; class VoiceAssistantAnnounceRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 119; } + uint16_t get_message_type() const override { return 119; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_announce_request"; } #endif @@ -2472,7 +2472,7 @@ class VoiceAssistantAnnounceRequest : public ProtoMessage { }; class VoiceAssistantAnnounceFinished : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 120; } + uint16_t get_message_type() const override { return 120; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_announce_finished"; } #endif @@ -2502,7 +2502,7 @@ class VoiceAssistantWakeWord : public ProtoMessage { }; class VoiceAssistantConfigurationRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 121; } + uint16_t get_message_type() const override { return 121; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_configuration_request"; } #endif @@ -2516,7 +2516,7 @@ class VoiceAssistantConfigurationRequest : public ProtoMessage { }; class VoiceAssistantConfigurationResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 122; } + uint16_t get_message_type() const override { return 122; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_configuration_response"; } #endif @@ -2535,7 +2535,7 @@ class VoiceAssistantConfigurationResponse : public ProtoMessage { }; class VoiceAssistantSetConfiguration : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 123; } + uint16_t get_message_type() const override { return 123; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "voice_assistant_set_configuration"; } #endif @@ -2551,7 +2551,7 @@ class VoiceAssistantSetConfiguration : public ProtoMessage { }; class ListEntitiesAlarmControlPanelResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 94; } + uint16_t get_message_type() const override { return 94; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_alarm_control_panel_response"; } #endif @@ -2578,7 +2578,7 @@ class ListEntitiesAlarmControlPanelResponse : public ProtoMessage { }; class AlarmControlPanelStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 95; } + uint16_t get_message_type() const override { return 95; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "alarm_control_panel_state_response"; } #endif @@ -2596,7 +2596,7 @@ class AlarmControlPanelStateResponse : public ProtoMessage { }; class AlarmControlPanelCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 96; } + uint16_t get_message_type() const override { return 96; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "alarm_control_panel_command_request"; } #endif @@ -2616,7 +2616,7 @@ class AlarmControlPanelCommandRequest : public ProtoMessage { }; class ListEntitiesTextResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 97; } + uint16_t get_message_type() const override { return 97; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_text_response"; } #endif @@ -2644,7 +2644,7 @@ class ListEntitiesTextResponse : public ProtoMessage { }; class TextStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 98; } + uint16_t get_message_type() const override { return 98; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "text_state_response"; } #endif @@ -2664,7 +2664,7 @@ class TextStateResponse : public ProtoMessage { }; class TextCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 99; } + uint16_t get_message_type() const override { return 99; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "text_command_request"; } #endif @@ -2682,7 +2682,7 @@ class TextCommandRequest : public ProtoMessage { }; class ListEntitiesDateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 100; } + uint16_t get_message_type() const override { return 100; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_date_response"; } #endif @@ -2706,7 +2706,7 @@ class ListEntitiesDateResponse : public ProtoMessage { }; class DateStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 101; } + uint16_t get_message_type() const override { return 101; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "date_state_response"; } #endif @@ -2727,7 +2727,7 @@ class DateStateResponse : public ProtoMessage { }; class DateCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 102; } + uint16_t get_message_type() const override { return 102; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "date_command_request"; } #endif @@ -2747,7 +2747,7 @@ class DateCommandRequest : public ProtoMessage { }; class ListEntitiesTimeResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 103; } + uint16_t get_message_type() const override { return 103; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_time_response"; } #endif @@ -2771,7 +2771,7 @@ class ListEntitiesTimeResponse : public ProtoMessage { }; class TimeStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 104; } + uint16_t get_message_type() const override { return 104; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "time_state_response"; } #endif @@ -2792,7 +2792,7 @@ class TimeStateResponse : public ProtoMessage { }; class TimeCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 105; } + uint16_t get_message_type() const override { return 105; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "time_command_request"; } #endif @@ -2812,7 +2812,7 @@ class TimeCommandRequest : public ProtoMessage { }; class ListEntitiesEventResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 107; } + uint16_t get_message_type() const override { return 107; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_event_response"; } #endif @@ -2838,7 +2838,7 @@ class ListEntitiesEventResponse : public ProtoMessage { }; class EventResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 108; } + uint16_t get_message_type() const override { return 108; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "event_response"; } #endif @@ -2856,7 +2856,7 @@ class EventResponse : public ProtoMessage { }; class ListEntitiesValveResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 109; } + uint16_t get_message_type() const override { return 109; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_valve_response"; } #endif @@ -2884,7 +2884,7 @@ class ListEntitiesValveResponse : public ProtoMessage { }; class ValveStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 110; } + uint16_t get_message_type() const override { return 110; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "valve_state_response"; } #endif @@ -2903,7 +2903,7 @@ class ValveStateResponse : public ProtoMessage { }; class ValveCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 111; } + uint16_t get_message_type() const override { return 111; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "valve_command_request"; } #endif @@ -2923,7 +2923,7 @@ class ValveCommandRequest : public ProtoMessage { }; class ListEntitiesDateTimeResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 112; } + uint16_t get_message_type() const override { return 112; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_date_time_response"; } #endif @@ -2947,7 +2947,7 @@ class ListEntitiesDateTimeResponse : public ProtoMessage { }; class DateTimeStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 113; } + uint16_t get_message_type() const override { return 113; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "date_time_state_response"; } #endif @@ -2966,7 +2966,7 @@ class DateTimeStateResponse : public ProtoMessage { }; class DateTimeCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 114; } + uint16_t get_message_type() const override { return 114; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "date_time_command_request"; } #endif @@ -2983,7 +2983,7 @@ class DateTimeCommandRequest : public ProtoMessage { }; class ListEntitiesUpdateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 116; } + uint16_t get_message_type() const override { return 116; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "list_entities_update_response"; } #endif @@ -3008,7 +3008,7 @@ class ListEntitiesUpdateResponse : public ProtoMessage { }; class UpdateStateResponse : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 117; } + uint16_t get_message_type() const override { return 117; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "update_state_response"; } #endif @@ -3035,7 +3035,7 @@ class UpdateStateResponse : public ProtoMessage { }; class UpdateCommandRequest : public ProtoMessage { public: - static constexpr uint32_t message_type() { return 118; } + uint16_t get_message_type() const override { return 118; } #ifdef HAS_PROTO_MESSAGE_DUMP static constexpr const char *message_name() { return "update_command_request"; } #endif diff --git a/esphome/components/api/api_pb2_service.h b/esphome/components/api/api_pb2_service.h index 571d67647e..dd6b335d7d 100644 --- a/esphome/components/api/api_pb2_service.h +++ b/esphome/components/api/api_pb2_service.h @@ -14,7 +14,7 @@ class APIServerConnectionBase : public ProtoService { #ifdef HAS_PROTO_MESSAGE_DUMP ESP_LOGVV(TAG, "send_message %s: %s", T::message_name(), msg.dump().c_str()); #endif - return this->send_message_(msg, T::message_type()); + return this->send_message_(msg, msg.get_message_type()); } virtual void on_hello_request(const HelloRequest &value){}; diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index b3440dbfe0..6287210479 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -330,6 +330,7 @@ class ProtoMessage { virtual void encode(ProtoWriteBuffer buffer) const = 0; void decode(const uint8_t *buffer, size_t length); virtual void calculate_size(uint32_t &total_size) const = 0; + virtual uint16_t get_message_type() const = 0; #ifdef HAS_PROTO_MESSAGE_DUMP std::string dump() const; virtual void dump_to(std::string &out) const = 0; diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 1c86039226..8837293730 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -779,7 +779,7 @@ def build_message_type(desc: descriptor.DescriptorProto) -> tuple[str, str]: # Add message_type method if this is a service message if message_id is not None: public_content.append( - f"static constexpr uint32_t message_type() {{ return {message_id}; }}" + f"uint16_t get_message_type() const override {{ return {message_id}; }}" ) # Add message_name method for debugging public_content.append("#ifdef HAS_PROTO_MESSAGE_DUMP") @@ -1097,7 +1097,7 @@ def main() -> None: hpp += "#ifdef HAS_PROTO_MESSAGE_DUMP\n" hpp += ' ESP_LOGVV(TAG, "send_message %s: %s", T::message_name(), msg.dump().c_str());\n' hpp += "#endif\n" - hpp += " return this->send_message_(msg, T::message_type());\n" + hpp += " return this->send_message_(msg, msg.get_message_type());\n" hpp += " }\n\n" for mt in file.message_type: