11#ifdef USE_API_SERVICES
15 void (T::*callback)(Ts...))
52#ifdef USE_API_SERVICES
53 template<
typename T,
typename... Ts>
55 const std::array<std::string,
sizeof...(Ts)> &arg_names) {
60 template<
typename T,
typename... Ts>
62 const std::array<std::string,
sizeof...(Ts)> &arg_names) {
65 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
87#ifdef USE_API_SERVICES
88 template<
typename T>
void register_service(
void (T::*callback)(),
const std::string &name) {
93 template<
typename T>
void register_service(
void (T::*callback)(),
const std::string &name) {
96 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
100#ifdef USE_API_HOMEASSISTANT_STATES
122 const std::string &attribute =
"") {
123 auto f = std::bind(callback, (T *)
this, std::placeholders::_1);
148 const std::string &attribute =
"") {
149 auto f = std::bind(callback, (T *)
this, entity_id, std::placeholders::_1);
155 const std::string &attribute =
"") {
156 static_assert(
sizeof(T) == 0,
157 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
158 "of your YAML configuration");
163 const std::string &attribute =
"") {
164 static_assert(
sizeof(T) == 0,
165 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
166 "of your YAML configuration");
170#ifdef USE_API_HOMEASSISTANT_SERVICES
204 for (
auto &it : data) {
205 resp.
data.emplace_back();
206 auto &kv = resp.
data.back();
208 kv.value = it.second;
247 for (
auto &it : data) {
248 resp.
data.emplace_back();
249 auto &kv = resp.
data.back();
251 kv.value = it.second;
257 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
258 "section of your YAML configuration");
261 template<
typename T =
void>
263 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
264 "section of your YAML configuration");
268 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
269 "section of your YAML configuration");
272 template<
typename T =
void>
274 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
275 "section of your YAML configuration");
StringRef is a reference to a string owned by something else.
void send_homeassistant_service_call(const HomeassistantServiceResponse &call)
void register_user_service(UserServiceDescriptor *descriptor)
bool is_connected() const
void subscribe_home_assistant_state(std::string entity_id, optional< std::string > attribute, std::function< void(std::string)> f)
void subscribe_homeassistant_state(void(T::*callback)(std::string), const std::string &entity_id, const std::string &attribute="")
Subscribe to the state (or attribute state) of an entity from Home Assistant.
void fire_homeassistant_event(const std::string &service_name, const std::map< std::string, std::string > &data)
void register_service(void(T::*callback)(Ts...), const std::string &name, const std::array< std::string, sizeof...(Ts)> &arg_names)
Register a custom native API service that will show up in Home Assistant.
void fire_homeassistant_event(const std::string &event_name)
void call_homeassistant_service(const std::string &service_name)
Call a Home Assistant service from ESPHome.
void register_service(void(T::*callback)(), const std::string &name)
Register a custom native API service that will show up in Home Assistant.
void fire_homeassistant_event(const std::string &event_name)
Fire an ESPHome event in Home Assistant.
bool is_connected() const
Return if a client (such as Home Assistant) is connected to the native API.
void fire_homeassistant_event(const std::string &service_name, const std::map< std::string, std::string > &data)
Fire an ESPHome event in Home Assistant.
void call_homeassistant_service(const std::string &service_name)
void subscribe_homeassistant_state(void(T::*callback)(std::string, std::string), const std::string &entity_id, const std::string &attribute="")
Subscribe to the state (or attribute state) of an entity from Home Assistant.
void call_homeassistant_service(const std::string &service_name, const std::map< std::string, std::string > &data)
Call a Home Assistant service from ESPHome.
void call_homeassistant_service(const std::string &service_name, const std::map< std::string, std::string > &data)
void(T::* callback_)(Ts...)
void execute(Ts... x) override
CustomAPIDeviceService(const std::string &name, const std::array< std::string, sizeof...(Ts)> &arg_names, T *obj, void(T::*callback)(Ts...))
void set_service(const StringRef &ref)
std::vector< HomeassistantServiceMap > data
APIServer * global_api_server