mirror of
https://github.com/esphome/esphome.git
synced 2024-12-04 13:44:40 +01:00
fixed api dependency
This commit is contained in:
parent
cca0adc3bd
commit
e7a50f18f2
@ -2,7 +2,9 @@
|
||||
|
||||
#include "datapoint_component.h"
|
||||
#include "optolink.h"
|
||||
#ifdef USE_API
|
||||
#include "esphome/components/api/api_server.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -268,20 +270,24 @@ void DatapointComponent::subscribe_hass(std::string entity_id, std::function<voi
|
||||
subscription.callbacks.push_back(f);
|
||||
hass_subscriptions_.push_back(subscription);
|
||||
|
||||
api::global_api_server->subscribe_home_assistant_state(
|
||||
entity_id, optional<std::string>(), [this, entity_id](const std::string &state) {
|
||||
ESP_LOGD(TAG, "received schedule plan from HASS entity '%s': %s", entity_id.c_str(), state.c_str());
|
||||
for (auto &subscription : hass_subscriptions_) {
|
||||
if (subscription.last_state != state) {
|
||||
if (subscription.entity_id == entity_id) {
|
||||
subscription.last_state = state;
|
||||
for (auto callback : subscription.callbacks) {
|
||||
callback(state);
|
||||
#ifdef USE_API
|
||||
if (api::global_api_server != nullptr) {
|
||||
api::global_api_server->subscribe_home_assistant_state(
|
||||
entity_id, optional<std::string>(), [this, entity_id](const std::string &state) {
|
||||
ESP_LOGD(TAG, "received schedule plan from HASS entity '%s': %s", entity_id.c_str(), state.c_str());
|
||||
for (auto &subscription : hass_subscriptions_) {
|
||||
if (subscription.last_state != state) {
|
||||
if (subscription.entity_id == entity_id) {
|
||||
subscription.last_state = state;
|
||||
for (auto callback : subscription.callbacks) {
|
||||
callback(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void conv2_100_F::encode(uint8_t *out, DPValue in) {
|
||||
|
Loading…
Reference in New Issue
Block a user