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) {
56#ifdef USE_API_CUSTOM_SERVICES
62 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
66 template<
typename T,
typename... Ts>
68 const std::array<std::string,
sizeof...(Ts)> &arg_names) {
71 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
93#ifdef USE_API_SERVICES
94 template<
typename T>
void register_service(
void (T::*callback)(),
const std::string &name) {
95#ifdef USE_API_CUSTOM_SERVICES
101 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
105 template<
typename T>
void register_service(
void (T::*callback)(),
const std::string &name) {
108 "register_service() requires 'custom_services: true' in the 'api:' section of your YAML configuration");
112#ifdef USE_API_HOMEASSISTANT_STATES
134 const std::string &attribute =
"") {
135 auto f = std::bind(callback, (T *)
this, std::placeholders::_1);
160 const std::string &attribute =
"") {
161 auto f = std::bind(callback, (T *)
this, entity_id, std::placeholders::_1);
167 const std::string &attribute =
"") {
168 static_assert(
sizeof(T) == 0,
169 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
170 "of your YAML configuration");
175 const std::string &attribute =
"") {
176 static_assert(
sizeof(T) == 0,
177 "subscribe_homeassistant_state() requires 'homeassistant_states: true' in the 'api:' section "
178 "of your YAML configuration");
182#ifdef USE_API_HOMEASSISTANT_SERVICES
216 resp.
data.init(data.size());
217 for (
auto &it : data) {
218 auto &kv = resp.
data.emplace_back();
220 kv.value = it.second;
259 resp.
data.init(data.size());
260 for (
auto &it : data) {
261 auto &kv = resp.
data.emplace_back();
263 kv.value = it.second;
269 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
270 "section of your YAML configuration");
273 template<
typename T =
void>
275 static_assert(
sizeof(T) == 0,
"call_homeassistant_service() requires 'homeassistant_services: true' in the 'api:' "
276 "section of your YAML configuration");
280 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
281 "section of your YAML configuration");
284 template<
typename T =
void>
286 static_assert(
sizeof(T) == 0,
"fire_homeassistant_event() requires 'homeassistant_services: true' in the 'api:' "
287 "section of your YAML configuration");
StringRef is a reference to a string owned by something else.
void register_user_service(UserServiceDescriptor *descriptor)
bool is_connected() const
void send_homeassistant_action(const HomeassistantActionRequest &call)
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...))
FixedVector< HomeassistantServiceMap > data
void set_service(const StringRef &ref)
APIServer * global_api_server