5#ifdef USE_API_HOMEASSISTANT_SERVICES
16 template<
typename T>
static std::string value_to_string(T &&
val) {
return to_string(std::forward<T>(
val)); }
19 static std::string value_to_string(
char *
val) {
20 return val ? std::string(
val) : std::string();
22 static std::string value_to_string(
const char *
val) {
return std::string(
val); }
23 static std::string value_to_string(
const std::string &
val) {
return val; }
24 static std::string value_to_string(std::string &&
val) {
return std::move(
val); }
29 template<
typename F, enable_if_t<!is_invocable<F, X...>
::value,
int> = 0>
32 template<
typename F, enable_if_t<is_invocable<F, X...>
::value,
int> = 0>
34 :
TemplatableValue<std::string, X...>([f](X...
x) -> std::string { return value_to_string(f(
x...)); }) {}
51 template<
typename T>
void set_service(T service) { this->service_ = service; }
56 template<
typename T>
void add_data(std::string key, T value) { this->data_.emplace_back(std::move(key), value); }
58 this->data_template_.emplace_back(std::move(key), value);
61 this->variables_.emplace_back(std::move(key), value);
66 std::string service_value = this->service_.value(
x...);
69 for (
auto &it : this->data_) {
70 resp.
data.emplace_back();
71 auto &kv = resp.
data.back();
73 kv.value = it.value.value(
x...);
75 for (
auto &it : this->data_template_) {
79 kv.value = it.value.value(
x...);
81 for (
auto &it : this->variables_) {
85 kv.value = it.value.value(
x...);
87 this->parent_->send_homeassistant_service_call(resp);
StringRef is a reference to a string owned by something else.
std::string value(X... x)
void set_service(T service)
HomeAssistantServiceCallAction(APIServer *parent, bool is_event)
std::vector< TemplatableKeyValuePair< Ts... > > variables_
void play(Ts... x) override
void add_variable(std::string key, T value)
std::vector< TemplatableKeyValuePair< Ts... > > data_template_
void add_data(std::string key, T value)
void add_data_template(std::string key, T value)
std::vector< TemplatableKeyValuePair< Ts... > > data_
std::vector< HomeassistantServiceMap > data_template
void set_service(const StringRef &ref)
std::vector< HomeassistantServiceMap > data
std::vector< HomeassistantServiceMap > variables
TemplatableKeyValuePair(std::string key, T value)
TemplatableStringValue< Ts... > value
TemplatableStringValue(F value)
TemplatableStringValue(F f)