5#ifdef USE_API_HOMEASSISTANT_SERVICES
11#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
23 requires(!std::is_pointer_v<std::remove_cvref_t<T>>)
25 return to_string(std::forward<T>(
val));
36 std::string (*
fn)(
const Ts &...);
44#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
53#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
56 if (data ==
nullptr || data_len == 0)
67#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
75#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
91 uint8_t data_template_count, uint8_t variables_count)
100#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
109#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
116 void play(
const Ts &...
x)
override {
121 size_t lambda_count = 0;
122 for (
size_t i = 0; i < total; i++)
123 lambda_count += fields[i].fn !=
nullptr;
125 results.
init(lambda_count);
126 auto string_ref = [](
const char *str) {
return ProgmemStringRef(str, ESPHOME_strlen_P(str)); };
127 auto value_ref = [&](
const Field &field) {
128 if (field.fn ==
nullptr)
129 return string_ref(field.value);
135 for (uint8_t i = 0; i <
count; i++, fields++) {
137 kv.key = string_ref(fields->
key);
138 kv.value = value_ref(*fields);
143 resp.
service = value_ref(*fields++);
145 fill(resp.
data, this->data_count_);
147 fill(resp.
variables, this->variables_count_);
149#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
150#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
152 std::string response_template_value;
156 static uint32_t call_id_counter = 1;
157 uint32_t call_id = call_id_counter++;
159#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
170 auto captured_args = std::make_tuple(
x...);
173 [
this, &response](
auto &&...args) {
175#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
208#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
209#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avo...
T & back()
Access last element (no bounds checking - matches std::vector behavior) Caller must ensure vector is ...
T & emplace_back(Args &&...args)
Emplace element without bounds checking - constructs in-place with arguments Caller must ensure suffi...
void push_back(const T &value)
Add element without bounds checking Caller must ensure sufficient capacity was allocated via init() S...
A string that may live in flash (on ESP8266): pointer and length, with no byte-reading operations.
StringRef is a reference to a string owned by something else.
Primary TemplatableValue: stores either a constant value or a function pointer.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
void register_action_response_callback(uint32_t call_id, ActionResponseCallback callback)
void send_homeassistant_action(const HomeassistantActionRequest &call)
ActionResponse(bool success, StringRef error_message)
JsonDocument json_document_
const StringRef & get_error_message() const
JsonObjectConst get_json() const
ActionResponse(bool success, StringRef error_message, const uint8_t *data, size_t data_len)
Trigger< JsonObjectConst, Ts... > success_trigger_with_response_
HomeAssistantServiceCallAction(APIServer *parent, bool is_event, const Field *fields, uint8_t data_count, uint8_t data_template_count, uint8_t variables_count)
fields is a codegen table: the action or event name (no key), then the data, data_template and variab...
Trigger< std::string, Ts... > error_trigger_
void play(const Ts &...x) override
uint8_t data_template_count_
Trigger< Ts... > * get_success_trigger()
Trigger< std::string, Ts... > * get_error_trigger()
TemplatableValue< std::string, Ts... > response_template_
Trigger< Ts... > success_trigger_
Trigger< JsonObjectConst, Ts... > * get_success_trigger_with_response()
void set_response_template(T response_template)
struct esphome::api::HomeAssistantServiceCallAction::Flags flags_
void set_wants_response()
FixedVector< HomeassistantServiceMap > variables
FixedVector< HomeassistantServiceMap > data
StringRef response_template
FixedVector< HomeassistantServiceMap > data_template
std::function< void(const ActionResponse &, Ts...)> ActionResponseCallback
std::string field_to_string(T &&val)
bool parse_json(const std::string &data, const json_parse_t &f)
Parse a JSON string and run the provided json parse function if it's valid.
A key and value from codegen; on ESP8266 the table and its strings are in flash.
static std::string call_lambda(const Ts &...x)
static constexpr HomeAssistantField from_lambda(const char *key, F)
std::string(* fn)(const Ts &...)
uint8_t has_response_template