6#ifdef USE_API_USER_DEFINED_ACTIONS
11#ifdef USE_API_USER_DEFINED_ACTIONS
15 void (T::*callback)(Ts...))
20 void execute(uint32_t ,
bool , Ts...
x)
override {
55#ifdef USE_API_USER_DEFINED_ACTIONS
56 template<
typename T,
typename... Ts>
58 const std::array<std::string,
sizeof...(Ts)> &arg_names) {
59#ifdef USE_API_CUSTOM_SERVICES
65 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
69 template<
typename T,
typename... Ts>
71 const std::array<std::string,
sizeof...(Ts)> &arg_names) {
74 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
96#ifdef USE_API_USER_DEFINED_ACTIONS
97 template<
typename T>
void register_service(
void (T::*callback)(),
const std::string &name) {
98#ifdef USE_API_CUSTOM_SERVICES
104 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
108 template<
typename T>
void register_service(
void (T::*callback)(),
const std::string &name) {
111 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
115#ifdef USE_API_HOMEASSISTANT_STATES
138 const std::string &attribute =
"") {
139 auto f = std::bind(callback, (T *)
this, std::placeholders::_1);
148 ESPDEPRECATED(
"Use void callback(StringRef) instead. Will be removed in 2027.1.0.",
"2026.1.0")
150 const std::
string &attribute = "") {
151 auto f = std::bind(callback, (T *)
this, std::placeholders::_1);
154 std::function<
void(
const std::string &)>(f));
178 const std::string &attribute =
"") {
179 auto f = std::bind(callback, (T *)
this, entity_id, std::placeholders::_1);
188 ESPDEPRECATED(
"Use void callback(const std::string &, StringRef) instead. Will be removed in 2027.1.0.",
"2026.1.0")
190 const std::
string &attribute = "") {
191 auto f = std::bind(callback, (T *)
this, entity_id, std::placeholders::_1);
194 std::function<
void(
const std::string &)>(f));
199 const std::string &attribute =
"") {
200 static_assert(
sizeof(T) == 0,
201 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
202 "of your YAML configuration");
207 const std::string &attribute =
"") {
208 static_assert(
sizeof(T) == 0,
209 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
210 "of your YAML configuration");
215 const std::string &attribute =
"") {
216 static_assert(
sizeof(T) == 0,
217 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
218 "of your YAML configuration");
223 const std::string &attribute =
"") {
224 static_assert(
sizeof(T) == 0,
225 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
226 "of your YAML configuration");
230#ifdef USE_API_HOMEASSISTANT_SERVICES
264 resp.
data.init(data.size());
265 for (
auto &it : data) {
266 auto &kv = resp.
data.emplace_back();
307 resp.
data.init(data.size());
308 for (
auto &it : data) {
309 auto &kv = resp.
data.emplace_back();
317 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
318 "section of your YAML configuration");
321 template<
typename T =
void>
323 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
324 "section of your YAML configuration");
328 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
329 "section of your YAML configuration");
332 template<
typename T =
void>
334 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
335 "section of your YAML configuration");
StringRef is a reference to a string owned by something else.
void register_user_service(UserServiceDescriptor *descriptor)
void send_homeassistant_action(const HomeassistantActionRequest &call)
void subscribe_home_assistant_state(const char *entity_id, const char *attribute, std::function< void(StringRef)> f)
bool is_connected(bool state_subscription_only=false) const
void subscribe_homeassistant_state(void(T::*callback)(std::string), const std::string &entity_id, const std::string &attribute="")
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.
ESPDEPRECATED("Use void callback(StringRef) instead. Will be removed in 2027.1.0.", "2026.1.0") void subscribe_homeassistant_state(void(T
Subscribe to the state (or attribute state) of an entity from Home Assistant (legacy std::string vers...
void fire_homeassistant_event(const std::string &event_name)
void subscribe_homeassistant_state(void(T::*callback)(const std::string &, StringRef), 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)
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.
ESPDEPRECATED("Use void callback(const std::string &, StringRef) instead. Will be removed in 2027.1.0.", "2026.1.0") void subscribe_homeassistant_state(void(T
Subscribe to the state (or attribute state) of an entity from Home Assistant (legacy std::string vers...
void subscribe_homeassistant_state(void(T::*callback)(StringRef), 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)
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="")
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 execute(uint32_t, bool, Ts... x) override
void(T::* callback_)(Ts...)
CustomAPIDeviceService(const std::string &name, const std::array< std::string, sizeof...(Ts)> &arg_names, T *obj, void(T::*callback)(Ts...))
FixedVector< HomeassistantServiceMap > data
APIServer * global_api_server