ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
user_services.cpp
Go to the documentation of this file.
1#include "user_services.h"
2#include "esphome/core/log.h"
3
4namespace esphome::api {
5
6template<> bool get_execute_arg_value<bool>(const ExecuteServiceArgument &arg) { return arg.bool_; }
8 if (arg.legacy_int != 0)
9 return arg.legacy_int;
10 return arg.int_;
11}
12template<> float get_execute_arg_value<float>(const ExecuteServiceArgument &arg) { return arg.float_; }
13template<> std::string get_execute_arg_value<std::string>(const ExecuteServiceArgument &arg) { return arg.string_; }
14
15// Legacy std::vector versions for external components using custom_api_device.h - optimized with reserve
16template<> std::vector<bool> get_execute_arg_value<std::vector<bool>>(const ExecuteServiceArgument &arg) {
17 std::vector<bool> result;
18 result.reserve(arg.bool_array.size());
19 result.insert(result.end(), arg.bool_array.begin(), arg.bool_array.end());
20 return result;
21}
22template<> std::vector<int32_t> get_execute_arg_value<std::vector<int32_t>>(const ExecuteServiceArgument &arg) {
23 std::vector<int32_t> result;
24 result.reserve(arg.int_array.size());
25 result.insert(result.end(), arg.int_array.begin(), arg.int_array.end());
26 return result;
27}
28template<> std::vector<float> get_execute_arg_value<std::vector<float>>(const ExecuteServiceArgument &arg) {
29 std::vector<float> result;
30 result.reserve(arg.float_array.size());
31 result.insert(result.end(), arg.float_array.begin(), arg.float_array.end());
32 return result;
33}
34template<> std::vector<std::string> get_execute_arg_value<std::vector<std::string>>(const ExecuteServiceArgument &arg) {
35 std::vector<std::string> result;
36 result.reserve(arg.string_array.size());
37 result.insert(result.end(), arg.string_array.begin(), arg.string_array.end());
38 return result;
39}
40
41// New FixedVector const reference versions for YAML-generated services - zero-copy
42template<>
46template<>
50template<>
54template<>
59
64
65// Legacy std::vector versions for external components using custom_api_device.h
76
77// New FixedVector const reference versions for YAML-generated services
90
91} // namespace esphome::api
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:184
@ SERVICE_ARG_TYPE_BOOL_ARRAY
Definition api_pb2.h:72
@ SERVICE_ARG_TYPE_STRING_ARRAY
Definition api_pb2.h:75
@ SERVICE_ARG_TYPE_FLOAT_ARRAY
Definition api_pb2.h:74
float get_execute_arg_value< float >(const ExecuteServiceArgument &arg)
bool get_execute_arg_value< bool >(const ExecuteServiceArgument &arg)
int32_t get_execute_arg_value< int32_t >(const ExecuteServiceArgument &arg)
enums::ServiceArgType to_service_arg_type()
enums::ServiceArgType to_service_arg_type< int32_t >()
enums::ServiceArgType to_service_arg_type< bool >()
enums::ServiceArgType to_service_arg_type< std::string >()
std::string get_execute_arg_value< std::string >(const ExecuteServiceArgument &arg)
T get_execute_arg_value(const ExecuteServiceArgument &arg)
enums::ServiceArgType to_service_arg_type< float >()