mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 23:48:11 +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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class Optolink;
|
|||
|
||||
struct HassSubscription {
|
||||
std::string entity_id;
|
||||
std::string last_state;
|
||||
std::vector<std::function<void(std::string)>> callbacks;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue