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(
const char *
val) {
return std::string(
val); }
20 static std::string value_to_string(
const std::string &
val) {
return val; }
21 static std::string value_to_string(std::string &&
val) {
return std::move(
val); }
26 template<
typename F, enable_if_t<!is_invocable<F, X...>
::value,
int> = 0>
29 template<
typename F, enable_if_t<is_invocable<F, X...>
::value,
int> = 0>
31 :
TemplatableValue<std::string, X...>([f](X...
x) -> std::string { return value_to_string(f(
x...)); }) {}
45 template<
typename T>
void set_service(T service) { this->service_ = service; }
47 template<
typename T>
void add_data(std::string key, T value) {
59 resp.
service = this->service_.value(
x...);
61 for (
auto &it : this->data_) {
64 kv.
value = it.value.value(
x...);
65 resp.
data.push_back(kv);
67 for (
auto &it : this->data_template_) {
70 kv.
value = it.value.value(
x...);
73 for (
auto &it : this->variables_) {
76 kv.
value = it.value.value(
x...);
79 this->parent_->send_homeassistant_service_call(resp);
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
std::vector< HomeassistantServiceMap > data
std::vector< HomeassistantServiceMap > variables
TemplatableKeyValuePair(std::string key, T value)
TemplatableStringValue< Ts... > value
TemplatableStringValue(F value)
TemplatableStringValue(F f)
Providing packet encoding functions for exchanging data with a remote host.