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
137 const std::string &attribute =
"") {
138 auto f = std::bind(callback, (T *)
this, std::placeholders::_1);
163 const std::string &attribute =
"") {
164 auto f = std::bind(callback, (T *)
this, entity_id, std::placeholders::_1);
170 const std::string &attribute =
"") {
171 static_assert(
sizeof(T) == 0,
172 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
173 "of your YAML configuration");
178 const std::string &attribute =
"") {
179 static_assert(
sizeof(T) == 0,
180 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
181 "of your YAML configuration");
185#ifdef USE_API_HOMEASSISTANT_SERVICES
219 resp.
data.init(data.size());
220 for (
auto &it : data) {
221 auto &kv = resp.
data.emplace_back();
223 kv.value = it.second;
262 resp.
data.init(data.size());
263 for (
auto &it : data) {
264 auto &kv = resp.
data.emplace_back();
266 kv.value = it.second;
272 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
273 "section of your YAML configuration");
276 template<
typename T =
void>
278 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
279 "section of your YAML configuration");
283 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
284 "section of your YAML configuration");
287 template<
typename T =
void>
289 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
290 "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)
bool is_connected(bool state_subscription_only=false) const
void subscribe_home_assistant_state(const char *entity_id, const char *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 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
void set_service(const StringRef &ref)
APIServer * global_api_server