mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 07:28:10 +01:00
tuya: add time sync callback only once to prevent memleak (#5234)
This commit is contained in:
parent
f26238e824
commit
3a899e28dc
2 changed files with 8 additions and 2 deletions
|
@ -246,8 +246,13 @@ void Tuya::handle_command_(uint8_t command, uint8_t version, const uint8_t *buff
|
||||||
#ifdef USE_TIME
|
#ifdef USE_TIME
|
||||||
if (this->time_id_.has_value()) {
|
if (this->time_id_.has_value()) {
|
||||||
this->send_local_time_();
|
this->send_local_time_();
|
||||||
auto *time_id = *this->time_id_;
|
|
||||||
time_id->add_on_time_sync_callback([this] { this->send_local_time_(); });
|
if (!this->time_sync_callback_registered_) {
|
||||||
|
// tuya mcu supports time, so we let them know when our time changed
|
||||||
|
auto *time_id = *this->time_id_;
|
||||||
|
time_id->add_on_time_sync_callback([this] { this->send_local_time_(); });
|
||||||
|
this->time_sync_callback_registered_ = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "LOCAL_TIME_QUERY is not handled because time is not configured");
|
ESP_LOGW(TAG, "LOCAL_TIME_QUERY is not handled because time is not configured");
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,7 @@ class Tuya : public Component, public uart::UARTDevice {
|
||||||
#ifdef USE_TIME
|
#ifdef USE_TIME
|
||||||
void send_local_time_();
|
void send_local_time_();
|
||||||
optional<time::RealTimeClock *> time_id_{};
|
optional<time::RealTimeClock *> time_id_{};
|
||||||
|
bool time_sync_callback_registered_{false};
|
||||||
#endif
|
#endif
|
||||||
TuyaInitState init_state_ = TuyaInitState::INIT_HEARTBEAT;
|
TuyaInitState init_state_ = TuyaInitState::INIT_HEARTBEAT;
|
||||||
bool init_failed_{false};
|
bool init_failed_{false};
|
||||||
|
|
Loading…
Reference in a new issue