mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
optimized HASS value update for text_sensor
This commit is contained in:
parent
6094830625
commit
cf33d4b824
2 changed files with 7 additions and 3 deletions
|
@ -272,12 +272,15 @@ void DatapointComponent::subscribe_hass(std::string entity_id, std::function<voi
|
||||||
entity_id, optional<std::string>(), [this, entity_id](const std::string &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());
|
ESP_LOGD(TAG, "received schedule plan from HASS entity '%s': %s", entity_id.c_str(), state.c_str());
|
||||||
for (auto &subscription : hass_subscriptions_) {
|
for (auto &subscription : hass_subscriptions_) {
|
||||||
|
if (subscription.last_state != state) {
|
||||||
if (subscription.entity_id == entity_id) {
|
if (subscription.entity_id == entity_id) {
|
||||||
|
subscription.last_state = state;
|
||||||
for (auto callback : subscription.callbacks) {
|
for (auto callback : subscription.callbacks) {
|
||||||
callback(state);
|
callback(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Optolink;
|
||||||
|
|
||||||
struct HassSubscription {
|
struct HassSubscription {
|
||||||
std::string entity_id;
|
std::string entity_id;
|
||||||
|
std::string last_state;
|
||||||
std::vector<std::function<void(std::string)>> callbacks;
|
std::vector<std::function<void(std::string)>> callbacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue