diff --git a/esphome/components/api/__init__.py b/esphome/components/api/__init__.py index eb8883b025..5b302760b1 100644 --- a/esphome/components/api/__init__.py +++ b/esphome/components/api/__init__.py @@ -24,8 +24,9 @@ from esphome.const import ( CONF_TRIGGER_ID, CONF_VARIABLES, ) -from esphome.core import coroutine_with_priority +from esphome.core import CORE, coroutine_with_priority +DOMAIN = "api" DEPENDENCIES = ["network"] AUTO_LOAD = ["socket"] CODEOWNERS = ["@OttoWinter"] @@ -51,6 +52,7 @@ SERVICE_ARG_NATIVE_TYPES = { } CONF_ENCRYPTION = "encryption" CONF_BATCH_DELAY = "batch_delay" +CONF_CUSTOM_SERVICES = "custom_services" def validate_encryption_key(value): @@ -115,6 +117,7 @@ CONFIG_SCHEMA = cv.All( cv.positive_time_period_milliseconds, cv.Range(max=cv.TimePeriod(milliseconds=65535)), ), + cv.Optional(CONF_CUSTOM_SERVICES, default=False): cv.boolean, cv.Optional(CONF_ON_CLIENT_CONNECTED): automation.validate_automation( single=True ), @@ -139,8 +142,11 @@ async def to_code(config): cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT])) cg.add(var.set_batch_delay(config[CONF_BATCH_DELAY])) + # Set USE_API_SERVICES if any services are enabled + if config.get(CONF_ACTIONS) or config[CONF_CUSTOM_SERVICES]: + cg.add_define("USE_API_SERVICES") + if actions := config.get(CONF_ACTIONS, []): - cg.add_define("USE_API_YAML_SERVICES") for conf in actions: template_args = [] func_args = [] @@ -317,7 +323,10 @@ async def api_connected_to_code(config, condition_id, template_arg, args): def FILTER_SOURCE_FILES() -> list[str]: - """Filter out api_pb2_dump.cpp when proto message dumping is not enabled.""" + """Filter out api_pb2_dump.cpp when proto message dumping is not enabled + and user_services.cpp when no services are defined.""" + files_to_filter = [] + # api_pb2_dump.cpp is only needed when HAS_PROTO_MESSAGE_DUMP is defined # This is a particularly large file that still needs to be opened and read # all the way to the end even when ifdef'd out @@ -325,6 +334,11 @@ def FILTER_SOURCE_FILES() -> list[str]: # HAS_PROTO_MESSAGE_DUMP is defined when ESPHOME_LOG_HAS_VERY_VERBOSE is set, # which happens when the logger level is VERY_VERBOSE if get_logger_level() != "VERY_VERBOSE": - return ["api_pb2_dump.cpp"] + files_to_filter.append("api_pb2_dump.cpp") - return [] + # user_services.cpp is only needed when services are defined + config = CORE.config.get(DOMAIN, {}) + if config and not config.get(CONF_ACTIONS) and not config[CONF_CUSTOM_SERVICES]: + files_to_filter.append("user_services.cpp") + + return files_to_filter diff --git a/esphome/components/api/api.proto b/esphome/components/api/api.proto index c35e603628..861b3471d7 100644 --- a/esphome/components/api/api.proto +++ b/esphome/components/api/api.proto @@ -807,18 +807,21 @@ enum ServiceArgType { SERVICE_ARG_TYPE_STRING_ARRAY = 7; } message ListEntitiesServicesArgument { + option (ifdef) = "USE_API_SERVICES"; string name = 1; ServiceArgType type = 2; } message ListEntitiesServicesResponse { option (id) = 41; option (source) = SOURCE_SERVER; + option (ifdef) = "USE_API_SERVICES"; string name = 1; fixed32 key = 2; repeated ListEntitiesServicesArgument args = 3; } message ExecuteServiceArgument { + option (ifdef) = "USE_API_SERVICES"; bool bool_ = 1; int32 legacy_int = 2; float float_ = 3; @@ -834,6 +837,7 @@ message ExecuteServiceRequest { option (id) = 42; option (source) = SOURCE_CLIENT; option (no_delay) = true; + option (ifdef) = "USE_API_SERVICES"; fixed32 key = 1; repeated ExecuteServiceArgument args = 2; diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 3b0b4858a9..ea3268a583 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1551,6 +1551,7 @@ void APIConnection::on_home_assistant_state_response(const HomeAssistantStateRes } } } +#ifdef USE_API_SERVICES void APIConnection::execute_service(const ExecuteServiceRequest &msg) { bool found = false; for (auto *service : this->parent_->get_user_services()) { @@ -1562,6 +1563,7 @@ void APIConnection::execute_service(const ExecuteServiceRequest &msg) { ESP_LOGV(TAG, "Could not find service"); } } +#endif #ifdef USE_API_NOISE NoiseEncryptionSetKeyResponse APIConnection::noise_encryption_set_key(const NoiseEncryptionSetKeyRequest &msg) { psk_t psk{}; diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index fdc2fb3529..0051a143de 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -195,7 +195,9 @@ class APIConnection : public APIServerConnection { // TODO return {}; } +#ifdef USE_API_SERVICES void execute_service(const ExecuteServiceRequest &msg) override; +#endif #ifdef USE_API_NOISE NoiseEncryptionSetKeyResponse noise_encryption_set_key(const NoiseEncryptionSetKeyRequest &msg) override; #endif diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 156fd42cb3..afd64e8981 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -5,7 +5,6 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" #include "proto.h" -#include "api_pb2_size.h" #include #include diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index 3a6e9230b1..797a33bfbd 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -1,7 +1,6 @@ // This file was automatically generated with a tool. // See script/api_protobuf/api_protobuf.py #include "api_pb2.h" -#include "api_pb2_size.h" #include "esphome/core/log.h" #include "esphome/core/helpers.h" @@ -31,42 +30,6 @@ bool HelloRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) } return true; } -void HelloRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->client_info); - buffer.encode_uint32(2, this->api_version_major); - buffer.encode_uint32(3, this->api_version_minor); -} -void HelloRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->client_info); - ProtoSize::add_uint32_field(total_size, 1, this->api_version_major); - ProtoSize::add_uint32_field(total_size, 1, this->api_version_minor); -} -bool HelloResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->api_version_major = value.as_uint32(); - break; - case 2: - this->api_version_minor = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool HelloResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 3: - this->server_info = value.as_string(); - break; - case 4: - this->name = value.as_string(); - break; - default: - return false; - } - return true; -} void HelloResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, this->api_version_major); buffer.encode_uint32(2, this->api_version_minor); @@ -89,20 +52,6 @@ bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value } return true; } -void ConnectRequest::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->password); } -void ConnectRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->password); -} -bool ConnectResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->invalid_password = value.as_bool(); - break; - default: - return false; - } - return true; -} void ConnectResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->invalid_password); } void ConnectResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->invalid_password); @@ -168,88 +117,6 @@ void DeviceInfo::calculate_size(uint32_t &total_size) const { ProtoSize::add_string_field(total_size, 1, this->name); ProtoSize::add_uint32_field(total_size, 1, this->area_id); } -bool DeviceInfoResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->uses_password = value.as_bool(); - break; - case 7: - this->has_deep_sleep = value.as_bool(); - break; - case 10: - this->webserver_port = value.as_uint32(); - break; - case 11: - this->legacy_bluetooth_proxy_version = value.as_uint32(); - break; - case 15: - this->bluetooth_proxy_feature_flags = value.as_uint32(); - break; - case 14: - this->legacy_voice_assistant_version = value.as_uint32(); - break; - case 17: - this->voice_assistant_feature_flags = value.as_uint32(); - break; - case 19: - this->api_encryption_supported = value.as_bool(); - break; - default: - return false; - } - return true; -} -bool DeviceInfoResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->name = value.as_string(); - break; - case 3: - this->mac_address = value.as_string(); - break; - case 4: - this->esphome_version = value.as_string(); - break; - case 5: - this->compilation_time = value.as_string(); - break; - case 6: - this->model = value.as_string(); - break; - case 8: - this->project_name = value.as_string(); - break; - case 9: - this->project_version = value.as_string(); - break; - case 12: - this->manufacturer = value.as_string(); - break; - case 13: - this->friendly_name = value.as_string(); - break; - case 16: - this->suggested_area = value.as_string(); - break; - case 18: - this->bluetooth_mac_address = value.as_string(); - break; - case 20: - this->devices.emplace_back(); - value.decode_to_message(this->devices.back()); - break; - case 21: - this->areas.emplace_back(); - value.decode_to_message(this->areas.back()); - break; - case 22: - value.decode_to_message(this->area); - break; - default: - return false; - } - return true; -} void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->uses_password); buffer.encode_string(2, this->name); @@ -303,57 +170,6 @@ void DeviceInfoResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_message_object(total_size, 2, this->area); } #ifdef USE_BINARY_SENSOR -bool ListEntitiesBinarySensorResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->is_status_binary_sensor = value.as_bool(); - break; - case 7: - this->disabled_by_default = value.as_bool(); - break; - case 9: - this->entity_category = static_cast(value.as_uint32()); - break; - case 10: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesBinarySensorResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->device_class = value.as_string(); - break; - case 8: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesBinarySensorResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesBinarySensorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -378,32 +194,6 @@ void ListEntitiesBinarySensorResponse::calculate_size(uint32_t &total_size) cons ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool BinarySensorStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = value.as_bool(); - break; - case 3: - this->missing_state = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool BinarySensorStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void BinarySensorStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->state); @@ -418,66 +208,6 @@ void BinarySensorStateResponse::calculate_size(uint32_t &total_size) const { } #endif #ifdef USE_COVER -bool ListEntitiesCoverResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 5: - this->assumed_state = value.as_bool(); - break; - case 6: - this->supports_position = value.as_bool(); - break; - case 7: - this->supports_tilt = value.as_bool(); - break; - case 9: - this->disabled_by_default = value.as_bool(); - break; - case 11: - this->entity_category = static_cast(value.as_uint32()); - break; - case 12: - this->supports_stop = value.as_bool(); - break; - case 13: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesCoverResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 8: - this->device_class = value.as_string(); - break; - case 10: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesCoverResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesCoverResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -508,38 +238,6 @@ void ListEntitiesCoverResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->supports_stop); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool CoverStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->legacy_state = static_cast(value.as_uint32()); - break; - case 5: - this->current_operation = static_cast(value.as_uint32()); - break; - case 6: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool CoverStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 3: - this->position = value.as_float(); - break; - case 4: - this->tilt = value.as_float(); - break; - default: - return false; - } - return true; -} void CoverStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_uint32(2, static_cast(this->legacy_state)); @@ -597,90 +295,8 @@ bool CoverCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void CoverCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->has_legacy_command); - buffer.encode_uint32(3, static_cast(this->legacy_command)); - buffer.encode_bool(4, this->has_position); - buffer.encode_float(5, this->position); - buffer.encode_bool(6, this->has_tilt); - buffer.encode_float(7, this->tilt); - buffer.encode_bool(8, this->stop); - buffer.encode_uint32(9, this->device_id); -} -void CoverCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->has_legacy_command); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->legacy_command)); - ProtoSize::add_bool_field(total_size, 1, this->has_position); - ProtoSize::add_fixed_field<4>(total_size, 1, this->position != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_tilt); - ProtoSize::add_fixed_field<4>(total_size, 1, this->tilt != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->stop); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_FAN -bool ListEntitiesFanResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 5: - this->supports_oscillation = value.as_bool(); - break; - case 6: - this->supports_speed = value.as_bool(); - break; - case 7: - this->supports_direction = value.as_bool(); - break; - case 8: - this->supported_speed_count = value.as_int32(); - break; - case 9: - this->disabled_by_default = value.as_bool(); - break; - case 11: - this->entity_category = static_cast(value.as_uint32()); - break; - case 13: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesFanResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 10: - this->icon = value.as_string(); - break; - case 12: - this->supported_preset_modes.push_back(value.as_string()); - break; - default: - return false; - } - return true; -} -bool ListEntitiesFanResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesFanResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -717,51 +333,6 @@ void ListEntitiesFanResponse::calculate_size(uint32_t &total_size) const { } ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool FanStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = value.as_bool(); - break; - case 3: - this->oscillating = value.as_bool(); - break; - case 4: - this->speed = static_cast(value.as_uint32()); - break; - case 5: - this->direction = static_cast(value.as_uint32()); - break; - case 6: - this->speed_level = value.as_int32(); - break; - case 8: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool FanStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 7: - this->preset_mode = value.as_string(); - break; - default: - return false; - } - return true; -} -bool FanStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void FanStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->state); @@ -845,109 +416,8 @@ bool FanCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void FanCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->has_state); - buffer.encode_bool(3, this->state); - buffer.encode_bool(4, this->has_speed); - buffer.encode_uint32(5, static_cast(this->speed)); - buffer.encode_bool(6, this->has_oscillating); - buffer.encode_bool(7, this->oscillating); - buffer.encode_bool(8, this->has_direction); - buffer.encode_uint32(9, static_cast(this->direction)); - buffer.encode_bool(10, this->has_speed_level); - buffer.encode_int32(11, this->speed_level); - buffer.encode_bool(12, this->has_preset_mode); - buffer.encode_string(13, this->preset_mode); - buffer.encode_uint32(14, this->device_id); -} -void FanCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->has_state); - ProtoSize::add_bool_field(total_size, 1, this->state); - ProtoSize::add_bool_field(total_size, 1, this->has_speed); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->speed)); - ProtoSize::add_bool_field(total_size, 1, this->has_oscillating); - ProtoSize::add_bool_field(total_size, 1, this->oscillating); - ProtoSize::add_bool_field(total_size, 1, this->has_direction); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->direction)); - ProtoSize::add_bool_field(total_size, 1, this->has_speed_level); - ProtoSize::add_int32_field(total_size, 1, this->speed_level); - ProtoSize::add_bool_field(total_size, 1, this->has_preset_mode); - ProtoSize::add_string_field(total_size, 1, this->preset_mode); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_LIGHT -bool ListEntitiesLightResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 12: - this->supported_color_modes.push_back(static_cast(value.as_uint32())); - break; - case 5: - this->legacy_supports_brightness = value.as_bool(); - break; - case 6: - this->legacy_supports_rgb = value.as_bool(); - break; - case 7: - this->legacy_supports_white_value = value.as_bool(); - break; - case 8: - this->legacy_supports_color_temperature = value.as_bool(); - break; - case 13: - this->disabled_by_default = value.as_bool(); - break; - case 15: - this->entity_category = static_cast(value.as_uint32()); - break; - case 16: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesLightResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 11: - this->effects.push_back(value.as_string()); - break; - case 14: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesLightResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - case 9: - this->min_mireds = value.as_float(); - break; - case 10: - this->max_mireds = value.as_float(); - break; - default: - return false; - } - return true; -} void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -996,69 +466,6 @@ void ListEntitiesLightResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 2, this->device_id); } -bool LightStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = value.as_bool(); - break; - case 11: - this->color_mode = static_cast(value.as_uint32()); - break; - case 14: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool LightStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 9: - this->effect = value.as_string(); - break; - default: - return false; - } - return true; -} -bool LightStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 3: - this->brightness = value.as_float(); - break; - case 10: - this->color_brightness = value.as_float(); - break; - case 4: - this->red = value.as_float(); - break; - case 5: - this->green = value.as_float(); - break; - case 6: - this->blue = value.as_float(); - break; - case 7: - this->white = value.as_float(); - break; - case 8: - this->color_temperature = value.as_float(); - break; - case 12: - this->cold_white = value.as_float(); - break; - case 13: - this->warm_white = value.as_float(); - break; - default: - return false; - } - return true; -} void LightStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->state); @@ -1196,131 +603,8 @@ bool LightCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void LightCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->has_state); - buffer.encode_bool(3, this->state); - buffer.encode_bool(4, this->has_brightness); - buffer.encode_float(5, this->brightness); - buffer.encode_bool(22, this->has_color_mode); - buffer.encode_uint32(23, static_cast(this->color_mode)); - buffer.encode_bool(20, this->has_color_brightness); - buffer.encode_float(21, this->color_brightness); - buffer.encode_bool(6, this->has_rgb); - buffer.encode_float(7, this->red); - buffer.encode_float(8, this->green); - buffer.encode_float(9, this->blue); - buffer.encode_bool(10, this->has_white); - buffer.encode_float(11, this->white); - buffer.encode_bool(12, this->has_color_temperature); - buffer.encode_float(13, this->color_temperature); - buffer.encode_bool(24, this->has_cold_white); - buffer.encode_float(25, this->cold_white); - buffer.encode_bool(26, this->has_warm_white); - buffer.encode_float(27, this->warm_white); - buffer.encode_bool(14, this->has_transition_length); - buffer.encode_uint32(15, this->transition_length); - buffer.encode_bool(16, this->has_flash_length); - buffer.encode_uint32(17, this->flash_length); - buffer.encode_bool(18, this->has_effect); - buffer.encode_string(19, this->effect); - buffer.encode_uint32(28, this->device_id); -} -void LightCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->has_state); - ProtoSize::add_bool_field(total_size, 1, this->state); - ProtoSize::add_bool_field(total_size, 1, this->has_brightness); - ProtoSize::add_fixed_field<4>(total_size, 1, this->brightness != 0.0f); - ProtoSize::add_bool_field(total_size, 2, this->has_color_mode); - ProtoSize::add_enum_field(total_size, 2, static_cast(this->color_mode)); - ProtoSize::add_bool_field(total_size, 2, this->has_color_brightness); - ProtoSize::add_fixed_field<4>(total_size, 2, this->color_brightness != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_rgb); - ProtoSize::add_fixed_field<4>(total_size, 1, this->red != 0.0f); - ProtoSize::add_fixed_field<4>(total_size, 1, this->green != 0.0f); - ProtoSize::add_fixed_field<4>(total_size, 1, this->blue != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_white); - ProtoSize::add_fixed_field<4>(total_size, 1, this->white != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_color_temperature); - ProtoSize::add_fixed_field<4>(total_size, 1, this->color_temperature != 0.0f); - ProtoSize::add_bool_field(total_size, 2, this->has_cold_white); - ProtoSize::add_fixed_field<4>(total_size, 2, this->cold_white != 0.0f); - ProtoSize::add_bool_field(total_size, 2, this->has_warm_white); - ProtoSize::add_fixed_field<4>(total_size, 2, this->warm_white != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_transition_length); - ProtoSize::add_uint32_field(total_size, 1, this->transition_length); - ProtoSize::add_bool_field(total_size, 2, this->has_flash_length); - ProtoSize::add_uint32_field(total_size, 2, this->flash_length); - ProtoSize::add_bool_field(total_size, 2, this->has_effect); - ProtoSize::add_string_field(total_size, 2, this->effect); - ProtoSize::add_uint32_field(total_size, 2, this->device_id); -} #endif #ifdef USE_SENSOR -bool ListEntitiesSensorResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 7: - this->accuracy_decimals = value.as_int32(); - break; - case 8: - this->force_update = value.as_bool(); - break; - case 10: - this->state_class = static_cast(value.as_uint32()); - break; - case 11: - this->legacy_last_reset_type = static_cast(value.as_uint32()); - break; - case 12: - this->disabled_by_default = value.as_bool(); - break; - case 13: - this->entity_category = static_cast(value.as_uint32()); - break; - case 14: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSensorResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 6: - this->unit_of_measurement = value.as_string(); - break; - case 9: - this->device_class = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSensorResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesSensorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -1353,32 +637,6 @@ void ListEntitiesSensorResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool SensorStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->missing_state = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool SensorStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 2: - this->state = value.as_float(); - break; - default: - return false; - } - return true; -} void SensorStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_float(2, this->state); @@ -1393,57 +651,6 @@ void SensorStateResponse::calculate_size(uint32_t &total_size) const { } #endif #ifdef USE_SWITCH -bool ListEntitiesSwitchResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->assumed_state = value.as_bool(); - break; - case 7: - this->disabled_by_default = value.as_bool(); - break; - case 8: - this->entity_category = static_cast(value.as_uint32()); - break; - case 10: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSwitchResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 9: - this->device_class = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSwitchResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesSwitchResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -1468,29 +675,6 @@ void ListEntitiesSwitchResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_string_field(total_size, 1, this->device_class); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool SwitchStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = value.as_bool(); - break; - case 3: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool SwitchStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void SwitchStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->state); @@ -1524,66 +708,8 @@ bool SwitchCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void SwitchCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->state); - buffer.encode_uint32(3, this->device_id); -} -void SwitchCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->state); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_TEXT_SENSOR -bool ListEntitiesTextSensorResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 9: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesTextSensorResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 8: - this->device_class = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesTextSensorResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesTextSensorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -1606,39 +732,6 @@ void ListEntitiesTextSensorResponse::calculate_size(uint32_t &total_size) const ProtoSize::add_string_field(total_size, 1, this->device_class); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool TextSensorStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->missing_state = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool TextSensorStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->state = value.as_string(); - break; - default: - return false; - } - return true; -} -bool TextSensorStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void TextSensorStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_string(2, this->state); @@ -1665,37 +758,6 @@ bool SubscribeLogsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { } return true; } -void SubscribeLogsRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint32(1, static_cast(this->level)); - buffer.encode_bool(2, this->dump_config); -} -void SubscribeLogsRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_enum_field(total_size, 1, static_cast(this->level)); - ProtoSize::add_bool_field(total_size, 1, this->dump_config); -} -bool SubscribeLogsResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->level = static_cast(value.as_uint32()); - break; - case 4: - this->send_failed = value.as_bool(); - break; - default: - return false; - } - return true; -} -bool SubscribeLogsResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 3: - this->message = value.as_string(); - break; - default: - return false; - } - return true; -} void SubscribeLogsResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, static_cast(this->level)); buffer.encode_bytes(3, reinterpret_cast(this->message.data()), this->message.size()); @@ -1717,22 +779,6 @@ bool NoiseEncryptionSetKeyRequest::decode_length(uint32_t field_id, ProtoLengthD } return true; } -void NoiseEncryptionSetKeyRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_bytes(1, reinterpret_cast(this->key.data()), this->key.size()); -} -void NoiseEncryptionSetKeyRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->key); -} -bool NoiseEncryptionSetKeyResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->success = value.as_bool(); - break; - default: - return false; - } - return true; -} void NoiseEncryptionSetKeyResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->success); } void NoiseEncryptionSetKeyResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->success); @@ -1759,38 +805,6 @@ void HomeassistantServiceMap::calculate_size(uint32_t &total_size) const { ProtoSize::add_string_field(total_size, 1, this->key); ProtoSize::add_string_field(total_size, 1, this->value); } -bool HomeassistantServiceResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 5: - this->is_event = value.as_bool(); - break; - default: - return false; - } - return true; -} -bool HomeassistantServiceResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->service = value.as_string(); - break; - case 2: - this->data.emplace_back(); - value.decode_to_message(this->data.back()); - break; - case 3: - this->data_template.emplace_back(); - value.decode_to_message(this->data_template.back()); - break; - case 4: - this->variables.emplace_back(); - value.decode_to_message(this->variables.back()); - break; - default: - return false; - } - return true; -} void HomeassistantServiceResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->service); for (auto &it : this->data) { @@ -1811,29 +825,6 @@ void HomeassistantServiceResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_repeated_message(total_size, 1, this->variables); ProtoSize::add_bool_field(total_size, 1, this->is_event); } -bool SubscribeHomeAssistantStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->once = value.as_bool(); - break; - default: - return false; - } - return true; -} -bool SubscribeHomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->entity_id = value.as_string(); - break; - case 2: - this->attribute = value.as_string(); - break; - default: - return false; - } - return true; -} void SubscribeHomeAssistantStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->entity_id); buffer.encode_string(2, this->attribute); @@ -1860,16 +851,6 @@ bool HomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDel } return true; } -void HomeAssistantStateResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->entity_id); - buffer.encode_string(2, this->state); - buffer.encode_string(3, this->attribute); -} -void HomeAssistantStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->entity_id); - ProtoSize::add_string_field(total_size, 1, this->state); - ProtoSize::add_string_field(total_size, 1, this->attribute); -} bool GetTimeResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { switch (field_id) { case 1: @@ -1884,6 +865,7 @@ void GetTimeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixe void GetTimeResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_fixed_field<4>(total_size, 1, this->epoch_seconds != 0); } +#ifdef USE_API_SERVICES bool ListEntitiesServicesArgument::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 2: @@ -1912,30 +894,6 @@ void ListEntitiesServicesArgument::calculate_size(uint32_t &total_size) const { ProtoSize::add_string_field(total_size, 1, this->name); ProtoSize::add_enum_field(total_size, 1, static_cast(this->type)); } -bool ListEntitiesServicesResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->name = value.as_string(); - break; - case 3: - this->args.emplace_back(); - value.decode_to_message(this->args.back()); - break; - default: - return false; - } - return true; -} -bool ListEntitiesServicesResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesServicesResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->name); buffer.encode_fixed32(2, this->key); @@ -2061,62 +1019,8 @@ bool ExecuteServiceRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void ExecuteServiceRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - for (auto &it : this->args) { - buffer.encode_message(2, it, true); - } -} -void ExecuteServiceRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_repeated_message(total_size, 1, this->args); -} +#endif #ifdef USE_CAMERA -bool ListEntitiesCameraResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 5: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesCameraResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 6: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesCameraResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesCameraResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -2137,39 +1041,6 @@ void ListEntitiesCameraResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool CameraImageResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->done = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool CameraImageResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->data = value.as_string(); - break; - default: - return false; - } - return true; -} -bool CameraImageResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void CameraImageResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bytes(2, reinterpret_cast(this->data.data()), this->data.size()); @@ -2195,115 +1066,8 @@ bool CameraImageRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { } return true; } -void CameraImageRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_bool(1, this->single); - buffer.encode_bool(2, this->stream); -} -void CameraImageRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_bool_field(total_size, 1, this->single); - ProtoSize::add_bool_field(total_size, 1, this->stream); -} #endif #ifdef USE_CLIMATE -bool ListEntitiesClimateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 5: - this->supports_current_temperature = value.as_bool(); - break; - case 6: - this->supports_two_point_target_temperature = value.as_bool(); - break; - case 7: - this->supported_modes.push_back(static_cast(value.as_uint32())); - break; - case 11: - this->legacy_supports_away = value.as_bool(); - break; - case 12: - this->supports_action = value.as_bool(); - break; - case 13: - this->supported_fan_modes.push_back(static_cast(value.as_uint32())); - break; - case 14: - this->supported_swing_modes.push_back(static_cast(value.as_uint32())); - break; - case 16: - this->supported_presets.push_back(static_cast(value.as_uint32())); - break; - case 18: - this->disabled_by_default = value.as_bool(); - break; - case 20: - this->entity_category = static_cast(value.as_uint32()); - break; - case 22: - this->supports_current_humidity = value.as_bool(); - break; - case 23: - this->supports_target_humidity = value.as_bool(); - break; - case 26: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesClimateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 15: - this->supported_custom_fan_modes.push_back(value.as_string()); - break; - case 17: - this->supported_custom_presets.push_back(value.as_string()); - break; - case 19: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesClimateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - case 8: - this->visual_min_temperature = value.as_float(); - break; - case 9: - this->visual_max_temperature = value.as_float(); - break; - case 10: - this->visual_target_temperature_step = value.as_float(); - break; - case 21: - this->visual_current_temperature_step = value.as_float(); - break; - case 24: - this->visual_min_humidity = value.as_float(); - break; - case 25: - this->visual_max_humidity = value.as_float(); - break; - default: - return false; - } - return true; -} void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -2396,75 +1160,6 @@ void ListEntitiesClimateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_fixed_field<4>(total_size, 2, this->visual_max_humidity != 0.0f); ProtoSize::add_uint32_field(total_size, 2, this->device_id); } -bool ClimateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->mode = static_cast(value.as_uint32()); - break; - case 7: - this->unused_legacy_away = value.as_bool(); - break; - case 8: - this->action = static_cast(value.as_uint32()); - break; - case 9: - this->fan_mode = static_cast(value.as_uint32()); - break; - case 10: - this->swing_mode = static_cast(value.as_uint32()); - break; - case 12: - this->preset = static_cast(value.as_uint32()); - break; - case 16: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ClimateStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 11: - this->custom_fan_mode = value.as_string(); - break; - case 13: - this->custom_preset = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ClimateStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 3: - this->current_temperature = value.as_float(); - break; - case 4: - this->target_temperature = value.as_float(); - break; - case 5: - this->target_temperature_low = value.as_float(); - break; - case 6: - this->target_temperature_high = value.as_float(); - break; - case 14: - this->current_humidity = value.as_float(); - break; - case 15: - this->target_humidity = value.as_float(); - break; - default: - return false; - } - return true; -} void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_uint32(2, static_cast(this->mode)); @@ -2594,123 +1289,8 @@ bool ClimateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void ClimateCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->has_mode); - buffer.encode_uint32(3, static_cast(this->mode)); - buffer.encode_bool(4, this->has_target_temperature); - buffer.encode_float(5, this->target_temperature); - buffer.encode_bool(6, this->has_target_temperature_low); - buffer.encode_float(7, this->target_temperature_low); - buffer.encode_bool(8, this->has_target_temperature_high); - buffer.encode_float(9, this->target_temperature_high); - buffer.encode_bool(10, this->unused_has_legacy_away); - buffer.encode_bool(11, this->unused_legacy_away); - buffer.encode_bool(12, this->has_fan_mode); - buffer.encode_uint32(13, static_cast(this->fan_mode)); - buffer.encode_bool(14, this->has_swing_mode); - buffer.encode_uint32(15, static_cast(this->swing_mode)); - buffer.encode_bool(16, this->has_custom_fan_mode); - buffer.encode_string(17, this->custom_fan_mode); - buffer.encode_bool(18, this->has_preset); - buffer.encode_uint32(19, static_cast(this->preset)); - buffer.encode_bool(20, this->has_custom_preset); - buffer.encode_string(21, this->custom_preset); - buffer.encode_bool(22, this->has_target_humidity); - buffer.encode_float(23, this->target_humidity); - buffer.encode_uint32(24, this->device_id); -} -void ClimateCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->has_mode); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); - ProtoSize::add_bool_field(total_size, 1, this->has_target_temperature); - ProtoSize::add_fixed_field<4>(total_size, 1, this->target_temperature != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_target_temperature_low); - ProtoSize::add_fixed_field<4>(total_size, 1, this->target_temperature_low != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_target_temperature_high); - ProtoSize::add_fixed_field<4>(total_size, 1, this->target_temperature_high != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->unused_has_legacy_away); - ProtoSize::add_bool_field(total_size, 1, this->unused_legacy_away); - ProtoSize::add_bool_field(total_size, 1, this->has_fan_mode); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->fan_mode)); - ProtoSize::add_bool_field(total_size, 1, this->has_swing_mode); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->swing_mode)); - ProtoSize::add_bool_field(total_size, 2, this->has_custom_fan_mode); - ProtoSize::add_string_field(total_size, 2, this->custom_fan_mode); - ProtoSize::add_bool_field(total_size, 2, this->has_preset); - ProtoSize::add_enum_field(total_size, 2, static_cast(this->preset)); - ProtoSize::add_bool_field(total_size, 2, this->has_custom_preset); - ProtoSize::add_string_field(total_size, 2, this->custom_preset); - ProtoSize::add_bool_field(total_size, 2, this->has_target_humidity); - ProtoSize::add_fixed_field<4>(total_size, 2, this->target_humidity != 0.0f); - ProtoSize::add_uint32_field(total_size, 2, this->device_id); -} #endif #ifdef USE_NUMBER -bool ListEntitiesNumberResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 9: - this->disabled_by_default = value.as_bool(); - break; - case 10: - this->entity_category = static_cast(value.as_uint32()); - break; - case 12: - this->mode = static_cast(value.as_uint32()); - break; - case 14: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesNumberResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 11: - this->unit_of_measurement = value.as_string(); - break; - case 13: - this->device_class = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesNumberResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - case 6: - this->min_value = value.as_float(); - break; - case 7: - this->max_value = value.as_float(); - break; - case 8: - this->step = value.as_float(); - break; - default: - return false; - } - return true; -} void ListEntitiesNumberResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -2743,32 +1323,6 @@ void ListEntitiesNumberResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_string_field(total_size, 1, this->device_class); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool NumberStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->missing_state = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool NumberStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 2: - this->state = value.as_float(); - break; - default: - return false; - } - return true; -} void NumberStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_float(2, this->state); @@ -2804,66 +1358,8 @@ bool NumberCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void NumberCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_float(2, this->state); - buffer.encode_uint32(3, this->device_id); -} -void NumberCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_fixed_field<4>(total_size, 1, this->state != 0.0f); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_SELECT -bool ListEntitiesSelectResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 7: - this->disabled_by_default = value.as_bool(); - break; - case 8: - this->entity_category = static_cast(value.as_uint32()); - break; - case 9: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSelectResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 6: - this->options.push_back(value.as_string()); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSelectResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesSelectResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -2892,39 +1388,6 @@ void ListEntitiesSelectResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool SelectStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->missing_state = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool SelectStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->state = value.as_string(); - break; - default: - return false; - } - return true; -} -bool SelectStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void SelectStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_string(2, this->state); @@ -2967,72 +1430,8 @@ bool SelectCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void SelectCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_string(2, this->state); - buffer.encode_uint32(3, this->device_id); -} -void SelectCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_string_field(total_size, 1, this->state); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_SIREN -bool ListEntitiesSirenResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 8: - this->supports_duration = value.as_bool(); - break; - case 9: - this->supports_volume = value.as_bool(); - break; - case 10: - this->entity_category = static_cast(value.as_uint32()); - break; - case 11: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSirenResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 7: - this->tones.push_back(value.as_string()); - break; - default: - return false; - } - return true; -} -bool ListEntitiesSirenResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesSirenResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -3065,29 +1464,6 @@ void ListEntitiesSirenResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool SirenStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = value.as_bool(); - break; - case 3: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool SirenStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void SirenStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->state); @@ -3149,89 +1525,8 @@ bool SirenCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void SirenCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->has_state); - buffer.encode_bool(3, this->state); - buffer.encode_bool(4, this->has_tone); - buffer.encode_string(5, this->tone); - buffer.encode_bool(6, this->has_duration); - buffer.encode_uint32(7, this->duration); - buffer.encode_bool(8, this->has_volume); - buffer.encode_float(9, this->volume); - buffer.encode_uint32(10, this->device_id); -} -void SirenCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->has_state); - ProtoSize::add_bool_field(total_size, 1, this->state); - ProtoSize::add_bool_field(total_size, 1, this->has_tone); - ProtoSize::add_string_field(total_size, 1, this->tone); - ProtoSize::add_bool_field(total_size, 1, this->has_duration); - ProtoSize::add_uint32_field(total_size, 1, this->duration); - ProtoSize::add_bool_field(total_size, 1, this->has_volume); - ProtoSize::add_fixed_field<4>(total_size, 1, this->volume != 0.0f); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_LOCK -bool ListEntitiesLockResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->assumed_state = value.as_bool(); - break; - case 9: - this->supports_open = value.as_bool(); - break; - case 10: - this->requires_code = value.as_bool(); - break; - case 12: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesLockResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 11: - this->code_format = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesLockResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesLockResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -3260,29 +1555,6 @@ void ListEntitiesLockResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_string_field(total_size, 1, this->code_format); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool LockStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = static_cast(value.as_uint32()); - break; - case 3: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool LockStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void LockStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_uint32(2, static_cast(this->state)); @@ -3329,70 +1601,8 @@ bool LockCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void LockCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_uint32(2, static_cast(this->command)); - buffer.encode_bool(3, this->has_code); - buffer.encode_string(4, this->code); - buffer.encode_uint32(5, this->device_id); -} -void LockCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->command)); - ProtoSize::add_bool_field(total_size, 1, this->has_code); - ProtoSize::add_string_field(total_size, 1, this->code); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_BUTTON -bool ListEntitiesButtonResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 9: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesButtonResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 8: - this->device_class = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesButtonResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesButtonResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -3435,14 +1645,6 @@ bool ButtonCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void ButtonCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_uint32(2, this->device_id); -} -void ButtonCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_MEDIA_PLAYER bool MediaPlayerSupportedFormat::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -3488,58 +1690,6 @@ void MediaPlayerSupportedFormat::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->purpose)); ProtoSize::add_uint32_field(total_size, 1, this->sample_bytes); } -bool ListEntitiesMediaPlayerResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->supports_pause = value.as_bool(); - break; - case 10: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesMediaPlayerResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 9: - this->supported_formats.emplace_back(); - value.decode_to_message(this->supported_formats.back()); - break; - default: - return false; - } - return true; -} -bool ListEntitiesMediaPlayerResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesMediaPlayerResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -3566,35 +1716,6 @@ void ListEntitiesMediaPlayerResponse::calculate_size(uint32_t &total_size) const ProtoSize::add_repeated_message(total_size, 1, this->supported_formats); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool MediaPlayerStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = static_cast(value.as_uint32()); - break; - case 4: - this->muted = value.as_bool(); - break; - case 5: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool MediaPlayerStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 3: - this->volume = value.as_float(); - break; - default: - return false; - } - return true; -} void MediaPlayerStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_uint32(2, static_cast(this->state)); @@ -3660,30 +1781,6 @@ bool MediaPlayerCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value } return true; } -void MediaPlayerCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->has_command); - buffer.encode_uint32(3, static_cast(this->command)); - buffer.encode_bool(4, this->has_volume); - buffer.encode_float(5, this->volume); - buffer.encode_bool(6, this->has_media_url); - buffer.encode_string(7, this->media_url); - buffer.encode_bool(8, this->has_announcement); - buffer.encode_bool(9, this->announcement); - buffer.encode_uint32(10, this->device_id); -} -void MediaPlayerCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->has_command); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->command)); - ProtoSize::add_bool_field(total_size, 1, this->has_volume); - ProtoSize::add_fixed_field<4>(total_size, 1, this->volume != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->has_media_url); - ProtoSize::add_string_field(total_size, 1, this->media_url); - ProtoSize::add_bool_field(total_size, 1, this->has_announcement); - ProtoSize::add_bool_field(total_size, 1, this->announcement); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_BLUETOOTH_PROXY bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -3696,12 +1793,6 @@ bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, } return true; } -void SubscribeBluetoothLEAdvertisementsRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint32(1, this->flags); -} -void SubscribeBluetoothLEAdvertisementsRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint32_field(total_size, 1, this->flags); -} bool BluetoothServiceData::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 2: @@ -3741,43 +1832,6 @@ void BluetoothServiceData::calculate_size(uint32_t &total_size) const { } ProtoSize::add_string_field(total_size, 1, this->data); } -bool BluetoothLEAdvertisementResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 3: - this->rssi = value.as_sint32(); - break; - case 7: - this->address_type = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool BluetoothLEAdvertisementResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->name = value.as_string(); - break; - case 4: - this->service_uuids.push_back(value.as_string()); - break; - case 5: - this->service_data.emplace_back(); - value.decode_to_message(this->service_data.back()); - break; - case 6: - this->manufacturer_data.emplace_back(); - value.decode_to_message(this->manufacturer_data.back()); - break; - default: - return false; - } - return true; -} void BluetoothLEAdvertisementResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bytes(2, reinterpret_cast(this->name.data()), this->name.size()); @@ -3844,17 +1898,6 @@ void BluetoothLERawAdvertisement::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint32_field(total_size, 1, this->address_type); ProtoSize::add_string_field(total_size, 1, this->data); } -bool BluetoothLERawAdvertisementsResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->advertisements.emplace_back(); - value.decode_to_message(this->advertisements.back()); - break; - default: - return false; - } - return true; -} void BluetoothLERawAdvertisementsResponse::encode(ProtoWriteBuffer buffer) const { for (auto &it : this->advertisements) { buffer.encode_message(1, it, true); @@ -3882,37 +1925,6 @@ bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, ProtoVarInt value) } return true; } -void BluetoothDeviceRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint64(1, this->address); - buffer.encode_uint32(2, static_cast(this->request_type)); - buffer.encode_bool(3, this->has_address_type); - buffer.encode_uint32(4, this->address_type); -} -void BluetoothDeviceRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->request_type)); - ProtoSize::add_bool_field(total_size, 1, this->has_address_type); - ProtoSize::add_uint32_field(total_size, 1, this->address_type); -} -bool BluetoothDeviceConnectionResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->connected = value.as_bool(); - break; - case 3: - this->mtu = value.as_uint32(); - break; - case 4: - this->error = value.as_int32(); - break; - default: - return false; - } - return true; -} void BluetoothDeviceConnectionResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bool(2, this->connected); @@ -3935,10 +1947,6 @@ bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarI } return true; } -void BluetoothGATTGetServicesRequest::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); } -void BluetoothGATTGetServicesRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); -} bool BluetoothGATTDescriptor::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 1: @@ -4055,27 +2063,6 @@ void BluetoothGATTService::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint32_field(total_size, 1, this->handle); ProtoSize::add_repeated_message(total_size, 1, this->characteristics); } -bool BluetoothGATTGetServicesResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - default: - return false; - } - return true; -} -bool BluetoothGATTGetServicesResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->services.emplace_back(); - value.decode_to_message(this->services.back()); - break; - default: - return false; - } - return true; -} void BluetoothGATTGetServicesResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); for (auto &it : this->services) { @@ -4086,16 +2073,6 @@ void BluetoothGATTGetServicesResponse::calculate_size(uint32_t &total_size) cons ProtoSize::add_uint64_field(total_size, 1, this->address); ProtoSize::add_repeated_message(total_size, 1, this->services); } -bool BluetoothGATTGetServicesDoneResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - default: - return false; - } - return true; -} void BluetoothGATTGetServicesDoneResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); } @@ -4115,37 +2092,6 @@ bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, ProtoVarInt valu } return true; } -void BluetoothGATTReadRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint64(1, this->address); - buffer.encode_uint32(2, this->handle); -} -void BluetoothGATTReadRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); -} -bool BluetoothGATTReadResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->handle = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool BluetoothGATTReadResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 3: - this->data = value.as_string(); - break; - default: - return false; - } - return true; -} void BluetoothGATTReadResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_uint32(2, this->handle); @@ -4182,18 +2128,6 @@ bool BluetoothGATTWriteRequest::decode_length(uint32_t field_id, ProtoLengthDeli } return true; } -void BluetoothGATTWriteRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint64(1, this->address); - buffer.encode_uint32(2, this->handle); - buffer.encode_bool(3, this->response); - buffer.encode_bytes(4, reinterpret_cast(this->data.data()), this->data.size()); -} -void BluetoothGATTWriteRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_bool_field(total_size, 1, this->response); - ProtoSize::add_string_field(total_size, 1, this->data); -} bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 1: @@ -4207,14 +2141,6 @@ bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, ProtoV } return true; } -void BluetoothGATTReadDescriptorRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint64(1, this->address); - buffer.encode_uint32(2, this->handle); -} -void BluetoothGATTReadDescriptorRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); -} bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 1: @@ -4238,16 +2164,6 @@ bool BluetoothGATTWriteDescriptorRequest::decode_length(uint32_t field_id, Proto } return true; } -void BluetoothGATTWriteDescriptorRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint64(1, this->address); - buffer.encode_uint32(2, this->handle); - buffer.encode_bytes(3, reinterpret_cast(this->data.data()), this->data.size()); -} -void BluetoothGATTWriteDescriptorRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_string_field(total_size, 1, this->data); -} bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 1: @@ -4264,39 +2180,6 @@ bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, ProtoVarInt va } return true; } -void BluetoothGATTNotifyRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint64(1, this->address); - buffer.encode_uint32(2, this->handle); - buffer.encode_bool(3, this->enable); -} -void BluetoothGATTNotifyRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_bool_field(total_size, 1, this->enable); -} -bool BluetoothGATTNotifyDataResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->handle = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool BluetoothGATTNotifyDataResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 3: - this->data = value.as_string(); - break; - default: - return false; - } - return true; -} void BluetoothGATTNotifyDataResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_uint32(2, this->handle); @@ -4307,22 +2190,6 @@ void BluetoothGATTNotifyDataResponse::calculate_size(uint32_t &total_size) const ProtoSize::add_uint32_field(total_size, 1, this->handle); ProtoSize::add_string_field(total_size, 1, this->data); } -bool BluetoothConnectionsFreeResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->free = value.as_uint32(); - break; - case 2: - this->limit = value.as_uint32(); - break; - case 3: - this->allocated.push_back(value.as_uint64()); - break; - default: - return false; - } - return true; -} void BluetoothConnectionsFreeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, this->free); buffer.encode_uint32(2, this->limit); @@ -4339,22 +2206,6 @@ void BluetoothConnectionsFreeResponse::calculate_size(uint32_t &total_size) cons } } } -bool BluetoothGATTErrorResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->handle = value.as_uint32(); - break; - case 3: - this->error = value.as_int32(); - break; - default: - return false; - } - return true; -} void BluetoothGATTErrorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_uint32(2, this->handle); @@ -4365,19 +2216,6 @@ void BluetoothGATTErrorResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint32_field(total_size, 1, this->handle); ProtoSize::add_int32_field(total_size, 1, this->error); } -bool BluetoothGATTWriteResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->handle = value.as_uint32(); - break; - default: - return false; - } - return true; -} void BluetoothGATTWriteResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_uint32(2, this->handle); @@ -4386,19 +2224,6 @@ void BluetoothGATTWriteResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint64_field(total_size, 1, this->address); ProtoSize::add_uint32_field(total_size, 1, this->handle); } -bool BluetoothGATTNotifyResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->handle = value.as_uint32(); - break; - default: - return false; - } - return true; -} void BluetoothGATTNotifyResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_uint32(2, this->handle); @@ -4407,22 +2232,6 @@ void BluetoothGATTNotifyResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint64_field(total_size, 1, this->address); ProtoSize::add_uint32_field(total_size, 1, this->handle); } -bool BluetoothDevicePairingResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->paired = value.as_bool(); - break; - case 3: - this->error = value.as_int32(); - break; - default: - return false; - } - return true; -} void BluetoothDevicePairingResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bool(2, this->paired); @@ -4433,22 +2242,6 @@ void BluetoothDevicePairingResponse::calculate_size(uint32_t &total_size) const ProtoSize::add_bool_field(total_size, 1, this->paired); ProtoSize::add_int32_field(total_size, 1, this->error); } -bool BluetoothDeviceUnpairingResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->success = value.as_bool(); - break; - case 3: - this->error = value.as_int32(); - break; - default: - return false; - } - return true; -} void BluetoothDeviceUnpairingResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bool(2, this->success); @@ -4459,22 +2252,6 @@ void BluetoothDeviceUnpairingResponse::calculate_size(uint32_t &total_size) cons ProtoSize::add_bool_field(total_size, 1, this->success); ProtoSize::add_int32_field(total_size, 1, this->error); } -bool BluetoothDeviceClearCacheResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->address = value.as_uint64(); - break; - case 2: - this->success = value.as_bool(); - break; - case 3: - this->error = value.as_int32(); - break; - default: - return false; - } - return true; -} void BluetoothDeviceClearCacheResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bool(2, this->success); @@ -4485,19 +2262,6 @@ void BluetoothDeviceClearCacheResponse::calculate_size(uint32_t &total_size) con ProtoSize::add_bool_field(total_size, 1, this->success); ProtoSize::add_int32_field(total_size, 1, this->error); } -bool BluetoothScannerStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->state = static_cast(value.as_uint32()); - break; - case 2: - this->mode = static_cast(value.as_uint32()); - break; - default: - return false; - } - return true; -} void BluetoothScannerStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, static_cast(this->state)); buffer.encode_uint32(2, static_cast(this->mode)); @@ -4516,12 +2280,6 @@ bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, ProtoVarIn } return true; } -void BluetoothScannerSetModeRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint32(1, static_cast(this->mode)); -} -void BluetoothScannerSetModeRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); -} #endif #ifdef USE_VOICE_ASSISTANT bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -4537,14 +2295,6 @@ bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarIn } return true; } -void SubscribeVoiceAssistantRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_bool(1, this->subscribe); - buffer.encode_uint32(2, this->flags); -} -void SubscribeVoiceAssistantRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_bool_field(total_size, 1, this->subscribe); - ProtoSize::add_uint32_field(total_size, 1, this->flags); -} bool VoiceAssistantAudioSettings::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 1: @@ -4578,35 +2328,6 @@ void VoiceAssistantAudioSettings::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint32_field(total_size, 1, this->auto_gain); ProtoSize::add_fixed_field<4>(total_size, 1, this->volume_multiplier != 0.0f); } -bool VoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->start = value.as_bool(); - break; - case 3: - this->flags = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool VoiceAssistantRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->conversation_id = value.as_string(); - break; - case 4: - value.decode_to_message(this->audio_settings); - break; - case 5: - this->wake_word_phrase = value.as_string(); - break; - default: - return false; - } - return true; -} void VoiceAssistantRequest::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->start); buffer.encode_string(2, this->conversation_id); @@ -4634,14 +2355,6 @@ bool VoiceAssistantResponse::decode_varint(uint32_t field_id, ProtoVarInt value) } return true; } -void VoiceAssistantResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint32(1, this->port); - buffer.encode_bool(2, this->error); -} -void VoiceAssistantResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint32_field(total_size, 1, this->port); - ProtoSize::add_bool_field(total_size, 1, this->error); -} bool VoiceAssistantEventData::decode_length(uint32_t field_id, ProtoLengthDelimited value) { switch (field_id) { case 1: @@ -4684,16 +2397,6 @@ bool VoiceAssistantEventResponse::decode_length(uint32_t field_id, ProtoLengthDe } return true; } -void VoiceAssistantEventResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint32(1, static_cast(this->event_type)); - for (auto &it : this->data) { - buffer.encode_message(2, it, true); - } -} -void VoiceAssistantEventResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_enum_field(total_size, 1, static_cast(this->event_type)); - ProtoSize::add_repeated_message(total_size, 1, this->data); -} bool VoiceAssistantAudio::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 2: @@ -4754,22 +2457,6 @@ bool VoiceAssistantTimerEventResponse::decode_length(uint32_t field_id, ProtoLen } return true; } -void VoiceAssistantTimerEventResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_uint32(1, static_cast(this->event_type)); - buffer.encode_string(2, this->timer_id); - buffer.encode_string(3, this->name); - buffer.encode_uint32(4, this->total_seconds); - buffer.encode_uint32(5, this->seconds_left); - buffer.encode_bool(6, this->is_active); -} -void VoiceAssistantTimerEventResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_enum_field(total_size, 1, static_cast(this->event_type)); - ProtoSize::add_string_field(total_size, 1, this->timer_id); - ProtoSize::add_string_field(total_size, 1, this->name); - ProtoSize::add_uint32_field(total_size, 1, this->total_seconds); - ProtoSize::add_uint32_field(total_size, 1, this->seconds_left); - ProtoSize::add_bool_field(total_size, 1, this->is_active); -} bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { case 4: @@ -4796,28 +2483,6 @@ bool VoiceAssistantAnnounceRequest::decode_length(uint32_t field_id, ProtoLength } return true; } -void VoiceAssistantAnnounceRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->media_id); - buffer.encode_string(2, this->text); - buffer.encode_string(3, this->preannounce_media_id); - buffer.encode_bool(4, this->start_conversation); -} -void VoiceAssistantAnnounceRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->media_id); - ProtoSize::add_string_field(total_size, 1, this->text); - ProtoSize::add_string_field(total_size, 1, this->preannounce_media_id); - ProtoSize::add_bool_field(total_size, 1, this->start_conversation); -} -bool VoiceAssistantAnnounceFinished::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 1: - this->success = value.as_bool(); - break; - default: - return false; - } - return true; -} void VoiceAssistantAnnounceFinished::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->success); } void VoiceAssistantAnnounceFinished::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->success); @@ -4854,30 +2519,6 @@ void VoiceAssistantWakeWord::calculate_size(uint32_t &total_size) const { } } } -bool VoiceAssistantConfigurationResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->max_active_wake_words = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool VoiceAssistantConfigurationResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->available_wake_words.emplace_back(); - value.decode_to_message(this->available_wake_words.back()); - break; - case 2: - this->active_wake_words.push_back(value.as_string()); - break; - default: - return false; - } - return true; -} void VoiceAssistantConfigurationResponse::encode(ProtoWriteBuffer buffer) const { for (auto &it : this->available_wake_words) { buffer.encode_message(1, it, true); @@ -4906,74 +2547,8 @@ bool VoiceAssistantSetConfiguration::decode_length(uint32_t field_id, ProtoLengt } return true; } -void VoiceAssistantSetConfiguration::encode(ProtoWriteBuffer buffer) const { - for (auto &it : this->active_wake_words) { - buffer.encode_string(1, it, true); - } -} -void VoiceAssistantSetConfiguration::calculate_size(uint32_t &total_size) const { - if (!this->active_wake_words.empty()) { - for (const auto &it : this->active_wake_words) { - ProtoSize::add_string_field_repeated(total_size, 1, it); - } - } -} #endif #ifdef USE_ALARM_CONTROL_PANEL -bool ListEntitiesAlarmControlPanelResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->supported_features = value.as_uint32(); - break; - case 9: - this->requires_code = value.as_bool(); - break; - case 10: - this->requires_code_to_arm = value.as_bool(); - break; - case 11: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesAlarmControlPanelResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesAlarmControlPanelResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesAlarmControlPanelResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -5000,29 +2575,6 @@ void ListEntitiesAlarmControlPanelResponse::calculate_size(uint32_t &total_size) ProtoSize::add_bool_field(total_size, 1, this->requires_code_to_arm); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool AlarmControlPanelStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->state = static_cast(value.as_uint32()); - break; - case 3: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool AlarmControlPanelStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void AlarmControlPanelStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_uint32(2, static_cast(this->state)); @@ -5066,77 +2618,8 @@ bool AlarmControlPanelCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit } return true; } -void AlarmControlPanelCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_uint32(2, static_cast(this->command)); - buffer.encode_string(3, this->code); - buffer.encode_uint32(4, this->device_id); -} -void AlarmControlPanelCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->command)); - ProtoSize::add_string_field(total_size, 1, this->code); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_TEXT -bool ListEntitiesTextResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->min_length = value.as_uint32(); - break; - case 9: - this->max_length = value.as_uint32(); - break; - case 11: - this->mode = static_cast(value.as_uint32()); - break; - case 12: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesTextResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 10: - this->pattern = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesTextResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesTextResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -5165,39 +2648,6 @@ void ListEntitiesTextResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool TextStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->missing_state = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool TextStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->state = value.as_string(); - break; - default: - return false; - } - return true; -} -bool TextStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void TextStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_string(2, this->state); @@ -5240,63 +2690,8 @@ bool TextCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void TextCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_string(2, this->state); - buffer.encode_uint32(3, this->device_id); -} -void TextCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_string_field(total_size, 1, this->state); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_DATETIME_DATE -bool ListEntitiesDateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesDateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesDateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesDateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -5317,38 +2712,6 @@ void ListEntitiesDateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool DateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->missing_state = value.as_bool(); - break; - case 3: - this->year = value.as_uint32(); - break; - case 4: - this->month = value.as_uint32(); - break; - case 5: - this->day = value.as_uint32(); - break; - case 6: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool DateStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void DateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->missing_state); @@ -5394,67 +2757,8 @@ bool DateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void DateCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_uint32(2, this->year); - buffer.encode_uint32(3, this->month); - buffer.encode_uint32(4, this->day); - buffer.encode_uint32(5, this->device_id); -} -void DateCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_uint32_field(total_size, 1, this->year); - ProtoSize::add_uint32_field(total_size, 1, this->month); - ProtoSize::add_uint32_field(total_size, 1, this->day); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_DATETIME_TIME -bool ListEntitiesTimeResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesTimeResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesTimeResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesTimeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -5475,38 +2779,6 @@ void ListEntitiesTimeResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool TimeStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->missing_state = value.as_bool(); - break; - case 3: - this->hour = value.as_uint32(); - break; - case 4: - this->minute = value.as_uint32(); - break; - case 5: - this->second = value.as_uint32(); - break; - case 6: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool TimeStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void TimeStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->missing_state); @@ -5552,73 +2824,8 @@ bool TimeCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void TimeCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_uint32(2, this->hour); - buffer.encode_uint32(3, this->minute); - buffer.encode_uint32(4, this->second); - buffer.encode_uint32(5, this->device_id); -} -void TimeCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_uint32_field(total_size, 1, this->hour); - ProtoSize::add_uint32_field(total_size, 1, this->minute); - ProtoSize::add_uint32_field(total_size, 1, this->second); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_EVENT -bool ListEntitiesEventResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 10: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesEventResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 8: - this->device_class = value.as_string(); - break; - case 9: - this->event_types.push_back(value.as_string()); - break; - default: - return false; - } - return true; -} -bool ListEntitiesEventResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesEventResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -5649,36 +2856,6 @@ void ListEntitiesEventResponse::calculate_size(uint32_t &total_size) const { } ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool EventResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool EventResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 2: - this->event_type = value.as_string(); - break; - default: - return false; - } - return true; -} -bool EventResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void EventResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_string(2, this->event_type); @@ -5691,63 +2868,6 @@ void EventResponse::calculate_size(uint32_t &total_size) const { } #endif #ifdef USE_VALVE -bool ListEntitiesValveResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 9: - this->assumed_state = value.as_bool(); - break; - case 10: - this->supports_position = value.as_bool(); - break; - case 11: - this->supports_stop = value.as_bool(); - break; - case 12: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesValveResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 8: - this->device_class = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesValveResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesValveResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -5776,32 +2896,6 @@ void ListEntitiesValveResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->supports_stop); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool ValveStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 3: - this->current_operation = static_cast(value.as_uint32()); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ValveStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 2: - this->position = value.as_float(); - break; - default: - return false; - } - return true; -} void ValveStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_float(2, this->position); @@ -5843,67 +2937,8 @@ bool ValveCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void ValveCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_bool(2, this->has_position); - buffer.encode_float(3, this->position); - buffer.encode_bool(4, this->stop); - buffer.encode_uint32(5, this->device_id); -} -void ValveCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_bool_field(total_size, 1, this->has_position); - ProtoSize::add_fixed_field<4>(total_size, 1, this->position != 0.0f); - ProtoSize::add_bool_field(total_size, 1, this->stop); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_DATETIME_DATETIME -bool ListEntitiesDateTimeResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 8: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesDateTimeResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesDateTimeResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesDateTimeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -5924,32 +2959,6 @@ void ListEntitiesDateTimeResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool DateTimeStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->missing_state = value.as_bool(); - break; - case 4: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool DateTimeStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 3: - this->epoch_seconds = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void DateTimeStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->missing_state); @@ -5985,66 +2994,8 @@ bool DateTimeCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void DateTimeCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_fixed32(2, this->epoch_seconds); - buffer.encode_uint32(3, this->device_id); -} -void DateTimeCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_fixed_field<4>(total_size, 1, this->epoch_seconds != 0); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif #ifdef USE_UPDATE -bool ListEntitiesUpdateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 6: - this->disabled_by_default = value.as_bool(); - break; - case 7: - this->entity_category = static_cast(value.as_uint32()); - break; - case 9: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesUpdateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 1: - this->object_id = value.as_string(); - break; - case 3: - this->name = value.as_string(); - break; - case 4: - this->unique_id = value.as_string(); - break; - case 5: - this->icon = value.as_string(); - break; - case 8: - this->device_class = value.as_string(); - break; - default: - return false; - } - return true; -} -bool ListEntitiesUpdateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 2: - this->key = value.as_fixed32(); - break; - default: - return false; - } - return true; -} void ListEntitiesUpdateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id); buffer.encode_fixed32(2, this->key); @@ -6067,60 +3018,6 @@ void ListEntitiesUpdateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_string_field(total_size, 1, this->device_class); ProtoSize::add_uint32_field(total_size, 1, this->device_id); } -bool UpdateStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { - switch (field_id) { - case 2: - this->missing_state = value.as_bool(); - break; - case 3: - this->in_progress = value.as_bool(); - break; - case 4: - this->has_progress = value.as_bool(); - break; - case 11: - this->device_id = value.as_uint32(); - break; - default: - return false; - } - return true; -} -bool UpdateStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { - switch (field_id) { - case 6: - this->current_version = value.as_string(); - break; - case 7: - this->latest_version = value.as_string(); - break; - case 8: - this->title = value.as_string(); - break; - case 9: - this->release_summary = value.as_string(); - break; - case 10: - this->release_url = value.as_string(); - break; - default: - return false; - } - return true; -} -bool UpdateStateResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { - switch (field_id) { - case 1: - this->key = value.as_fixed32(); - break; - case 5: - this->progress = value.as_float(); - break; - default: - return false; - } - return true; -} void UpdateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); buffer.encode_bool(2, this->missing_state); @@ -6170,16 +3067,6 @@ bool UpdateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { } return true; } -void UpdateCommandRequest::encode(ProtoWriteBuffer buffer) const { - buffer.encode_fixed32(1, this->key); - buffer.encode_uint32(2, static_cast(this->command)); - buffer.encode_uint32(3, this->device_id); -} -void UpdateCommandRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed_field<4>(total_size, 1, this->key != 0); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->command)); - ProtoSize::add_uint32_field(total_size, 1, this->device_id); -} #endif } // namespace api diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index 3c4e0dfb6d..3f2d4afad3 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -5,7 +5,6 @@ #include "esphome/core/defines.h" #include "proto.h" -#include "api_pb2_size.h" namespace esphome { namespace api { @@ -82,6 +81,7 @@ enum LogLevel : uint32_t { LOG_LEVEL_VERBOSE = 6, LOG_LEVEL_VERY_VERBOSE = 7, }; +#ifdef USE_API_SERVICES enum ServiceArgType : uint32_t { SERVICE_ARG_TYPE_BOOL = 0, SERVICE_ARG_TYPE_INT = 1, @@ -92,6 +92,7 @@ enum ServiceArgType : uint32_t { SERVICE_ARG_TYPE_FLOAT_ARRAY = 6, SERVICE_ARG_TYPE_STRING_ARRAY = 7, }; +#endif #ifdef USE_CLIMATE enum ClimateMode : uint32_t { CLIMATE_MODE_OFF = 0, @@ -326,8 +327,6 @@ class HelloRequest : public ProtoMessage { std::string client_info{}; uint32_t api_version_major{0}; uint32_t api_version_minor{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -354,8 +353,6 @@ class HelloResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class ConnectRequest : public ProtoMessage { public: @@ -365,8 +362,6 @@ class ConnectRequest : public ProtoMessage { const char *message_name() const override { return "connect_request"; } #endif std::string password{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -389,7 +384,6 @@ class ConnectResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class DisconnectRequest : public ProtoMessage { public: @@ -521,8 +515,6 @@ class DeviceInfoResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class ListEntitiesRequest : public ProtoMessage { public: @@ -580,9 +572,6 @@ class ListEntitiesBinarySensorResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BinarySensorStateResponse : public StateResponseProtoMessage { public: @@ -600,8 +589,6 @@ class BinarySensorStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; #endif #ifdef USE_COVER @@ -624,9 +611,6 @@ class ListEntitiesCoverResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class CoverStateResponse : public StateResponseProtoMessage { public: @@ -646,8 +630,6 @@ class CoverStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class CoverCommandRequest : public CommandProtoMessage { public: @@ -663,8 +645,6 @@ class CoverCommandRequest : public CommandProtoMessage { bool has_tilt{false}; float tilt{0.0f}; bool stop{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -694,9 +674,6 @@ class ListEntitiesFanResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class FanStateResponse : public StateResponseProtoMessage { public: @@ -718,9 +695,6 @@ class FanStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class FanCommandRequest : public CommandProtoMessage { public: @@ -741,8 +715,6 @@ class FanCommandRequest : public CommandProtoMessage { int32_t speed_level{0}; bool has_preset_mode{false}; std::string preset_mode{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -776,9 +748,6 @@ class ListEntitiesLightResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class LightStateResponse : public StateResponseProtoMessage { public: @@ -806,9 +775,6 @@ class LightStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class LightCommandRequest : public CommandProtoMessage { public: @@ -843,8 +809,6 @@ class LightCommandRequest : public CommandProtoMessage { uint32_t flash_length{0}; bool has_effect{false}; std::string effect{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -876,9 +840,6 @@ class ListEntitiesSensorResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SensorStateResponse : public StateResponseProtoMessage { public: @@ -896,8 +857,6 @@ class SensorStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; #endif #ifdef USE_SWITCH @@ -917,9 +876,6 @@ class ListEntitiesSwitchResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SwitchStateResponse : public StateResponseProtoMessage { public: @@ -936,8 +892,6 @@ class SwitchStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SwitchCommandRequest : public CommandProtoMessage { public: @@ -947,8 +901,6 @@ class SwitchCommandRequest : public CommandProtoMessage { const char *message_name() const override { return "switch_command_request"; } #endif bool state{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -974,9 +926,6 @@ class ListEntitiesTextSensorResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class TextSensorStateResponse : public StateResponseProtoMessage { public: @@ -994,9 +943,6 @@ class TextSensorStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; #endif class SubscribeLogsRequest : public ProtoMessage { @@ -1008,8 +954,6 @@ class SubscribeLogsRequest : public ProtoMessage { #endif enums::LogLevel level{}; bool dump_config{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1034,8 +978,6 @@ class SubscribeLogsResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; #ifdef USE_API_NOISE class NoiseEncryptionSetKeyRequest : public ProtoMessage { @@ -1046,8 +988,6 @@ class NoiseEncryptionSetKeyRequest : public ProtoMessage { const char *message_name() const override { return "noise_encryption_set_key_request"; } #endif std::string key{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1070,7 +1010,6 @@ class NoiseEncryptionSetKeyResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; #endif class SubscribeHomeassistantServicesRequest : public ProtoMessage { @@ -1118,8 +1057,6 @@ class HomeassistantServiceResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SubscribeHomeAssistantStatesRequest : public ProtoMessage { public: @@ -1151,8 +1088,6 @@ class SubscribeHomeAssistantStateResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class HomeAssistantStateResponse : public ProtoMessage { public: @@ -1164,8 +1099,6 @@ class HomeAssistantStateResponse : public ProtoMessage { std::string entity_id{}; std::string state{}; std::string attribute{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1203,6 +1136,7 @@ class GetTimeResponse : public ProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; }; +#ifdef USE_API_SERVICES class ListEntitiesServicesArgument : public ProtoMessage { public: std::string name{}; @@ -1234,8 +1168,6 @@ class ListEntitiesServicesResponse : public ProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; }; class ExecuteServiceArgument : public ProtoMessage { public: @@ -1268,8 +1200,6 @@ class ExecuteServiceRequest : public ProtoMessage { #endif uint32_t key{0}; std::vector args{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1278,6 +1208,7 @@ class ExecuteServiceRequest : public ProtoMessage { bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; }; +#endif #ifdef USE_CAMERA class ListEntitiesCameraResponse : public InfoResponseProtoMessage { public: @@ -1293,9 +1224,6 @@ class ListEntitiesCameraResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class CameraImageResponse : public StateResponseProtoMessage { public: @@ -1313,9 +1241,6 @@ class CameraImageResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class CameraImageRequest : public ProtoMessage { public: @@ -1326,8 +1251,6 @@ class CameraImageRequest : public ProtoMessage { #endif bool single{false}; bool stream{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1369,9 +1292,6 @@ class ListEntitiesClimateResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class ClimateStateResponse : public StateResponseProtoMessage { public: @@ -1401,9 +1321,6 @@ class ClimateStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class ClimateCommandRequest : public CommandProtoMessage { public: @@ -1434,8 +1351,6 @@ class ClimateCommandRequest : public CommandProtoMessage { std::string custom_preset{}; bool has_target_humidity{false}; float target_humidity{0.0f}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1467,9 +1382,6 @@ class ListEntitiesNumberResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class NumberStateResponse : public StateResponseProtoMessage { public: @@ -1487,8 +1399,6 @@ class NumberStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class NumberCommandRequest : public CommandProtoMessage { public: @@ -1498,8 +1408,6 @@ class NumberCommandRequest : public CommandProtoMessage { const char *message_name() const override { return "number_command_request"; } #endif float state{0.0f}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1525,9 +1433,6 @@ class ListEntitiesSelectResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SelectStateResponse : public StateResponseProtoMessage { public: @@ -1545,9 +1450,6 @@ class SelectStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SelectCommandRequest : public CommandProtoMessage { public: @@ -1557,8 +1459,6 @@ class SelectCommandRequest : public CommandProtoMessage { const char *message_name() const override { return "select_command_request"; } #endif std::string state{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1587,9 +1487,6 @@ class ListEntitiesSirenResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SirenStateResponse : public StateResponseProtoMessage { public: @@ -1606,8 +1503,6 @@ class SirenStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SirenCommandRequest : public CommandProtoMessage { public: @@ -1624,8 +1519,6 @@ class SirenCommandRequest : public CommandProtoMessage { uint32_t duration{0}; bool has_volume{false}; float volume{0.0f}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1655,9 +1548,6 @@ class ListEntitiesLockResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class LockStateResponse : public StateResponseProtoMessage { public: @@ -1674,8 +1564,6 @@ class LockStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class LockCommandRequest : public CommandProtoMessage { public: @@ -1687,8 +1575,6 @@ class LockCommandRequest : public CommandProtoMessage { enums::LockCommand command{}; bool has_code{false}; std::string code{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1715,9 +1601,6 @@ class ListEntitiesButtonResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class ButtonCommandRequest : public CommandProtoMessage { public: @@ -1726,8 +1609,6 @@ class ButtonCommandRequest : public CommandProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "button_command_request"; } #endif - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1771,9 +1652,6 @@ class ListEntitiesMediaPlayerResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class MediaPlayerStateResponse : public StateResponseProtoMessage { public: @@ -1792,8 +1670,6 @@ class MediaPlayerStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class MediaPlayerCommandRequest : public CommandProtoMessage { public: @@ -1810,8 +1686,6 @@ class MediaPlayerCommandRequest : public CommandProtoMessage { std::string media_url{}; bool has_announcement{false}; bool announcement{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1831,8 +1705,6 @@ class SubscribeBluetoothLEAdvertisementsRequest : public ProtoMessage { const char *message_name() const override { return "subscribe_bluetooth_le_advertisements_request"; } #endif uint32_t flags{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1876,8 +1748,6 @@ class BluetoothLEAdvertisementResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothLERawAdvertisement : public ProtoMessage { public: @@ -1910,7 +1780,6 @@ class BluetoothLERawAdvertisementsResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; }; class BluetoothDeviceRequest : public ProtoMessage { public: @@ -1923,8 +1792,6 @@ class BluetoothDeviceRequest : public ProtoMessage { enums::BluetoothDeviceRequestType request_type{}; bool has_address_type{false}; uint32_t address_type{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1950,7 +1817,6 @@ class BluetoothDeviceConnectionResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothGATTGetServicesRequest : public ProtoMessage { public: @@ -1960,8 +1826,6 @@ class BluetoothGATTGetServicesRequest : public ProtoMessage { const char *message_name() const override { return "bluetooth_gatt_get_services_request"; } #endif uint64_t address{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2029,8 +1893,6 @@ class BluetoothGATTGetServicesResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothGATTGetServicesDoneResponse : public ProtoMessage { public: @@ -2047,7 +1909,6 @@ class BluetoothGATTGetServicesDoneResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothGATTReadRequest : public ProtoMessage { public: @@ -2058,8 +1919,6 @@ class BluetoothGATTReadRequest : public ProtoMessage { #endif uint64_t address{0}; uint32_t handle{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2084,8 +1943,6 @@ class BluetoothGATTReadResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothGATTWriteRequest : public ProtoMessage { public: @@ -2098,8 +1955,6 @@ class BluetoothGATTWriteRequest : public ProtoMessage { uint32_t handle{0}; bool response{false}; std::string data{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2117,8 +1972,6 @@ class BluetoothGATTReadDescriptorRequest : public ProtoMessage { #endif uint64_t address{0}; uint32_t handle{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2136,8 +1989,6 @@ class BluetoothGATTWriteDescriptorRequest : public ProtoMessage { uint64_t address{0}; uint32_t handle{0}; std::string data{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2156,8 +2007,6 @@ class BluetoothGATTNotifyRequest : public ProtoMessage { uint64_t address{0}; uint32_t handle{0}; bool enable{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2182,8 +2031,6 @@ class BluetoothGATTNotifyDataResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class SubscribeBluetoothConnectionsFreeRequest : public ProtoMessage { public: @@ -2215,7 +2062,6 @@ class BluetoothConnectionsFreeResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothGATTErrorResponse : public ProtoMessage { public: @@ -2234,7 +2080,6 @@ class BluetoothGATTErrorResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothGATTWriteResponse : public ProtoMessage { public: @@ -2252,7 +2097,6 @@ class BluetoothGATTWriteResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothGATTNotifyResponse : public ProtoMessage { public: @@ -2270,7 +2114,6 @@ class BluetoothGATTNotifyResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothDevicePairingResponse : public ProtoMessage { public: @@ -2289,7 +2132,6 @@ class BluetoothDevicePairingResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothDeviceUnpairingResponse : public ProtoMessage { public: @@ -2308,7 +2150,6 @@ class BluetoothDeviceUnpairingResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class UnsubscribeBluetoothLEAdvertisementsRequest : public ProtoMessage { public: @@ -2340,7 +2181,6 @@ class BluetoothDeviceClearCacheResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothScannerStateResponse : public ProtoMessage { public: @@ -2358,7 +2198,6 @@ class BluetoothScannerStateResponse : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class BluetoothScannerSetModeRequest : public ProtoMessage { public: @@ -2368,8 +2207,6 @@ class BluetoothScannerSetModeRequest : public ProtoMessage { const char *message_name() const override { return "bluetooth_scanner_set_mode_request"; } #endif enums::BluetoothScannerMode mode{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2388,8 +2225,6 @@ class SubscribeVoiceAssistantRequest : public ProtoMessage { #endif bool subscribe{false}; uint32_t flags{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2431,8 +2266,6 @@ class VoiceAssistantRequest : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class VoiceAssistantResponse : public ProtoMessage { public: @@ -2443,8 +2276,6 @@ class VoiceAssistantResponse : public ProtoMessage { #endif uint32_t port{0}; bool error{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2474,8 +2305,6 @@ class VoiceAssistantEventResponse : public ProtoMessage { #endif enums::VoiceAssistantEvent event_type{}; std::vector data{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2516,8 +2345,6 @@ class VoiceAssistantTimerEventResponse : public ProtoMessage { uint32_t total_seconds{0}; uint32_t seconds_left{0}; bool is_active{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2537,8 +2364,6 @@ class VoiceAssistantAnnounceRequest : public ProtoMessage { std::string text{}; std::string preannounce_media_id{}; bool start_conversation{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2562,7 +2387,6 @@ class VoiceAssistantAnnounceFinished : public ProtoMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class VoiceAssistantWakeWord : public ProtoMessage { public: @@ -2608,8 +2432,6 @@ class VoiceAssistantConfigurationResponse : public ProtoMessage { #endif protected: - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class VoiceAssistantSetConfiguration : public ProtoMessage { public: @@ -2619,8 +2441,6 @@ class VoiceAssistantSetConfiguration : public ProtoMessage { const char *message_name() const override { return "voice_assistant_set_configuration"; } #endif std::vector active_wake_words{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2647,9 +2467,6 @@ class ListEntitiesAlarmControlPanelResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class AlarmControlPanelStateResponse : public StateResponseProtoMessage { public: @@ -2666,8 +2483,6 @@ class AlarmControlPanelStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class AlarmControlPanelCommandRequest : public CommandProtoMessage { public: @@ -2678,8 +2493,6 @@ class AlarmControlPanelCommandRequest : public CommandProtoMessage { #endif enums::AlarmControlPanelStateCommand command{}; std::string code{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2709,9 +2522,6 @@ class ListEntitiesTextResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class TextStateResponse : public StateResponseProtoMessage { public: @@ -2729,9 +2539,6 @@ class TextStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class TextCommandRequest : public CommandProtoMessage { public: @@ -2741,8 +2548,6 @@ class TextCommandRequest : public CommandProtoMessage { const char *message_name() const override { return "text_command_request"; } #endif std::string state{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2768,9 +2573,6 @@ class ListEntitiesDateResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class DateStateResponse : public StateResponseProtoMessage { public: @@ -2790,8 +2592,6 @@ class DateStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class DateCommandRequest : public CommandProtoMessage { public: @@ -2803,8 +2603,6 @@ class DateCommandRequest : public CommandProtoMessage { uint32_t year{0}; uint32_t month{0}; uint32_t day{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2829,9 +2627,6 @@ class ListEntitiesTimeResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class TimeStateResponse : public StateResponseProtoMessage { public: @@ -2851,8 +2646,6 @@ class TimeStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class TimeCommandRequest : public CommandProtoMessage { public: @@ -2864,8 +2657,6 @@ class TimeCommandRequest : public CommandProtoMessage { uint32_t hour{0}; uint32_t minute{0}; uint32_t second{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2892,9 +2683,6 @@ class ListEntitiesEventResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class EventResponse : public StateResponseProtoMessage { public: @@ -2911,9 +2699,6 @@ class EventResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; #endif #ifdef USE_VALVE @@ -2935,9 +2720,6 @@ class ListEntitiesValveResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class ValveStateResponse : public StateResponseProtoMessage { public: @@ -2955,8 +2737,6 @@ class ValveStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class ValveCommandRequest : public CommandProtoMessage { public: @@ -2968,8 +2748,6 @@ class ValveCommandRequest : public CommandProtoMessage { bool has_position{false}; float position{0.0f}; bool stop{false}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2994,9 +2772,6 @@ class ListEntitiesDateTimeResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class DateTimeStateResponse : public StateResponseProtoMessage { public: @@ -3014,8 +2789,6 @@ class DateTimeStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class DateTimeCommandRequest : public CommandProtoMessage { public: @@ -3025,8 +2798,6 @@ class DateTimeCommandRequest : public CommandProtoMessage { const char *message_name() const override { return "date_time_command_request"; } #endif uint32_t epoch_seconds{0}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -3052,9 +2823,6 @@ class ListEntitiesUpdateResponse : public InfoResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class UpdateStateResponse : public StateResponseProtoMessage { public: @@ -3079,9 +2847,6 @@ class UpdateStateResponse : public StateResponseProtoMessage { #endif protected: - bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; }; class UpdateCommandRequest : public CommandProtoMessage { public: @@ -3091,8 +2856,6 @@ class UpdateCommandRequest : public CommandProtoMessage { const char *message_name() const override { return "update_command_request"; } #endif enums::UpdateCommand command{}; - void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif diff --git a/esphome/components/api/api_pb2_dump.cpp b/esphome/components/api/api_pb2_dump.cpp index 7991e20bc5..f6509f47cc 100644 --- a/esphome/components/api/api_pb2_dump.cpp +++ b/esphome/components/api/api_pb2_dump.cpp @@ -162,6 +162,7 @@ template<> const char *proto_enum_to_string(enums::LogLevel val return "UNKNOWN"; } } +#ifdef USE_API_SERVICES template<> const char *proto_enum_to_string(enums::ServiceArgType value) { switch (value) { case enums::SERVICE_ARG_TYPE_BOOL: @@ -184,6 +185,7 @@ template<> const char *proto_enum_to_string(enums::Servic return "UNKNOWN"; } } +#endif #ifdef USE_CLIMATE template<> const char *proto_enum_to_string(enums::ClimateMode value) { switch (value) { @@ -1811,6 +1813,7 @@ void GetTimeResponse::dump_to(std::string &out) const { out.append("\n"); out.append("}"); } +#ifdef USE_API_SERVICES void ListEntitiesServicesArgument::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesServicesArgument {\n"); @@ -1910,6 +1913,7 @@ void ExecuteServiceRequest::dump_to(std::string &out) const { } out.append("}"); } +#endif #ifdef USE_CAMERA void ListEntitiesCameraResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; diff --git a/esphome/components/api/api_pb2_service.cpp b/esphome/components/api/api_pb2_service.cpp index 92dd90053b..b96e5736a4 100644 --- a/esphome/components/api/api_pb2_service.cpp +++ b/esphome/components/api/api_pb2_service.cpp @@ -195,6 +195,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, this->on_home_assistant_state_response(msg); break; } +#ifdef USE_API_SERVICES case 42: { ExecuteServiceRequest msg; msg.decode(msg_data, msg_size); @@ -204,6 +205,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, this->on_execute_service_request(msg); break; } +#endif #ifdef USE_CAMERA case 45: { CameraImageRequest msg; @@ -660,11 +662,13 @@ void APIServerConnection::on_get_time_request(const GetTimeRequest &msg) { } } } +#ifdef USE_API_SERVICES void APIServerConnection::on_execute_service_request(const ExecuteServiceRequest &msg) { if (this->check_authenticated_()) { this->execute_service(msg); } } +#endif #ifdef USE_API_NOISE void APIServerConnection::on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg) { if (this->check_authenticated_()) { diff --git a/esphome/components/api/api_pb2_service.h b/esphome/components/api/api_pb2_service.h index 458f8ec81b..9c5dc244fe 100644 --- a/esphome/components/api/api_pb2_service.h +++ b/esphome/components/api/api_pb2_service.h @@ -69,7 +69,9 @@ class APIServerConnectionBase : public ProtoService { virtual void on_get_time_request(const GetTimeRequest &value){}; virtual void on_get_time_response(const GetTimeResponse &value){}; +#ifdef USE_API_SERVICES virtual void on_execute_service_request(const ExecuteServiceRequest &value){}; +#endif #ifdef USE_CAMERA virtual void on_camera_image_request(const CameraImageRequest &value){}; @@ -216,7 +218,9 @@ class APIServerConnection : public APIServerConnectionBase { virtual void subscribe_homeassistant_services(const SubscribeHomeassistantServicesRequest &msg) = 0; virtual void subscribe_home_assistant_states(const SubscribeHomeAssistantStatesRequest &msg) = 0; virtual GetTimeResponse get_time(const GetTimeRequest &msg) = 0; +#ifdef USE_API_SERVICES virtual void execute_service(const ExecuteServiceRequest &msg) = 0; +#endif #ifdef USE_API_NOISE virtual NoiseEncryptionSetKeyResponse noise_encryption_set_key(const NoiseEncryptionSetKeyRequest &msg) = 0; #endif @@ -333,7 +337,9 @@ class APIServerConnection : public APIServerConnectionBase { void on_subscribe_homeassistant_services_request(const SubscribeHomeassistantServicesRequest &msg) override; void on_subscribe_home_assistant_states_request(const SubscribeHomeAssistantStatesRequest &msg) override; void on_get_time_request(const GetTimeRequest &msg) override; +#ifdef USE_API_SERVICES void on_execute_service_request(const ExecuteServiceRequest &msg) override; +#endif #ifdef USE_API_NOISE void on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg) override; #endif diff --git a/esphome/components/api/api_pb2_size.h b/esphome/components/api/api_pb2_size.h deleted file mode 100644 index dfa1452fff..0000000000 --- a/esphome/components/api/api_pb2_size.h +++ /dev/null @@ -1,469 +0,0 @@ -#pragma once - -#include "proto.h" -#include -#include - -namespace esphome { -namespace api { - -class ProtoSize { - public: - /** - * @brief ProtoSize class for Protocol Buffer serialization size calculation - * - * This class provides static methods to calculate the exact byte counts needed - * for encoding various Protocol Buffer field types. All methods are designed to be - * efficient for the common case where many fields have default values. - * - * Implements Protocol Buffer encoding size calculation according to: - * https://protobuf.dev/programming-guides/encoding/ - * - * Key features: - * - Early-return optimization for zero/default values - * - Direct total_size updates to avoid unnecessary additions - * - Specialized handling for different field types according to protobuf spec - * - Templated helpers for repeated fields and messages - */ - - /** - * @brief Calculates the size in bytes needed to encode a uint32_t value as a varint - * - * @param value The uint32_t value to calculate size for - * @return The number of bytes needed to encode the value - */ - static inline uint32_t varint(uint32_t value) { - // Optimized varint size calculation using leading zeros - // Each 7 bits requires one byte in the varint encoding - if (value < 128) - return 1; // 7 bits, common case for small values - - // For larger values, count bytes needed based on the position of the highest bit set - if (value < 16384) { - return 2; // 14 bits - } else if (value < 2097152) { - return 3; // 21 bits - } else if (value < 268435456) { - return 4; // 28 bits - } else { - return 5; // 32 bits (maximum for uint32_t) - } - } - - /** - * @brief Calculates the size in bytes needed to encode a uint64_t value as a varint - * - * @param value The uint64_t value to calculate size for - * @return The number of bytes needed to encode the value - */ - static inline uint32_t varint(uint64_t value) { - // Handle common case of values fitting in uint32_t (vast majority of use cases) - if (value <= UINT32_MAX) { - return varint(static_cast(value)); - } - - // For larger values, determine size based on highest bit position - if (value < (1ULL << 35)) { - return 5; // 35 bits - } else if (value < (1ULL << 42)) { - return 6; // 42 bits - } else if (value < (1ULL << 49)) { - return 7; // 49 bits - } else if (value < (1ULL << 56)) { - return 8; // 56 bits - } else if (value < (1ULL << 63)) { - return 9; // 63 bits - } else { - return 10; // 64 bits (maximum for uint64_t) - } - } - - /** - * @brief Calculates the size in bytes needed to encode an int32_t value as a varint - * - * Special handling is needed for negative values, which are sign-extended to 64 bits - * in Protocol Buffers, resulting in a 10-byte varint. - * - * @param value The int32_t value to calculate size for - * @return The number of bytes needed to encode the value - */ - static inline uint32_t varint(int32_t value) { - // Negative values are sign-extended to 64 bits in protocol buffers, - // which always results in a 10-byte varint for negative int32 - if (value < 0) { - return 10; // Negative int32 is always 10 bytes long - } - // For non-negative values, use the uint32_t implementation - return varint(static_cast(value)); - } - - /** - * @brief Calculates the size in bytes needed to encode an int64_t value as a varint - * - * @param value The int64_t value to calculate size for - * @return The number of bytes needed to encode the value - */ - static inline uint32_t varint(int64_t value) { - // For int64_t, we convert to uint64_t and calculate the size - // This works because the bit pattern determines the encoding size, - // and we've handled negative int32 values as a special case above - return varint(static_cast(value)); - } - - /** - * @brief Calculates the size in bytes needed to encode a field ID and wire type - * - * @param field_id The field identifier - * @param type The wire type value (from the WireType enum in the protobuf spec) - * @return The number of bytes needed to encode the field ID and wire type - */ - static inline uint32_t field(uint32_t field_id, uint32_t type) { - uint32_t tag = (field_id << 3) | (type & 0b111); - return varint(tag); - } - - /** - * @brief Common parameters for all add_*_field methods - * - * All add_*_field methods follow these common patterns: - * - * @param total_size Reference to the total message size to update - * @param field_id_size Pre-calculated size of the field ID in bytes - * @param value The value to calculate size for (type varies) - * @param force Whether to calculate size even if the value is default/zero/empty - * - * Each method follows this implementation pattern: - * 1. Skip calculation if value is default (0, false, empty) and not forced - * 2. Calculate the size based on the field's encoding rules - * 3. Add the field_id_size + calculated value size to total_size - */ - - /** - * @brief Calculates and adds the size of an int32 field to the total message size - */ - static inline void add_int32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { - // Skip calculation if value is zero - if (value == 0) { - return; // No need to update total_size - } - - // Calculate and directly add to total_size - if (value < 0) { - // Negative values are encoded as 10-byte varints in protobuf - total_size += field_id_size + 10; - } else { - // For non-negative values, use the standard varint size - total_size += field_id_size + varint(static_cast(value)); - } - } - - /** - * @brief Calculates and adds the size of an int32 field to the total message size (repeated field version) - */ - static inline void add_int32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { - // Always calculate size for repeated fields - if (value < 0) { - // Negative values are encoded as 10-byte varints in protobuf - total_size += field_id_size + 10; - } else { - // For non-negative values, use the standard varint size - total_size += field_id_size + varint(static_cast(value)); - } - } - - /** - * @brief Calculates and adds the size of a uint32 field to the total message size - */ - static inline void add_uint32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { - // Skip calculation if value is zero - if (value == 0) { - return; // No need to update total_size - } - - // Calculate and directly add to total_size - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of a uint32 field to the total message size (repeated field version) - */ - static inline void add_uint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { - // Always calculate size for repeated fields - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of a boolean field to the total message size - */ - static inline void add_bool_field(uint32_t &total_size, uint32_t field_id_size, bool value) { - // Skip calculation if value is false - if (!value) { - return; // No need to update total_size - } - - // Boolean fields always use 1 byte when true - total_size += field_id_size + 1; - } - - /** - * @brief Calculates and adds the size of a boolean field to the total message size (repeated field version) - */ - static inline void add_bool_field_repeated(uint32_t &total_size, uint32_t field_id_size, bool value) { - // Always calculate size for repeated fields - // Boolean fields always use 1 byte - total_size += field_id_size + 1; - } - - /** - * @brief Calculates and adds the size of a fixed field to the total message size - * - * Fixed fields always take exactly N bytes (4 for fixed32/float, 8 for fixed64/double). - * - * @tparam NumBytes The number of bytes for this fixed field (4 or 8) - * @param is_nonzero Whether the value is non-zero - */ - template - static inline void add_fixed_field(uint32_t &total_size, uint32_t field_id_size, bool is_nonzero) { - // Skip calculation if value is zero - if (!is_nonzero) { - return; // No need to update total_size - } - - // Fixed fields always take exactly NumBytes - total_size += field_id_size + NumBytes; - } - - /** - * @brief Calculates and adds the size of an enum field to the total message size - * - * Enum fields are encoded as uint32 varints. - */ - static inline void add_enum_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { - // Skip calculation if value is zero - if (value == 0) { - return; // No need to update total_size - } - - // Enums are encoded as uint32 - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of an enum field to the total message size (repeated field version) - * - * Enum fields are encoded as uint32 varints. - */ - static inline void add_enum_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { - // Always calculate size for repeated fields - // Enums are encoded as uint32 - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of a sint32 field to the total message size - * - * Sint32 fields use ZigZag encoding, which is more efficient for negative values. - */ - static inline void add_sint32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { - // Skip calculation if value is zero - if (value == 0) { - return; // No need to update total_size - } - - // ZigZag encoding for sint32: (n << 1) ^ (n >> 31) - uint32_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 31)); - total_size += field_id_size + varint(zigzag); - } - - /** - * @brief Calculates and adds the size of a sint32 field to the total message size (repeated field version) - * - * Sint32 fields use ZigZag encoding, which is more efficient for negative values. - */ - static inline void add_sint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { - // Always calculate size for repeated fields - // ZigZag encoding for sint32: (n << 1) ^ (n >> 31) - uint32_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 31)); - total_size += field_id_size + varint(zigzag); - } - - /** - * @brief Calculates and adds the size of an int64 field to the total message size - */ - static inline void add_int64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) { - // Skip calculation if value is zero - if (value == 0) { - return; // No need to update total_size - } - - // Calculate and directly add to total_size - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of an int64 field to the total message size (repeated field version) - */ - static inline void add_int64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) { - // Always calculate size for repeated fields - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of a uint64 field to the total message size - */ - static inline void add_uint64_field(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { - // Skip calculation if value is zero - if (value == 0) { - return; // No need to update total_size - } - - // Calculate and directly add to total_size - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of a uint64 field to the total message size (repeated field version) - */ - static inline void add_uint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { - // Always calculate size for repeated fields - total_size += field_id_size + varint(value); - } - - /** - * @brief Calculates and adds the size of a sint64 field to the total message size - * - * Sint64 fields use ZigZag encoding, which is more efficient for negative values. - */ - static inline void add_sint64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) { - // Skip calculation if value is zero - if (value == 0) { - return; // No need to update total_size - } - - // ZigZag encoding for sint64: (n << 1) ^ (n >> 63) - uint64_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 63)); - total_size += field_id_size + varint(zigzag); - } - - /** - * @brief Calculates and adds the size of a sint64 field to the total message size (repeated field version) - * - * Sint64 fields use ZigZag encoding, which is more efficient for negative values. - */ - static inline void add_sint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) { - // Always calculate size for repeated fields - // ZigZag encoding for sint64: (n << 1) ^ (n >> 63) - uint64_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 63)); - total_size += field_id_size + varint(zigzag); - } - - /** - * @brief Calculates and adds the size of a string/bytes field to the total message size - */ - static inline void add_string_field(uint32_t &total_size, uint32_t field_id_size, const std::string &str) { - // Skip calculation if string is empty - if (str.empty()) { - return; // No need to update total_size - } - - // Calculate and directly add to total_size - const uint32_t str_size = static_cast(str.size()); - total_size += field_id_size + varint(str_size) + str_size; - } - - /** - * @brief Calculates and adds the size of a string/bytes field to the total message size (repeated field version) - */ - static inline void add_string_field_repeated(uint32_t &total_size, uint32_t field_id_size, const std::string &str) { - // Always calculate size for repeated fields - const uint32_t str_size = static_cast(str.size()); - total_size += field_id_size + varint(str_size) + str_size; - } - - /** - * @brief Calculates and adds the size of a nested message field to the total message size - * - * This helper function directly updates the total_size reference if the nested size - * is greater than zero. - * - * @param nested_size The pre-calculated size of the nested message - */ - static inline void add_message_field(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { - // Skip calculation if nested message is empty - if (nested_size == 0) { - return; // No need to update total_size - } - - // Calculate and directly add to total_size - // Field ID + length varint + nested message content - total_size += field_id_size + varint(nested_size) + nested_size; - } - - /** - * @brief Calculates and adds the size of a nested message field to the total message size (repeated field version) - * - * @param nested_size The pre-calculated size of the nested message - */ - static inline void add_message_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { - // Always calculate size for repeated fields - // Field ID + length varint + nested message content - total_size += field_id_size + varint(nested_size) + nested_size; - } - - /** - * @brief Calculates and adds the size of a nested message field to the total message size - * - * This version takes a ProtoMessage object, calculates its size internally, - * and updates the total_size reference. This eliminates the need for a temporary variable - * at the call site. - * - * @param message The nested message object - */ - static inline void add_message_object(uint32_t &total_size, uint32_t field_id_size, const ProtoMessage &message) { - uint32_t nested_size = 0; - message.calculate_size(nested_size); - - // Use the base implementation with the calculated nested_size - add_message_field(total_size, field_id_size, nested_size); - } - - /** - * @brief Calculates and adds the size of a nested message field to the total message size (repeated field version) - * - * @param message The nested message object - */ - static inline void add_message_object_repeated(uint32_t &total_size, uint32_t field_id_size, - const ProtoMessage &message) { - uint32_t nested_size = 0; - message.calculate_size(nested_size); - - // Use the base implementation with the calculated nested_size - add_message_field_repeated(total_size, field_id_size, nested_size); - } - - /** - * @brief Calculates and adds the sizes of all messages in a repeated field to the total message size - * - * This helper processes a vector of message objects, calculating the size for each message - * and adding it to the total size. - * - * @tparam MessageType The type of the nested messages in the vector - * @param messages Vector of message objects - */ - template - static inline void add_repeated_message(uint32_t &total_size, uint32_t field_id_size, - const std::vector &messages) { - // Skip if the vector is empty - if (messages.empty()) { - return; - } - - // Use the repeated field version for all messages - for (const auto &message : messages) { - add_message_object_repeated(total_size, field_id_size, message); - } - } -}; - -} // namespace api -} // namespace esphome diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index 6a5d273ec1..f5be672c9a 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -24,14 +24,6 @@ static const char *const TAG = "api"; // APIServer APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -#ifndef USE_API_YAML_SERVICES -// Global empty vector to avoid guard variables (saves 8 bytes) -// This is initialized at program startup before any threads -static const std::vector empty_user_services{}; - -const std::vector &get_empty_user_services_instance() { return empty_user_services; } -#endif - APIServer::APIServer() { global_api_server = this; // Pre-allocate shared write buffer diff --git a/esphome/components/api/api_server.h b/esphome/components/api/api_server.h index f34fd55974..f41064b62b 100644 --- a/esphome/components/api/api_server.h +++ b/esphome/components/api/api_server.h @@ -12,7 +12,9 @@ #include "esphome/core/log.h" #include "list_entities.h" #include "subscribe_state.h" +#ifdef USE_API_SERVICES #include "user_services.h" +#endif #include @@ -25,11 +27,6 @@ struct SavedNoisePsk { } PACKED; // NOLINT #endif -#ifndef USE_API_YAML_SERVICES -// Forward declaration of helper function -const std::vector &get_empty_user_services_instance(); -#endif - class APIServer : public Component, public Controller { public: APIServer(); @@ -112,18 +109,9 @@ class APIServer : public Component, public Controller { void on_media_player_update(media_player::MediaPlayer *obj) override; #endif void send_homeassistant_service_call(const HomeassistantServiceResponse &call); - void register_user_service(UserServiceDescriptor *descriptor) { -#ifdef USE_API_YAML_SERVICES - // Vector is pre-allocated when services are defined in YAML - this->user_services_.push_back(descriptor); -#else - // Lazy allocate vector on first use for CustomAPIDevice - if (!this->user_services_) { - this->user_services_ = std::make_unique>(); - } - this->user_services_->push_back(descriptor); +#ifdef USE_API_SERVICES + void register_user_service(UserServiceDescriptor *descriptor) { this->user_services_.push_back(descriptor); } #endif - } #ifdef USE_HOMEASSISTANT_TIME void request_time(); #endif @@ -152,17 +140,9 @@ class APIServer : public Component, public Controller { void get_home_assistant_state(std::string entity_id, optional attribute, std::function f); const std::vector &get_state_subs() const; - const std::vector &get_user_services() const { -#ifdef USE_API_YAML_SERVICES - return this->user_services_; -#else - if (this->user_services_) { - return *this->user_services_; - } - // Return reference to global empty instance (no guard needed) - return get_empty_user_services_instance(); +#ifdef USE_API_SERVICES + const std::vector &get_user_services() const { return this->user_services_; } #endif - } #ifdef USE_API_CLIENT_CONNECTED_TRIGGER Trigger *get_client_connected_trigger() const { return this->client_connected_trigger_; } @@ -194,14 +174,8 @@ class APIServer : public Component, public Controller { #endif std::vector shared_write_buffer_; // Shared proto write buffer for all connections std::vector state_subs_; -#ifdef USE_API_YAML_SERVICES - // When services are defined in YAML, we know at compile time that services will be registered +#ifdef USE_API_SERVICES std::vector user_services_; -#else - // Services can still be registered at runtime by CustomAPIDevice components even when not - // defined in YAML. Using unique_ptr allows lazy allocation, saving 12 bytes in the common - // case where no services (YAML or custom) are used. - std::unique_ptr> user_services_; #endif // Group smaller types together diff --git a/esphome/components/api/custom_api_device.h b/esphome/components/api/custom_api_device.h index 1a8e189f41..35329c4a5e 100644 --- a/esphome/components/api/custom_api_device.h +++ b/esphome/components/api/custom_api_device.h @@ -3,10 +3,13 @@ #include #include "api_server.h" #ifdef USE_API +#ifdef USE_API_SERVICES #include "user_services.h" +#endif namespace esphome { namespace api { +#ifdef USE_API_SERVICES template class CustomAPIDeviceService : public UserServiceBase { public: CustomAPIDeviceService(const std::string &name, const std::array &arg_names, T *obj, @@ -19,6 +22,7 @@ template class CustomAPIDeviceService : public UserS T *obj_; void (T::*callback_)(Ts...); }; +#endif // USE_API_SERVICES class CustomAPIDevice { public: @@ -46,12 +50,14 @@ class CustomAPIDevice { * @param name The name of the service to register. * @param arg_names The name of the arguments for the service, must match the arguments of the function. */ +#ifdef USE_API_SERVICES template void register_service(void (T::*callback)(Ts...), const std::string &name, const std::array &arg_names) { auto *service = new CustomAPIDeviceService(name, arg_names, (T *) this, callback); // NOLINT global_api_server->register_user_service(service); } +#endif /** Register a custom native API service that will show up in Home Assistant. * @@ -71,10 +77,12 @@ class CustomAPIDevice { * @param callback The member function to call when the service is triggered. * @param name The name of the arguments for the service, must match the arguments of the function. */ +#ifdef USE_API_SERVICES template void register_service(void (T::*callback)(), const std::string &name) { auto *service = new CustomAPIDeviceService(name, {}, (T *) this, callback); // NOLINT global_api_server->register_user_service(service); } +#endif /** Subscribe to the state (or attribute state) of an entity from Home Assistant. * diff --git a/esphome/components/api/list_entities.cpp b/esphome/components/api/list_entities.cpp index 60814e359d..1fbe68117b 100644 --- a/esphome/components/api/list_entities.cpp +++ b/esphome/components/api/list_entities.cpp @@ -83,10 +83,12 @@ bool ListEntitiesIterator::on_end() { return this->client_->send_list_info_done( ListEntitiesIterator::ListEntitiesIterator(APIConnection *client) : client_(client) {} +#ifdef USE_API_SERVICES bool ListEntitiesIterator::on_service(UserServiceDescriptor *service) { auto resp = service->encode_list_service_response(); return this->client_->send_message(resp); } +#endif } // namespace api } // namespace esphome diff --git a/esphome/components/api/list_entities.h b/esphome/components/api/list_entities.h index 5e6074e008..b4cbf6c489 100644 --- a/esphome/components/api/list_entities.h +++ b/esphome/components/api/list_entities.h @@ -44,7 +44,9 @@ class ListEntitiesIterator : public ComponentIterator { #ifdef USE_TEXT_SENSOR bool on_text_sensor(text_sensor::TextSensor *entity) override; #endif +#ifdef USE_API_SERVICES bool on_service(UserServiceDescriptor *service) override; +#endif #ifdef USE_CAMERA bool on_camera(camera::Camera *entity) override; #endif diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 936e732af1..a435168821 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -4,6 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" +#include #include #ifdef ESPHOME_LOG_HAS_VERY_VERBOSE @@ -339,18 +340,487 @@ class ProtoMessage { virtual bool decode_64bit(uint32_t field_id, Proto64Bit value) { return false; } }; +class ProtoSize { + public: + /** + * @brief ProtoSize class for Protocol Buffer serialization size calculation + * + * This class provides static methods to calculate the exact byte counts needed + * for encoding various Protocol Buffer field types. All methods are designed to be + * efficient for the common case where many fields have default values. + * + * Implements Protocol Buffer encoding size calculation according to: + * https://protobuf.dev/programming-guides/encoding/ + * + * Key features: + * - Early-return optimization for zero/default values + * - Direct total_size updates to avoid unnecessary additions + * - Specialized handling for different field types according to protobuf spec + * - Templated helpers for repeated fields and messages + */ + + /** + * @brief Calculates the size in bytes needed to encode a uint32_t value as a varint + * + * @param value The uint32_t value to calculate size for + * @return The number of bytes needed to encode the value + */ + static inline uint32_t varint(uint32_t value) { + // Optimized varint size calculation using leading zeros + // Each 7 bits requires one byte in the varint encoding + if (value < 128) + return 1; // 7 bits, common case for small values + + // For larger values, count bytes needed based on the position of the highest bit set + if (value < 16384) { + return 2; // 14 bits + } else if (value < 2097152) { + return 3; // 21 bits + } else if (value < 268435456) { + return 4; // 28 bits + } else { + return 5; // 32 bits (maximum for uint32_t) + } + } + + /** + * @brief Calculates the size in bytes needed to encode a uint64_t value as a varint + * + * @param value The uint64_t value to calculate size for + * @return The number of bytes needed to encode the value + */ + static inline uint32_t varint(uint64_t value) { + // Handle common case of values fitting in uint32_t (vast majority of use cases) + if (value <= UINT32_MAX) { + return varint(static_cast(value)); + } + + // For larger values, determine size based on highest bit position + if (value < (1ULL << 35)) { + return 5; // 35 bits + } else if (value < (1ULL << 42)) { + return 6; // 42 bits + } else if (value < (1ULL << 49)) { + return 7; // 49 bits + } else if (value < (1ULL << 56)) { + return 8; // 56 bits + } else if (value < (1ULL << 63)) { + return 9; // 63 bits + } else { + return 10; // 64 bits (maximum for uint64_t) + } + } + + /** + * @brief Calculates the size in bytes needed to encode an int32_t value as a varint + * + * Special handling is needed for negative values, which are sign-extended to 64 bits + * in Protocol Buffers, resulting in a 10-byte varint. + * + * @param value The int32_t value to calculate size for + * @return The number of bytes needed to encode the value + */ + static inline uint32_t varint(int32_t value) { + // Negative values are sign-extended to 64 bits in protocol buffers, + // which always results in a 10-byte varint for negative int32 + if (value < 0) { + return 10; // Negative int32 is always 10 bytes long + } + // For non-negative values, use the uint32_t implementation + return varint(static_cast(value)); + } + + /** + * @brief Calculates the size in bytes needed to encode an int64_t value as a varint + * + * @param value The int64_t value to calculate size for + * @return The number of bytes needed to encode the value + */ + static inline uint32_t varint(int64_t value) { + // For int64_t, we convert to uint64_t and calculate the size + // This works because the bit pattern determines the encoding size, + // and we've handled negative int32 values as a special case above + return varint(static_cast(value)); + } + + /** + * @brief Calculates the size in bytes needed to encode a field ID and wire type + * + * @param field_id The field identifier + * @param type The wire type value (from the WireType enum in the protobuf spec) + * @return The number of bytes needed to encode the field ID and wire type + */ + static inline uint32_t field(uint32_t field_id, uint32_t type) { + uint32_t tag = (field_id << 3) | (type & 0b111); + return varint(tag); + } + + /** + * @brief Common parameters for all add_*_field methods + * + * All add_*_field methods follow these common patterns: + * + * @param total_size Reference to the total message size to update + * @param field_id_size Pre-calculated size of the field ID in bytes + * @param value The value to calculate size for (type varies) + * @param force Whether to calculate size even if the value is default/zero/empty + * + * Each method follows this implementation pattern: + * 1. Skip calculation if value is default (0, false, empty) and not forced + * 2. Calculate the size based on the field's encoding rules + * 3. Add the field_id_size + calculated value size to total_size + */ + + /** + * @brief Calculates and adds the size of an int32 field to the total message size + */ + static inline void add_int32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + // Skip calculation if value is zero + if (value == 0) { + return; // No need to update total_size + } + + // Calculate and directly add to total_size + if (value < 0) { + // Negative values are encoded as 10-byte varints in protobuf + total_size += field_id_size + 10; + } else { + // For non-negative values, use the standard varint size + total_size += field_id_size + varint(static_cast(value)); + } + } + + /** + * @brief Calculates and adds the size of an int32 field to the total message size (repeated field version) + */ + static inline void add_int32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + // Always calculate size for repeated fields + if (value < 0) { + // Negative values are encoded as 10-byte varints in protobuf + total_size += field_id_size + 10; + } else { + // For non-negative values, use the standard varint size + total_size += field_id_size + varint(static_cast(value)); + } + } + + /** + * @brief Calculates and adds the size of a uint32 field to the total message size + */ + static inline void add_uint32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + // Skip calculation if value is zero + if (value == 0) { + return; // No need to update total_size + } + + // Calculate and directly add to total_size + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of a uint32 field to the total message size (repeated field version) + */ + static inline void add_uint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + // Always calculate size for repeated fields + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of a boolean field to the total message size + */ + static inline void add_bool_field(uint32_t &total_size, uint32_t field_id_size, bool value) { + // Skip calculation if value is false + if (!value) { + return; // No need to update total_size + } + + // Boolean fields always use 1 byte when true + total_size += field_id_size + 1; + } + + /** + * @brief Calculates and adds the size of a boolean field to the total message size (repeated field version) + */ + static inline void add_bool_field_repeated(uint32_t &total_size, uint32_t field_id_size, bool value) { + // Always calculate size for repeated fields + // Boolean fields always use 1 byte + total_size += field_id_size + 1; + } + + /** + * @brief Calculates and adds the size of a fixed field to the total message size + * + * Fixed fields always take exactly N bytes (4 for fixed32/float, 8 for fixed64/double). + * + * @tparam NumBytes The number of bytes for this fixed field (4 or 8) + * @param is_nonzero Whether the value is non-zero + */ + template + static inline void add_fixed_field(uint32_t &total_size, uint32_t field_id_size, bool is_nonzero) { + // Skip calculation if value is zero + if (!is_nonzero) { + return; // No need to update total_size + } + + // Fixed fields always take exactly NumBytes + total_size += field_id_size + NumBytes; + } + + /** + * @brief Calculates and adds the size of an enum field to the total message size + * + * Enum fields are encoded as uint32 varints. + */ + static inline void add_enum_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + // Skip calculation if value is zero + if (value == 0) { + return; // No need to update total_size + } + + // Enums are encoded as uint32 + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of an enum field to the total message size (repeated field version) + * + * Enum fields are encoded as uint32 varints. + */ + static inline void add_enum_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + // Always calculate size for repeated fields + // Enums are encoded as uint32 + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of a sint32 field to the total message size + * + * Sint32 fields use ZigZag encoding, which is more efficient for negative values. + */ + static inline void add_sint32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + // Skip calculation if value is zero + if (value == 0) { + return; // No need to update total_size + } + + // ZigZag encoding for sint32: (n << 1) ^ (n >> 31) + uint32_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 31)); + total_size += field_id_size + varint(zigzag); + } + + /** + * @brief Calculates and adds the size of a sint32 field to the total message size (repeated field version) + * + * Sint32 fields use ZigZag encoding, which is more efficient for negative values. + */ + static inline void add_sint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + // Always calculate size for repeated fields + // ZigZag encoding for sint32: (n << 1) ^ (n >> 31) + uint32_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 31)); + total_size += field_id_size + varint(zigzag); + } + + /** + * @brief Calculates and adds the size of an int64 field to the total message size + */ + static inline void add_int64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) { + // Skip calculation if value is zero + if (value == 0) { + return; // No need to update total_size + } + + // Calculate and directly add to total_size + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of an int64 field to the total message size (repeated field version) + */ + static inline void add_int64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) { + // Always calculate size for repeated fields + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of a uint64 field to the total message size + */ + static inline void add_uint64_field(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { + // Skip calculation if value is zero + if (value == 0) { + return; // No need to update total_size + } + + // Calculate and directly add to total_size + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of a uint64 field to the total message size (repeated field version) + */ + static inline void add_uint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { + // Always calculate size for repeated fields + total_size += field_id_size + varint(value); + } + + /** + * @brief Calculates and adds the size of a sint64 field to the total message size + * + * Sint64 fields use ZigZag encoding, which is more efficient for negative values. + */ + static inline void add_sint64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) { + // Skip calculation if value is zero + if (value == 0) { + return; // No need to update total_size + } + + // ZigZag encoding for sint64: (n << 1) ^ (n >> 63) + uint64_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 63)); + total_size += field_id_size + varint(zigzag); + } + + /** + * @brief Calculates and adds the size of a sint64 field to the total message size (repeated field version) + * + * Sint64 fields use ZigZag encoding, which is more efficient for negative values. + */ + static inline void add_sint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) { + // Always calculate size for repeated fields + // ZigZag encoding for sint64: (n << 1) ^ (n >> 63) + uint64_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 63)); + total_size += field_id_size + varint(zigzag); + } + + /** + * @brief Calculates and adds the size of a string/bytes field to the total message size + */ + static inline void add_string_field(uint32_t &total_size, uint32_t field_id_size, const std::string &str) { + // Skip calculation if string is empty + if (str.empty()) { + return; // No need to update total_size + } + + // Calculate and directly add to total_size + const uint32_t str_size = static_cast(str.size()); + total_size += field_id_size + varint(str_size) + str_size; + } + + /** + * @brief Calculates and adds the size of a string/bytes field to the total message size (repeated field version) + */ + static inline void add_string_field_repeated(uint32_t &total_size, uint32_t field_id_size, const std::string &str) { + // Always calculate size for repeated fields + const uint32_t str_size = static_cast(str.size()); + total_size += field_id_size + varint(str_size) + str_size; + } + + /** + * @brief Calculates and adds the size of a nested message field to the total message size + * + * This helper function directly updates the total_size reference if the nested size + * is greater than zero. + * + * @param nested_size The pre-calculated size of the nested message + */ + static inline void add_message_field(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { + // Skip calculation if nested message is empty + if (nested_size == 0) { + return; // No need to update total_size + } + + // Calculate and directly add to total_size + // Field ID + length varint + nested message content + total_size += field_id_size + varint(nested_size) + nested_size; + } + + /** + * @brief Calculates and adds the size of a nested message field to the total message size (repeated field version) + * + * @param nested_size The pre-calculated size of the nested message + */ + static inline void add_message_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { + // Always calculate size for repeated fields + // Field ID + length varint + nested message content + total_size += field_id_size + varint(nested_size) + nested_size; + } + + /** + * @brief Calculates and adds the size of a nested message field to the total message size + * + * This version takes a ProtoMessage object, calculates its size internally, + * and updates the total_size reference. This eliminates the need for a temporary variable + * at the call site. + * + * @param message The nested message object + */ + static inline void add_message_object(uint32_t &total_size, uint32_t field_id_size, const ProtoMessage &message) { + uint32_t nested_size = 0; + message.calculate_size(nested_size); + + // Use the base implementation with the calculated nested_size + add_message_field(total_size, field_id_size, nested_size); + } + + /** + * @brief Calculates and adds the size of a nested message field to the total message size (repeated field version) + * + * @param message The nested message object + */ + static inline void add_message_object_repeated(uint32_t &total_size, uint32_t field_id_size, + const ProtoMessage &message) { + uint32_t nested_size = 0; + message.calculate_size(nested_size); + + // Use the base implementation with the calculated nested_size + add_message_field_repeated(total_size, field_id_size, nested_size); + } + + /** + * @brief Calculates and adds the sizes of all messages in a repeated field to the total message size + * + * This helper processes a vector of message objects, calculating the size for each message + * and adding it to the total size. + * + * @tparam MessageType The type of the nested messages in the vector + * @param messages Vector of message objects + */ + template + static inline void add_repeated_message(uint32_t &total_size, uint32_t field_id_size, + const std::vector &messages) { + // Skip if the vector is empty + if (messages.empty()) { + return; + } + + // Use the repeated field version for all messages + for (const auto &message : messages) { + add_message_object_repeated(total_size, field_id_size, message); + } + } +}; + // Implementation of encode_message - must be after ProtoMessage is defined inline void ProtoWriteBuffer::encode_message(uint32_t field_id, const ProtoMessage &value, bool force) { this->encode_field_raw(field_id, 2); // type 2: Length-delimited message - size_t begin = this->buffer_->size(); + // Calculate the message size first + uint32_t msg_length_bytes = 0; + value.calculate_size(msg_length_bytes); + + // Calculate how many bytes the length varint needs + uint32_t varint_length_bytes = ProtoSize::varint(msg_length_bytes); + + // Reserve exact space for the length varint + size_t begin = this->buffer_->size(); + this->buffer_->resize(this->buffer_->size() + varint_length_bytes); + + // Write the length varint directly + ProtoVarInt(msg_length_bytes).encode_to_buffer_unchecked(this->buffer_->data() + begin, varint_length_bytes); + + // Now encode the message content - it will append to the buffer value.encode(*this); - const uint32_t nested_length = this->buffer_->size() - begin; - // add size varint - std::vector var; - ProtoVarInt(nested_length).encode(var); - this->buffer_->insert(this->buffer_->begin() + begin, var.begin(), var.end()); + // Verify that the encoded size matches what we calculated + assert(this->buffer_->size() == begin + varint_length_bytes + msg_length_bytes); } // Implementation of decode_to_message - must be after ProtoMessage is defined diff --git a/esphome/components/api/user_services.h b/esphome/components/api/user_services.h index 673bcf5693..93cea8133f 100644 --- a/esphome/components/api/user_services.h +++ b/esphome/components/api/user_services.h @@ -7,6 +7,7 @@ #include "esphome/core/automation.h" #include "api_pb2.h" +#ifdef USE_API_SERVICES namespace esphome { namespace api { @@ -73,3 +74,4 @@ template class UserServiceTrigger : public UserServiceBase in every file cg.add_platformio_option("build_src_flags", "-include Arduino.h") # dummy version code diff --git a/esphome/components/packet_transport/packet_transport.cpp b/esphome/components/packet_transport/packet_transport.cpp index 6684d43ff7..b6ce24bc1b 100644 --- a/esphome/components/packet_transport/packet_transport.cpp +++ b/esphome/components/packet_transport/packet_transport.cpp @@ -314,6 +314,9 @@ void PacketTransport::send_data_(bool all) { } void PacketTransport::update() { + if (!this->ping_pong_enable_) { + return; + } auto now = millis() / 1000; if (this->last_key_time_ + this->ping_pong_recyle_time_ < now) { this->resend_ping_key_ = this->ping_pong_enable_; diff --git a/esphome/components/sx126x/__init__.py b/esphome/components/sx126x/__init__.py index 492febe283..b6aeaf072c 100644 --- a/esphome/components/sx126x/__init__.py +++ b/esphome/components/sx126x/__init__.py @@ -167,8 +167,8 @@ def validate_config(config): if config[CONF_MODULATION] == "LORA": if config[CONF_BANDWIDTH] not in lora_bws: raise cv.Invalid(f"{config[CONF_BANDWIDTH]} is not available with LORA") - if config[CONF_PREAMBLE_SIZE] > 0 and config[CONF_PREAMBLE_SIZE] < 6: - raise cv.Invalid("Minimum preamble size is 6 with LORA") + if config[CONF_PREAMBLE_SIZE] < 6: + raise cv.Invalid("Minimum 'preamble_size' is 6 with LORA") if config[CONF_SPREADING_FACTOR] == 6 and config[CONF_PAYLOAD_LENGTH] == 0: raise cv.Invalid("Payload length must be set when spreading factor is 6") else: @@ -200,7 +200,7 @@ CONFIG_SCHEMA = ( cv.Optional(CONF_PA_RAMP, default="40us"): cv.enum(RAMP), cv.Optional(CONF_PAYLOAD_LENGTH, default=0): cv.int_range(min=0, max=256), cv.Optional(CONF_PREAMBLE_DETECT, default=2): cv.int_range(min=0, max=4), - cv.Required(CONF_PREAMBLE_SIZE): cv.int_range(min=1, max=65535), + cv.Optional(CONF_PREAMBLE_SIZE, default=8): cv.int_range(min=1, max=65535), cv.Required(CONF_RST_PIN): pins.internal_gpio_output_pin_schema, cv.Optional(CONF_RX_START, default=True): cv.boolean, cv.Required(CONF_RF_SWITCH): cv.boolean, diff --git a/esphome/components/sx127x/__init__.py b/esphome/components/sx127x/__init__.py index 4d034801cc..33b556db07 100644 --- a/esphome/components/sx127x/__init__.py +++ b/esphome/components/sx127x/__init__.py @@ -164,8 +164,8 @@ def validate_config(config): raise cv.Invalid(f"{config[CONF_BANDWIDTH]} is not available with LORA") if CONF_DIO0_PIN not in config: raise cv.Invalid("Cannot use LoRa without dio0_pin") - if 0 < config[CONF_PREAMBLE_SIZE] < 6: - raise cv.Invalid("Minimum preamble size is 6 with LORA") + if config[CONF_PREAMBLE_SIZE] < 6: + raise cv.Invalid("Minimum 'preamble_size' is 6 with LORA") if config[CONF_SPREADING_FACTOR] == 6 and config[CONF_PAYLOAD_LENGTH] == 0: raise cv.Invalid("Payload length must be set when spreading factor is 6") else: diff --git a/esphome/components/usb_host/usb_host_client.cpp b/esphome/components/usb_host/usb_host_client.cpp index fc5f772f41..edf6c94b07 100644 --- a/esphome/components/usb_host/usb_host_client.cpp +++ b/esphome/components/usb_host/usb_host_client.cpp @@ -70,7 +70,7 @@ static void usbh_print_cfg_desc(const usb_config_desc_t *cfg_desc) { ESP_LOGV(TAG, "bMaxPower %dmA", cfg_desc->bMaxPower * 2); } -void usb_client_print_device_descriptor(const usb_device_desc_t *devc_desc) { +static void usb_client_print_device_descriptor(const usb_device_desc_t *devc_desc) { if (devc_desc == NULL) { return; } @@ -92,8 +92,8 @@ void usb_client_print_device_descriptor(const usb_device_desc_t *devc_desc) { ESP_LOGV(TAG, "bNumConfigurations %d", devc_desc->bNumConfigurations); } -void usb_client_print_config_descriptor(const usb_config_desc_t *cfg_desc, - print_class_descriptor_cb class_specific_cb) { +static void usb_client_print_config_descriptor(const usb_config_desc_t *cfg_desc, + print_class_descriptor_cb class_specific_cb) { if (cfg_desc == nullptr) { return; } @@ -128,9 +128,9 @@ void usb_client_print_config_descriptor(const usb_config_desc_t *cfg_desc, static std::string get_descriptor_string(const usb_str_desc_t *desc) { char buffer[256]; if (desc == nullptr) - return "(unknown)"; + return "(unspecified)"; char *p = buffer; - for (size_t i = 0; i != desc->bLength / 2; i++) { + for (int i = 0; i != desc->bLength / 2; i++) { auto c = desc->wData[i]; if (c < 0x100) *p++ = static_cast(c); @@ -169,7 +169,7 @@ void USBClient::setup() { this->mark_failed(); return; } - for (auto trq : this->trq_pool_) { + for (auto *trq : this->trq_pool_) { usb_host_transfer_alloc(64, 0, &trq->transfer); trq->client = this; } @@ -197,7 +197,8 @@ void USBClient::loop() { ESP_LOGD(TAG, "Device descriptor: vid %X pid %X", desc->idVendor, desc->idProduct); if (desc->idVendor == this->vid_ && desc->idProduct == this->pid_ || this->vid_ == 0 && this->pid_ == 0) { usb_device_info_t dev_info; - if ((err = usb_host_device_info(this->device_handle_, &dev_info)) != ESP_OK) { + err = usb_host_device_info(this->device_handle_, &dev_info); + if (err != ESP_OK) { ESP_LOGW(TAG, "Device info failed: %s", esp_err_to_name(err)); this->disconnect(); break; @@ -336,7 +337,7 @@ static void transfer_callback(usb_transfer_t *xfer) { * @throws None. */ void USBClient::transfer_in(uint8_t ep_address, const transfer_cb_t &callback, uint16_t length) { - auto trq = this->get_trq_(); + auto *trq = this->get_trq_(); if (trq == nullptr) { ESP_LOGE(TAG, "Too many requests queued"); return; @@ -349,7 +350,6 @@ void USBClient::transfer_in(uint8_t ep_address, const transfer_cb_t &callback, u if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to submit transfer, address=%x, length=%d, err=%x", ep_address, length, err); this->release_trq(trq); - this->disconnect(); } } @@ -364,7 +364,7 @@ void USBClient::transfer_in(uint8_t ep_address, const transfer_cb_t &callback, u * @throws None. */ void USBClient::transfer_out(uint8_t ep_address, const transfer_cb_t &callback, const uint8_t *data, uint16_t length) { - auto trq = this->get_trq_(); + auto *trq = this->get_trq_(); if (trq == nullptr) { ESP_LOGE(TAG, "Too many requests queued"); return; diff --git a/esphome/components/usb_uart/cp210x.cpp b/esphome/components/usb_uart/cp210x.cpp index 267385d1bd..f7d60c307a 100644 --- a/esphome/components/usb_uart/cp210x.cpp +++ b/esphome/components/usb_uart/cp210x.cpp @@ -43,7 +43,7 @@ static constexpr uint8_t SET_BAUDRATE = 0x1E; // Set the baud rate. static constexpr uint8_t SET_CHARS = 0x19; // Set special characters. static constexpr uint8_t VENDOR_SPECIFIC = 0xFF; // Vendor specific command. -std::vector USBUartTypeCP210X::parse_descriptors_(usb_device_handle_t dev_hdl) { +std::vector USBUartTypeCP210X::parse_descriptors(usb_device_handle_t dev_hdl) { const usb_config_desc_t *config_desc; const usb_device_desc_t *device_desc; int conf_offset = 0, ep_offset; diff --git a/esphome/components/usb_uart/usb_uart.cpp b/esphome/components/usb_uart/usb_uart.cpp index e599409f0c..934306f480 100644 --- a/esphome/components/usb_uart/usb_uart.cpp +++ b/esphome/components/usb_uart/usb_uart.cpp @@ -18,52 +18,48 @@ namespace usb_uart { */ static optional get_cdc(const usb_config_desc_t *config_desc, uint8_t intf_idx) { int conf_offset, ep_offset; - const usb_ep_desc_t *notify_ep{}, *in_ep{}, *out_ep{}; - uint8_t interface_number = 0; - // look for an interface with one interrupt endpoint (notify), and an interface with two bulk endpoints (data in/out) + // look for an interface with an interrupt endpoint (notify), and one with two bulk endpoints (data in/out) + CdcEps eps{}; + eps.bulk_interface_number = 0xFF; for (;;) { - auto intf_desc = usb_parse_interface_descriptor(config_desc, intf_idx++, 0, &conf_offset); + const auto *intf_desc = usb_parse_interface_descriptor(config_desc, intf_idx++, 0, &conf_offset); if (!intf_desc) { ESP_LOGE(TAG, "usb_parse_interface_descriptor failed"); return nullopt; } - if (intf_desc->bNumEndpoints == 1) { + ESP_LOGD(TAG, "intf_desc: bInterfaceClass=%02X, bInterfaceSubClass=%02X, bInterfaceProtocol=%02X, bNumEndpoints=%d", + intf_desc->bInterfaceClass, intf_desc->bInterfaceSubClass, intf_desc->bInterfaceProtocol, + intf_desc->bNumEndpoints); + for (uint8_t i = 0; i != intf_desc->bNumEndpoints; i++) { ep_offset = conf_offset; - notify_ep = usb_parse_endpoint_descriptor_by_index(intf_desc, 0, config_desc->wTotalLength, &ep_offset); - if (!notify_ep) { - ESP_LOGE(TAG, "notify_ep: usb_parse_endpoint_descriptor_by_index failed"); + const auto *ep = usb_parse_endpoint_descriptor_by_index(intf_desc, i, config_desc->wTotalLength, &ep_offset); + if (!ep) { + ESP_LOGE(TAG, "Ran out of interfaces at %d before finding all endpoints", i); return nullopt; } - if (notify_ep->bmAttributes != USB_BM_ATTRIBUTES_XFER_INT) - notify_ep = nullptr; - } else if (USB_CLASS_CDC_DATA && intf_desc->bNumEndpoints == 2) { - interface_number = intf_desc->bInterfaceNumber; - ep_offset = conf_offset; - out_ep = usb_parse_endpoint_descriptor_by_index(intf_desc, 0, config_desc->wTotalLength, &ep_offset); - if (!out_ep) { - ESP_LOGE(TAG, "out_ep: usb_parse_endpoint_descriptor_by_index failed"); - return nullopt; + ESP_LOGD(TAG, "ep: bEndpointAddress=%02X, bmAttributes=%02X", ep->bEndpointAddress, ep->bmAttributes); + if (ep->bmAttributes == USB_BM_ATTRIBUTES_XFER_INT) { + eps.notify_ep = ep; + eps.interrupt_interface_number = intf_desc->bInterfaceNumber; + } else if (ep->bmAttributes == USB_BM_ATTRIBUTES_XFER_BULK && ep->bEndpointAddress & usb_host::USB_DIR_IN && + (eps.bulk_interface_number == 0xFF || eps.bulk_interface_number == intf_desc->bInterfaceNumber)) { + eps.in_ep = ep; + eps.bulk_interface_number = intf_desc->bInterfaceNumber; + } else if (ep->bmAttributes == USB_BM_ATTRIBUTES_XFER_BULK && !(ep->bEndpointAddress & usb_host::USB_DIR_IN) && + (eps.bulk_interface_number == 0xFF || eps.bulk_interface_number == intf_desc->bInterfaceNumber)) { + eps.out_ep = ep; + eps.bulk_interface_number = intf_desc->bInterfaceNumber; + } else { + ESP_LOGE(TAG, "Unexpected endpoint attributes: %02X", ep->bmAttributes); + continue; } - if (out_ep->bmAttributes != USB_BM_ATTRIBUTES_XFER_BULK) - out_ep = nullptr; - ep_offset = conf_offset; - in_ep = usb_parse_endpoint_descriptor_by_index(intf_desc, 1, config_desc->wTotalLength, &ep_offset); - if (!in_ep) { - ESP_LOGE(TAG, "in_ep: usb_parse_endpoint_descriptor_by_index failed"); - return nullopt; - } - if (in_ep->bmAttributes != USB_BM_ATTRIBUTES_XFER_BULK) - in_ep = nullptr; } - if (in_ep != nullptr && out_ep != nullptr && notify_ep != nullptr) - break; + if (eps.in_ep != nullptr && eps.out_ep != nullptr && eps.notify_ep != nullptr) + return eps; } - if (in_ep->bEndpointAddress & usb_host::USB_DIR_IN) - return CdcEps{notify_ep, in_ep, out_ep, interface_number}; - return CdcEps{notify_ep, out_ep, in_ep, interface_number}; } -std::vector USBUartTypeCdcAcm::parse_descriptors_(usb_device_handle_t dev_hdl) { +std::vector USBUartTypeCdcAcm::parse_descriptors(usb_device_handle_t dev_hdl) { const usb_config_desc_t *config_desc; const usb_device_desc_t *device_desc; int desc_offset = 0; @@ -78,7 +74,7 @@ std::vector USBUartTypeCdcAcm::parse_descriptors_(usb_device_handle_t de ESP_LOGE(TAG, "get_active_config_descriptor failed"); return {}; } - if (device_desc->bDeviceClass == USB_CLASS_COMM) { + if (device_desc->bDeviceClass == USB_CLASS_COMM || device_desc->bDeviceClass == USB_CLASS_VENDOR_SPEC) { // single CDC-ACM device if (auto eps = get_cdc(config_desc, 0)) { ESP_LOGV(TAG, "Found CDC-ACM device"); @@ -194,7 +190,7 @@ void USBUartComponent::start_input(USBUartChannel *channel) { if (!channel->initialised_ || channel->input_started_ || channel->input_buffer_.get_free_space() < channel->cdc_dev_.in_ep->wMaxPacketSize) return; - auto ep = channel->cdc_dev_.in_ep; + const auto *ep = channel->cdc_dev_.in_ep; auto callback = [this, channel](const usb_host::TransferStatus &status) { ESP_LOGV(TAG, "Transfer result: length: %u; status %X", status.data_len, status.error_code); if (!status.success) { @@ -227,7 +223,7 @@ void USBUartComponent::start_output(USBUartChannel *channel) { if (channel->output_buffer_.is_empty()) { return; } - auto ep = channel->cdc_dev_.out_ep; + const auto *ep = channel->cdc_dev_.out_ep; auto callback = [this, channel](const usb_host::TransferStatus &status) { ESP_LOGV(TAG, "Output Transfer result: length: %u; status %X", status.data_len, status.error_code); channel->output_started_ = false; @@ -259,15 +255,15 @@ static void fix_mps(const usb_ep_desc_t *ep) { } } void USBUartTypeCdcAcm::on_connected() { - auto cdc_devs = this->parse_descriptors_(this->device_handle_); + auto cdc_devs = this->parse_descriptors(this->device_handle_); if (cdc_devs.empty()) { this->status_set_error("No CDC-ACM device found"); this->disconnect(); return; } ESP_LOGD(TAG, "Found %zu CDC-ACM devices", cdc_devs.size()); - auto i = 0; - for (auto channel : this->channels_) { + size_t i = 0; + for (auto *channel : this->channels_) { if (i == cdc_devs.size()) { ESP_LOGE(TAG, "No configuration found for channel %d", channel->index_); this->status_set_warning("No configuration found for channel"); @@ -277,10 +273,11 @@ void USBUartTypeCdcAcm::on_connected() { fix_mps(channel->cdc_dev_.in_ep); fix_mps(channel->cdc_dev_.out_ep); channel->initialised_ = true; - auto err = usb_host_interface_claim(this->handle_, this->device_handle_, channel->cdc_dev_.interface_number, 0); + auto err = + usb_host_interface_claim(this->handle_, this->device_handle_, channel->cdc_dev_.bulk_interface_number, 0); if (err != ESP_OK) { ESP_LOGE(TAG, "usb_host_interface_claim failed: %s, channel=%d, intf=%d", esp_err_to_name(err), channel->index_, - channel->cdc_dev_.interface_number); + channel->cdc_dev_.bulk_interface_number); this->status_set_error("usb_host_interface_claim failed"); this->disconnect(); return; @@ -290,7 +287,7 @@ void USBUartTypeCdcAcm::on_connected() { } void USBUartTypeCdcAcm::on_disconnected() { - for (auto channel : this->channels_) { + for (auto *channel : this->channels_) { if (channel->cdc_dev_.in_ep != nullptr) { usb_host_endpoint_halt(this->device_handle_, channel->cdc_dev_.in_ep->bEndpointAddress); usb_host_endpoint_flush(this->device_handle_, channel->cdc_dev_.in_ep->bEndpointAddress); @@ -303,7 +300,7 @@ void USBUartTypeCdcAcm::on_disconnected() { usb_host_endpoint_halt(this->device_handle_, channel->cdc_dev_.notify_ep->bEndpointAddress); usb_host_endpoint_flush(this->device_handle_, channel->cdc_dev_.notify_ep->bEndpointAddress); } - usb_host_interface_release(this->handle_, this->device_handle_, channel->cdc_dev_.interface_number); + usb_host_interface_release(this->handle_, this->device_handle_, channel->cdc_dev_.bulk_interface_number); channel->initialised_ = false; channel->input_started_ = false; channel->output_started_ = false; @@ -314,7 +311,7 @@ void USBUartTypeCdcAcm::on_disconnected() { } void USBUartTypeCdcAcm::enable_channels() { - for (auto channel : this->channels_) { + for (auto *channel : this->channels_) { if (!channel->initialised_) continue; channel->input_started_ = false; diff --git a/esphome/components/usb_uart/usb_uart.h b/esphome/components/usb_uart/usb_uart.h index fd0fb2c59a..a103c51add 100644 --- a/esphome/components/usb_uart/usb_uart.h +++ b/esphome/components/usb_uart/usb_uart.h @@ -25,7 +25,8 @@ struct CdcEps { const usb_ep_desc_t *notify_ep; const usb_ep_desc_t *in_ep; const usb_ep_desc_t *out_ep; - uint8_t interface_number; + uint8_t bulk_interface_number; + uint8_t interrupt_interface_number; }; enum UARTParityOptions { @@ -123,7 +124,7 @@ class USBUartTypeCdcAcm : public USBUartComponent { USBUartTypeCdcAcm(uint16_t vid, uint16_t pid) : USBUartComponent(vid, pid) {} protected: - virtual std::vector parse_descriptors_(usb_device_handle_t dev_hdl); + virtual std::vector parse_descriptors(usb_device_handle_t dev_hdl); void on_connected() override; virtual void enable_channels(); void on_disconnected() override; @@ -134,7 +135,7 @@ class USBUartTypeCP210X : public USBUartTypeCdcAcm { USBUartTypeCP210X(uint16_t vid, uint16_t pid) : USBUartTypeCdcAcm(vid, pid) {} protected: - std::vector parse_descriptors_(usb_device_handle_t dev_hdl) override; + std::vector parse_descriptors(usb_device_handle_t dev_hdl) override; void enable_channels() override; }; class USBUartTypeCH34X : public USBUartTypeCdcAcm { diff --git a/esphome/core/component_iterator.cpp b/esphome/core/component_iterator.cpp index aab5c2a72d..d27c4e70ba 100644 --- a/esphome/core/component_iterator.cpp +++ b/esphome/core/component_iterator.cpp @@ -4,6 +4,8 @@ #ifdef USE_API #include "esphome/components/api/api_server.h" +#endif +#ifdef USE_API_SERVICES #include "esphome/components/api/user_services.h" #endif @@ -148,7 +150,7 @@ void ComponentIterator::advance() { } break; #endif -#ifdef USE_API +#ifdef USE_API_SERVICES case IteratorState ::SERVICE: if (this->at_ >= api::global_api_server->get_user_services().size()) { advance_platform = true; @@ -383,7 +385,7 @@ void ComponentIterator::advance() { } bool ComponentIterator::on_end() { return true; } bool ComponentIterator::on_begin() { return true; } -#ifdef USE_API +#ifdef USE_API_SERVICES bool ComponentIterator::on_service(api::UserServiceDescriptor *service) { return true; } #endif #ifdef USE_CAMERA diff --git a/esphome/core/component_iterator.h b/esphome/core/component_iterator.h index eda786be7f..ea2c8004ac 100644 --- a/esphome/core/component_iterator.h +++ b/esphome/core/component_iterator.h @@ -10,7 +10,7 @@ namespace esphome { -#ifdef USE_API +#ifdef USE_API_SERVICES namespace api { class UserServiceDescriptor; } // namespace api @@ -45,7 +45,7 @@ class ComponentIterator { #ifdef USE_TEXT_SENSOR virtual bool on_text_sensor(text_sensor::TextSensor *text_sensor) = 0; #endif -#ifdef USE_API +#ifdef USE_API_SERVICES virtual bool on_service(api::UserServiceDescriptor *service); #endif #ifdef USE_CAMERA @@ -122,7 +122,7 @@ class ComponentIterator { #ifdef USE_TEXT_SENSOR TEXT_SENSOR, #endif -#ifdef USE_API +#ifdef USE_API_SERVICES SERVICE, #endif #ifdef USE_CAMERA diff --git a/esphome/core/defines.h b/esphome/core/defines.h index d73009436b..8ed8f4b5aa 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -108,7 +108,7 @@ #define USE_API_CLIENT_DISCONNECTED_TRIGGER #define USE_API_NOISE #define USE_API_PLAINTEXT -#define USE_API_YAML_SERVICES +#define USE_API_SERVICES #define USE_MD5 #define USE_MQTT #define USE_NETWORK diff --git a/platformio.ini b/platformio.ini index 7f10f0f51f..54c72eb28d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -212,6 +212,7 @@ build_unflags = extends = common:arduino platform = libretiny@1.9.1 framework = arduino +lib_compat_mode = soft lib_deps = droscy/esp_wireguard@0.4.2 ; wireguard build_flags = diff --git a/requirements.txt b/requirements.txt index d056f22e28..ea264a8ac4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile esptool==4.9.0 click==8.1.7 esphome-dashboard==20250514.0 -aioesphomeapi==34.2.0 +aioesphomeapi==34.2.1 zeroconf==0.147.0 puremagic==1.30 ruamel.yaml==0.18.14 # dashboard_import diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 49fcb19ec1..fd01491ed1 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -1005,6 +1005,11 @@ def build_message_type( # Get message ID if it's a service message message_id: int | None = get_opt(desc, pb.id) + # Get source direction to determine if we need decode/encode methods + source: int = get_opt(desc, pb.source, SOURCE_BOTH) + needs_decode = source in (SOURCE_BOTH, SOURCE_CLIENT) + needs_encode = source in (SOURCE_BOTH, SOURCE_SERVER) + # Add MESSAGE_TYPE method if this is a service message if message_id is not None: # Validate that message_id fits in uint8_t @@ -1047,18 +1052,21 @@ def build_message_type( protected_content.extend(ti.protected_content) public_content.extend(ti.public_content) - # Always include encode/decode logic for all fields - encode.append(ti.encode_content) - size_calc.append(ti.get_size_calculation(f"this->{ti.field_name}")) + # Only collect encode logic if this message needs it + if needs_encode: + encode.append(ti.encode_content) + size_calc.append(ti.get_size_calculation(f"this->{ti.field_name}")) - if ti.decode_varint_content: - decode_varint.append(ti.decode_varint_content) - if ti.decode_length_content: - decode_length.append(ti.decode_length_content) - if ti.decode_32bit_content: - decode_32bit.append(ti.decode_32bit_content) - if ti.decode_64bit_content: - decode_64bit.append(ti.decode_64bit_content) + # Only collect decode methods if this message needs them + if needs_decode: + if ti.decode_varint_content: + decode_varint.append(ti.decode_varint_content) + if ti.decode_length_content: + decode_length.append(ti.decode_length_content) + if ti.decode_32bit_content: + decode_32bit.append(ti.decode_32bit_content) + if ti.decode_64bit_content: + decode_64bit.append(ti.decode_64bit_content) if ti.dump_content: dump.append(ti.dump_content) @@ -1108,8 +1116,8 @@ def build_message_type( prot = "bool decode_64bit(uint32_t field_id, Proto64Bit value) override;" protected_content.insert(0, prot) - # Only generate encode method if there are fields to encode - if encode: + # Only generate encode method if this message needs encoding and has fields + if needs_encode and encode: o = f"void {desc.name}::encode(ProtoWriteBuffer buffer) const {{" if len(encode) == 1 and len(encode[0]) + len(o) + 3 < 120: o += f" {encode[0]} " @@ -1120,10 +1128,10 @@ def build_message_type( cpp += o prot = "void encode(ProtoWriteBuffer buffer) const override;" public_content.append(prot) - # If no fields to encode, the default implementation in ProtoMessage will be used + # If no fields to encode or message doesn't need encoding, the default implementation in ProtoMessage will be used - # Add calculate_size method only if there are fields - if size_calc: + # Add calculate_size method only if this message needs encoding and has fields + if needs_encode and size_calc: o = f"void {desc.name}::calculate_size(uint32_t &total_size) const {{" # For a single field, just inline it for simplicity if len(size_calc) == 1 and len(size_calc[0]) + len(o) + 3 < 120: @@ -1136,7 +1144,7 @@ def build_message_type( cpp += o prot = "void calculate_size(uint32_t &total_size) const override;" public_content.append(prot) - # If no fields to calculate size for, the default implementation in ProtoMessage will be used + # If no fields to calculate size for or message doesn't need encoding, the default implementation in ProtoMessage will be used # dump_to method declaration in header prot = "#ifdef HAS_PROTO_MESSAGE_DUMP\n" @@ -1401,7 +1409,6 @@ def main() -> None: #include "esphome/core/defines.h" #include "proto.h" -#include "api_pb2_size.h" namespace esphome { namespace api { @@ -1411,7 +1418,6 @@ namespace api { cpp = FILE_HEADER cpp += """\ #include "api_pb2.h" - #include "api_pb2_size.h" #include "esphome/core/log.h" #include "esphome/core/helpers.h" diff --git a/tests/integration/fixtures/api_custom_services.yaml b/tests/integration/fixtures/api_custom_services.yaml new file mode 100644 index 0000000000..41efc95b85 --- /dev/null +++ b/tests/integration/fixtures/api_custom_services.yaml @@ -0,0 +1,24 @@ +esphome: + name: api-custom-services-test +host: + +# This is required for CustomAPIDevice to work +api: + custom_services: true + # Also test that YAML services still work + actions: + - action: test_yaml_service + then: + - logger.log: "YAML service called" + +logger: + level: DEBUG + +# External component that uses CustomAPIDevice +external_components: + - source: + type: local + path: EXTERNAL_COMPONENT_PATH + components: [custom_api_device_component] + +custom_api_device_component: diff --git a/tests/integration/fixtures/external_components/custom_api_device_component/__init__.py b/tests/integration/fixtures/external_components/custom_api_device_component/__init__.py new file mode 100644 index 0000000000..127082601a --- /dev/null +++ b/tests/integration/fixtures/external_components/custom_api_device_component/__init__.py @@ -0,0 +1,19 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.const import CONF_ID + +custom_api_device_component_ns = cg.esphome_ns.namespace("custom_api_device_component") +CustomAPIDeviceComponent = custom_api_device_component_ns.class_( + "CustomAPIDeviceComponent", cg.Component +) + +CONFIG_SCHEMA = cv.Schema( + { + cv.GenerateID(): cv.declare_id(CustomAPIDeviceComponent), + } +).extend(cv.COMPONENT_SCHEMA) + + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await cg.register_component(var, config) diff --git a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp new file mode 100644 index 0000000000..c8581b3d2f --- /dev/null +++ b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp @@ -0,0 +1,53 @@ +#include "custom_api_device_component.h" +#include "esphome/core/log.h" + +#ifdef USE_API +namespace esphome { +namespace custom_api_device_component { + +static const char *const TAG = "custom_api"; + +void CustomAPIDeviceComponent::setup() { + // Register services using CustomAPIDevice + register_service(&CustomAPIDeviceComponent::on_test_service, "custom_test_service"); + + register_service(&CustomAPIDeviceComponent::on_service_with_args, "custom_service_with_args", + {"arg_string", "arg_int", "arg_bool", "arg_float"}); + + // Test array types + register_service(&CustomAPIDeviceComponent::on_service_with_arrays, "custom_service_with_arrays", + {"bool_array", "int_array", "float_array", "string_array"}); +} + +void CustomAPIDeviceComponent::on_test_service() { ESP_LOGI(TAG, "Custom test service called!"); } + +// NOLINTNEXTLINE(performance-unnecessary-value-param) +void CustomAPIDeviceComponent::on_service_with_args(std::string arg_string, int32_t arg_int, bool arg_bool, + float arg_float) { + ESP_LOGI(TAG, "Custom service called with: %s, %d, %d, %.2f", arg_string.c_str(), arg_int, arg_bool, arg_float); +} + +void CustomAPIDeviceComponent::on_service_with_arrays(std::vector bool_array, std::vector int_array, + std::vector float_array, + std::vector string_array) { + ESP_LOGI(TAG, "Array service called with %zu bools, %zu ints, %zu floats, %zu strings", bool_array.size(), + int_array.size(), float_array.size(), string_array.size()); + + // Log first element of each array if not empty + if (!bool_array.empty()) { + ESP_LOGI(TAG, "First bool: %s", bool_array[0] ? "true" : "false"); + } + if (!int_array.empty()) { + ESP_LOGI(TAG, "First int: %d", int_array[0]); + } + if (!float_array.empty()) { + ESP_LOGI(TAG, "First float: %.2f", float_array[0]); + } + if (!string_array.empty()) { + ESP_LOGI(TAG, "First string: %s", string_array[0].c_str()); + } +} + +} // namespace custom_api_device_component +} // namespace esphome +#endif // USE_API diff --git a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h new file mode 100644 index 0000000000..92960746d9 --- /dev/null +++ b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include "esphome/core/component.h" +#include "esphome/components/api/custom_api_device.h" + +#ifdef USE_API +namespace esphome { +namespace custom_api_device_component { + +using namespace api; + +class CustomAPIDeviceComponent : public Component, public CustomAPIDevice { + public: + void setup() override; + + void on_test_service(); + + // NOLINTNEXTLINE(performance-unnecessary-value-param) + void on_service_with_args(std::string arg_string, int32_t arg_int, bool arg_bool, float arg_float); + + void on_service_with_arrays(std::vector bool_array, std::vector int_array, + std::vector float_array, std::vector string_array); +}; + +} // namespace custom_api_device_component +} // namespace esphome +#endif // USE_API diff --git a/tests/integration/test_api_custom_services.py b/tests/integration/test_api_custom_services.py new file mode 100644 index 0000000000..2862dcc900 --- /dev/null +++ b/tests/integration/test_api_custom_services.py @@ -0,0 +1,144 @@ +"""Integration test for API custom services using CustomAPIDevice.""" + +from __future__ import annotations + +import asyncio +from pathlib import Path +import re + +from aioesphomeapi import UserService, UserServiceArgType +import pytest + +from .types import APIClientConnectedFactory, RunCompiledFunction + + +@pytest.mark.asyncio +async def test_api_custom_services( + yaml_config: str, + run_compiled: RunCompiledFunction, + api_client_connected: APIClientConnectedFactory, +) -> None: + """Test CustomAPIDevice services work correctly with custom_services: true.""" + # Get the path to the external components directory + external_components_path = str( + Path(__file__).parent / "fixtures" / "external_components" + ) + + # Replace the placeholder in the YAML config with the actual path + yaml_config = yaml_config.replace( + "EXTERNAL_COMPONENT_PATH", external_components_path + ) + + loop = asyncio.get_running_loop() + + # Track log messages + yaml_service_future = loop.create_future() + custom_service_future = loop.create_future() + custom_args_future = loop.create_future() + custom_arrays_future = loop.create_future() + + # Patterns to match in logs + yaml_service_pattern = re.compile(r"YAML service called") + custom_service_pattern = re.compile(r"Custom test service called!") + custom_args_pattern = re.compile( + r"Custom service called with: test_string, 456, 1, 78\.90" + ) + custom_arrays_pattern = re.compile( + r"Array service called with 2 bools, 3 ints, 2 floats, 2 strings" + ) + + def check_output(line: str) -> None: + """Check log output for expected messages.""" + if not yaml_service_future.done() and yaml_service_pattern.search(line): + yaml_service_future.set_result(True) + elif not custom_service_future.done() and custom_service_pattern.search(line): + custom_service_future.set_result(True) + elif not custom_args_future.done() and custom_args_pattern.search(line): + custom_args_future.set_result(True) + elif not custom_arrays_future.done() and custom_arrays_pattern.search(line): + custom_arrays_future.set_result(True) + + # Run with log monitoring + async with run_compiled(yaml_config, line_callback=check_output): + async with api_client_connected() as client: + # Verify device info + device_info = await client.device_info() + assert device_info is not None + assert device_info.name == "api-custom-services-test" + + # List services + _, services = await client.list_entities_services() + + # Should have 4 services: 1 YAML + 3 CustomAPIDevice + assert len(services) == 4, f"Expected 4 services, found {len(services)}" + + # Find our services + yaml_service: UserService | None = None + custom_service: UserService | None = None + custom_args_service: UserService | None = None + custom_arrays_service: UserService | None = None + + for service in services: + if service.name == "test_yaml_service": + yaml_service = service + elif service.name == "custom_test_service": + custom_service = service + elif service.name == "custom_service_with_args": + custom_args_service = service + elif service.name == "custom_service_with_arrays": + custom_arrays_service = service + + assert yaml_service is not None, "test_yaml_service not found" + assert custom_service is not None, "custom_test_service not found" + assert custom_args_service is not None, "custom_service_with_args not found" + assert custom_arrays_service is not None, ( + "custom_service_with_arrays not found" + ) + + # Test YAML service + client.execute_service(yaml_service, {}) + await asyncio.wait_for(yaml_service_future, timeout=5.0) + + # Test simple CustomAPIDevice service + client.execute_service(custom_service, {}) + await asyncio.wait_for(custom_service_future, timeout=5.0) + + # Verify custom_args_service arguments + assert len(custom_args_service.args) == 4 + arg_types = {arg.name: arg.type for arg in custom_args_service.args} + assert arg_types["arg_string"] == UserServiceArgType.STRING + assert arg_types["arg_int"] == UserServiceArgType.INT + assert arg_types["arg_bool"] == UserServiceArgType.BOOL + assert arg_types["arg_float"] == UserServiceArgType.FLOAT + + # Test CustomAPIDevice service with arguments + client.execute_service( + custom_args_service, + { + "arg_string": "test_string", + "arg_int": 456, + "arg_bool": True, + "arg_float": 78.9, + }, + ) + await asyncio.wait_for(custom_args_future, timeout=5.0) + + # Verify array service arguments + assert len(custom_arrays_service.args) == 4 + array_arg_types = {arg.name: arg.type for arg in custom_arrays_service.args} + assert array_arg_types["bool_array"] == UserServiceArgType.BOOL_ARRAY + assert array_arg_types["int_array"] == UserServiceArgType.INT_ARRAY + assert array_arg_types["float_array"] == UserServiceArgType.FLOAT_ARRAY + assert array_arg_types["string_array"] == UserServiceArgType.STRING_ARRAY + + # Test CustomAPIDevice service with arrays + client.execute_service( + custom_arrays_service, + { + "bool_array": [True, False], + "int_array": [1, 2, 3], + "float_array": [1.1, 2.2], + "string_array": ["hello", "world"], + }, + ) + await asyncio.wait_for(custom_arrays_future, timeout=5.0)