Revert nextion clang-tidy changes (#2566)

This commit is contained in:
Otto Winter 2021-10-20 20:31:13 +02:00 committed by Jesse Hills
parent 996ec59d28
commit 3af297aa76
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A
13 changed files with 78 additions and 70 deletions

View file

@ -33,7 +33,7 @@ void NextionBinarySensor::update() {
if (this->variable_name_.empty()) // This is a touch component if (this->variable_name_.empty()) // This is a touch component
return; return;
this->nextion_->add_to_get_queue(shared_from_this()); this->nextion_->add_to_get_queue(this);
} }
void NextionBinarySensor::set_state(bool state, bool publish, bool send_to_nextion) { void NextionBinarySensor::set_state(bool state, bool publish, bool send_to_nextion) {
@ -48,7 +48,7 @@ void NextionBinarySensor::set_state(bool state, bool publish, bool send_to_nexti
this->needs_to_send_update_ = true; this->needs_to_send_update_ = true;
} else { } else {
this->needs_to_send_update_ = false; this->needs_to_send_update_ = false;
this->nextion_->add_no_result_to_queue_with_set(shared_from_this(), (int) state); this->nextion_->add_no_result_to_queue_with_set(this, (int) state);
} }
} }

View file

@ -10,8 +10,7 @@ class NextionBinarySensor;
class NextionBinarySensor : public NextionComponent, class NextionBinarySensor : public NextionComponent,
public binary_sensor::BinarySensorInitiallyOff, public binary_sensor::BinarySensorInitiallyOff,
public PollingComponent, public PollingComponent {
public std::enable_shared_from_this<NextionBinarySensor> {
public: public:
NextionBinarySensor(NextionBase *nextion) { this->nextion_ = nextion; } NextionBinarySensor(NextionBase *nextion) { this->nextion_ = nextion; }

View file

@ -196,7 +196,7 @@ void Nextion::print_queue_members_() {
ESP_LOGN(TAG, "print_queue_members_ (top 10) size %zu", this->nextion_queue_.size()); ESP_LOGN(TAG, "print_queue_members_ (top 10) size %zu", this->nextion_queue_.size());
ESP_LOGN(TAG, "*******************************************"); ESP_LOGN(TAG, "*******************************************");
int count = 0; int count = 0;
for (auto &i : this->nextion_queue_) { for (auto *i : this->nextion_queue_) {
if (count++ == 10) if (count++ == 10)
break; break;
@ -257,9 +257,8 @@ bool Nextion::remove_from_q_(bool report_empty) {
return false; return false;
} }
auto nb = std::move(this->nextion_queue_.front()); NextionQueue *nb = this->nextion_queue_.front();
this->nextion_queue_.pop_front(); NextionComponentBase *component = nb->component;
auto &component = nb->component;
ESP_LOGN(TAG, "Removing %s from the queue", component->get_variable_name().c_str()); ESP_LOGN(TAG, "Removing %s from the queue", component->get_variable_name().c_str());
@ -267,8 +266,10 @@ bool Nextion::remove_from_q_(bool report_empty) {
if (component->get_variable_name() == "sleep_wake") { if (component->get_variable_name() == "sleep_wake") {
this->is_sleeping_ = false; this->is_sleeping_ = false;
} }
delete component; // NOLINT(cppcoreguidelines-owning-memory)
} }
delete nb; // NOLINT(cppcoreguidelines-owning-memory)
this->nextion_queue_.pop_front();
return true; return true;
} }
@ -357,7 +358,7 @@ void Nextion::process_nextion_commands_() {
int index = 0; int index = 0;
int found = -1; int found = -1;
for (auto &nb : this->nextion_queue_) { for (auto &nb : this->nextion_queue_) {
auto &component = nb->component; NextionComponentBase *component = nb->component;
if (component->get_queue_type() == NextionQueueType::WAVEFORM_SENSOR) { if (component->get_queue_type() == NextionQueueType::WAVEFORM_SENSOR) {
ESP_LOGW(TAG, "Nextion reported invalid Waveform ID %d or Channel # %d was used!", ESP_LOGW(TAG, "Nextion reported invalid Waveform ID %d or Channel # %d was used!",
@ -368,6 +369,9 @@ void Nextion::process_nextion_commands_() {
found = index; found = index;
delete component; // NOLINT(cppcoreguidelines-owning-memory)
delete nb; // NOLINT(cppcoreguidelines-owning-memory)
break; break;
} }
++index; ++index;
@ -464,9 +468,8 @@ void Nextion::process_nextion_commands_() {
break; break;
} }
auto nb = std::move(this->nextion_queue_.front()); NextionQueue *nb = this->nextion_queue_.front();
this->nextion_queue_.pop_front(); NextionComponentBase *component = nb->component;
auto &component = nb->component;
if (component->get_queue_type() != NextionQueueType::TEXT_SENSOR) { if (component->get_queue_type() != NextionQueueType::TEXT_SENSOR) {
ESP_LOGE(TAG, "ERROR: Received string return but next in queue \"%s\" is not a text sensor", ESP_LOGE(TAG, "ERROR: Received string return but next in queue \"%s\" is not a text sensor",
@ -477,6 +480,9 @@ void Nextion::process_nextion_commands_() {
component->set_state_from_string(to_process, true, false); component->set_state_from_string(to_process, true, false);
} }
delete nb; // NOLINT(cppcoreguidelines-owning-memory)
this->nextion_queue_.pop_front();
break; break;
} }
// 0x71 0x01 0x02 0x03 0x04 0xFF 0xFF 0xFF // 0x71 0x01 0x02 0x03 0x04 0xFF 0xFF 0xFF
@ -505,9 +511,8 @@ void Nextion::process_nextion_commands_() {
++dataindex; ++dataindex;
} }
auto nb = std::move(this->nextion_queue_.front()); NextionQueue *nb = this->nextion_queue_.front();
this->nextion_queue_.pop_front(); NextionComponentBase *component = nb->component;
auto &component = nb->component;
if (component->get_queue_type() != NextionQueueType::SENSOR && if (component->get_queue_type() != NextionQueueType::SENSOR &&
component->get_queue_type() != NextionQueueType::BINARY_SENSOR && component->get_queue_type() != NextionQueueType::BINARY_SENSOR &&
@ -521,6 +526,9 @@ void Nextion::process_nextion_commands_() {
component->set_state_from_int(value, true, false); component->set_state_from_int(value, true, false);
} }
delete nb; // NOLINT(cppcoreguidelines-owning-memory)
this->nextion_queue_.pop_front();
break; break;
} }
@ -682,7 +690,7 @@ void Nextion::process_nextion_commands_() {
int index = 0; int index = 0;
int found = -1; int found = -1;
for (auto &nb : this->nextion_queue_) { for (auto &nb : this->nextion_queue_) {
auto &component = nb->component; auto component = nb->component;
if (component->get_queue_type() == NextionQueueType::WAVEFORM_SENSOR) { if (component->get_queue_type() == NextionQueueType::WAVEFORM_SENSOR) {
size_t buffer_to_send = component->get_wave_buffer().size() < 255 ? component->get_wave_buffer().size() size_t buffer_to_send = component->get_wave_buffer().size() < 255 ? component->get_wave_buffer().size()
: 255; // ADDT command can only send 255 : 255; // ADDT command can only send 255
@ -699,6 +707,8 @@ void Nextion::process_nextion_commands_() {
component->get_wave_buffer().begin() + buffer_to_send); component->get_wave_buffer().begin() + buffer_to_send);
} }
found = index; found = index;
delete component; // NOLINT(cppcoreguidelines-owning-memory)
delete nb; // NOLINT(cppcoreguidelines-owning-memory)
break; break;
} }
++index; ++index;
@ -727,7 +737,7 @@ void Nextion::process_nextion_commands_() {
if (!this->nextion_queue_.empty() && this->nextion_queue_.front()->queue_time + this->max_q_age_ms_ < ms) { if (!this->nextion_queue_.empty() && this->nextion_queue_.front()->queue_time + this->max_q_age_ms_ < ms) {
for (int i = 0; i < this->nextion_queue_.size(); i++) { for (int i = 0; i < this->nextion_queue_.size(); i++) {
auto &component = this->nextion_queue_[i]->component; NextionComponentBase *component = this->nextion_queue_[i]->component;
if (this->nextion_queue_[i]->queue_time + this->max_q_age_ms_ < ms) { if (this->nextion_queue_[i]->queue_time + this->max_q_age_ms_ < ms) {
if (this->nextion_queue_[i]->queue_time == 0) if (this->nextion_queue_[i]->queue_time == 0)
ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\" queue_time 0", ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\" queue_time 0",
@ -744,8 +754,11 @@ void Nextion::process_nextion_commands_() {
if (component->get_variable_name() == "sleep_wake") { if (component->get_variable_name() == "sleep_wake") {
this->is_sleeping_ = false; this->is_sleeping_ = false;
} }
delete component; // NOLINT(cppcoreguidelines-owning-memory)
} }
delete this->nextion_queue_[i]; // NOLINT(cppcoreguidelines-owning-memory)
this->nextion_queue_.erase(this->nextion_queue_.begin() + i); this->nextion_queue_.erase(this->nextion_queue_.begin() + i);
i--; i--;
@ -899,16 +912,18 @@ uint16_t Nextion::recv_ret_string_(std::string &response, uint32_t timeout, bool
* @param variable_name Name for the queue * @param variable_name Name for the queue
*/ */
void Nextion::add_no_result_to_queue_(const std::string &variable_name) { void Nextion::add_no_result_to_queue_(const std::string &variable_name) {
auto nextion_queue = make_unique<nextion::NextionQueue>(); // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
nextion_queue->component = make_unique<nextion::NextionComponentBase>(); // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
nextion_queue->component = new nextion::NextionComponentBase;
nextion_queue->component->set_variable_name(variable_name); nextion_queue->component->set_variable_name(variable_name);
nextion_queue->queue_time = millis(); nextion_queue->queue_time = millis();
ESP_LOGN(TAG, "Add to queue type: NORESULT component %s", nextion_queue->component->get_variable_name().c_str()); this->nextion_queue_.push_back(nextion_queue);
this->nextion_queue_.push_back(std::move(nextion_queue)); ESP_LOGN(TAG, "Add to queue type: NORESULT component %s", nextion_queue->component->get_variable_name().c_str());
} }
/** /**
@ -979,7 +994,7 @@ bool Nextion::add_no_result_to_queue_with_printf_(const std::string &variable_na
* @param is_sleep_safe The command is safe to send when the Nextion is sleeping * @param is_sleep_safe The command is safe to send when the Nextion is sleeping
*/ */
void Nextion::add_no_result_to_queue_with_set(std::shared_ptr<NextionComponentBase> component, int state_value) { void Nextion::add_no_result_to_queue_with_set(NextionComponentBase *component, int state_value) {
this->add_no_result_to_queue_with_set(component->get_variable_name(), component->get_variable_name_to_send(), this->add_no_result_to_queue_with_set(component->get_variable_name(), component->get_variable_name_to_send(),
state_value); state_value);
} }
@ -1007,8 +1022,7 @@ void Nextion::add_no_result_to_queue_with_set_internal_(const std::string &varia
* @param state_value String value to set * @param state_value String value to set
* @param is_sleep_safe The command is safe to send when the Nextion is sleeping * @param is_sleep_safe The command is safe to send when the Nextion is sleeping
*/ */
void Nextion::add_no_result_to_queue_with_set(std::shared_ptr<NextionComponentBase> component, void Nextion::add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) {
const std::string &state_value) {
this->add_no_result_to_queue_with_set(component->get_variable_name(), component->get_variable_name_to_send(), this->add_no_result_to_queue_with_set(component->get_variable_name(), component->get_variable_name_to_send(),
state_value); state_value);
} }
@ -1028,11 +1042,12 @@ void Nextion::add_no_result_to_queue_with_set_internal_(const std::string &varia
state_value.c_str()); state_value.c_str());
} }
void Nextion::add_to_get_queue(std::shared_ptr<NextionComponentBase> component) { void Nextion::add_to_get_queue(NextionComponentBase *component) {
if ((!this->is_setup() && !this->ignore_is_setup_)) if ((!this->is_setup() && !this->ignore_is_setup_))
return; return;
auto nextion_queue = make_unique<nextion::NextionQueue>(); // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
nextion_queue->component = component; nextion_queue->component = component;
nextion_queue->queue_time = millis(); nextion_queue->queue_time = millis();
@ -1043,7 +1058,7 @@ void Nextion::add_to_get_queue(std::shared_ptr<NextionComponentBase> component)
std::string command = "get " + component->get_variable_name_to_send(); std::string command = "get " + component->get_variable_name_to_send();
if (this->send_command_(command)) { if (this->send_command_(command)) {
this->nextion_queue_.push_back(std::move(nextion_queue)); this->nextion_queue_.push_back(nextion_queue);
} }
} }
@ -1055,13 +1070,15 @@ void Nextion::add_to_get_queue(std::shared_ptr<NextionComponentBase> component)
* @param buffer_to_send The buffer size * @param buffer_to_send The buffer size
* @param buffer_size The buffer data * @param buffer_size The buffer data
*/ */
void Nextion::add_addt_command_to_queue(std::shared_ptr<NextionComponentBase> component) { void Nextion::add_addt_command_to_queue(NextionComponentBase *component) {
if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping()) if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
return; return;
auto nextion_queue = make_unique<nextion::NextionQueue>(); // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
nextion_queue->component = std::make_shared<nextion::NextionComponentBase>(); // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
nextion_queue->component = new nextion::NextionComponentBase;
nextion_queue->queue_time = millis(); nextion_queue->queue_time = millis();
size_t buffer_to_send = component->get_wave_buffer_size() < 255 ? component->get_wave_buffer_size() size_t buffer_to_send = component->get_wave_buffer_size() < 255 ? component->get_wave_buffer_size()
@ -1070,7 +1087,7 @@ void Nextion::add_addt_command_to_queue(std::shared_ptr<NextionComponentBase> co
std::string command = "addt " + to_string(component->get_component_id()) + "," + std::string command = "addt " + to_string(component->get_component_id()) + "," +
to_string(component->get_wave_channel_id()) + "," + to_string(buffer_to_send); to_string(component->get_wave_channel_id()) + "," + to_string(buffer_to_send);
if (this->send_command_(command)) { if (this->send_command_(command)) {
this->nextion_queue_.push_back(std::move(nextion_queue)); this->nextion_queue_.push_back(nextion_queue);
} }
} }

View file

@ -707,18 +707,17 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
void set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state); void set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state);
void set_nextion_text_state(const std::string &name, const std::string &state); void set_nextion_text_state(const std::string &name, const std::string &state);
void add_no_result_to_queue_with_set(std::shared_ptr<NextionComponentBase> component, int state_value) override; void add_no_result_to_queue_with_set(NextionComponentBase *component, int state_value) override;
void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send, void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send,
int state_value) override; int state_value) override;
void add_no_result_to_queue_with_set(std::shared_ptr<NextionComponentBase> component, void add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) override;
const std::string &state_value) override;
void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send, void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send,
const std::string &state_value) override; const std::string &state_value) override;
void add_to_get_queue(std::shared_ptr<NextionComponentBase> component) override; void add_to_get_queue(NextionComponentBase *component) override;
void add_addt_command_to_queue(std::shared_ptr<NextionComponentBase> component) override; void add_addt_command_to_queue(NextionComponentBase *component) override;
void update_components_by_prefix(const std::string &prefix); void update_components_by_prefix(const std::string &prefix);
@ -729,7 +728,7 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
void set_auto_wake_on_touch_internal(bool auto_wake_on_touch) { this->auto_wake_on_touch_ = auto_wake_on_touch; } void set_auto_wake_on_touch_internal(bool auto_wake_on_touch) { this->auto_wake_on_touch_ = auto_wake_on_touch; }
protected: protected:
std::deque<std::unique_ptr<NextionQueue>> nextion_queue_; std::deque<NextionQueue *> nextion_queue_;
uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag); uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag);
void all_components_send_state_(bool force_update = false); void all_components_send_state_(bool force_update = false);
uint64_t comok_sent_ = 0; uint64_t comok_sent_ = 0;

View file

@ -24,19 +24,18 @@ class NextionBase;
class NextionBase { class NextionBase {
public: public:
virtual void add_no_result_to_queue_with_set(std::shared_ptr<NextionComponentBase> component, int state_value) = 0; virtual void add_no_result_to_queue_with_set(NextionComponentBase *component, int state_value) = 0;
virtual void add_no_result_to_queue_with_set(const std::string &variable_name, virtual void add_no_result_to_queue_with_set(const std::string &variable_name,
const std::string &variable_name_to_send, int state_value) = 0; const std::string &variable_name_to_send, int state_value) = 0;
virtual void add_no_result_to_queue_with_set(std::shared_ptr<NextionComponentBase> component, virtual void add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) = 0;
const std::string &state_value) = 0;
virtual void add_no_result_to_queue_with_set(const std::string &variable_name, virtual void add_no_result_to_queue_with_set(const std::string &variable_name,
const std::string &variable_name_to_send, const std::string &variable_name_to_send,
const std::string &state_value) = 0; const std::string &state_value) = 0;
virtual void add_addt_command_to_queue(std::shared_ptr<NextionComponentBase> component) = 0; virtual void add_addt_command_to_queue(NextionComponentBase *component) = 0;
virtual void add_to_get_queue(std::shared_ptr<NextionComponentBase> component) = 0; virtual void add_to_get_queue(NextionComponentBase *component) = 0;
virtual void set_component_background_color(const char *component, Color color) = 0; virtual void set_component_background_color(const char *component, Color color) = 0;
virtual void set_component_pressed_background_color(const char *component, Color color) = 0; virtual void set_component_pressed_background_color(const char *component, Color color) = 0;

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <utility> #include <utility>
#include <memory>
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
namespace esphome { namespace esphome {
@ -23,7 +22,7 @@ class NextionComponentBase;
class NextionQueue { class NextionQueue {
public: public:
virtual ~NextionQueue() = default; virtual ~NextionQueue() = default;
std::shared_ptr<NextionComponentBase> component; NextionComponentBase *component;
uint32_t queue_time = 0; uint32_t queue_time = 0;
}; };

View file

@ -281,12 +281,14 @@ void Nextion::upload_tft() {
#endif #endif
// NOLINTNEXTLINE(readability-static-accessed-through-instance) // NOLINTNEXTLINE(readability-static-accessed-through-instance)
ESP_LOGD(TAG, "Allocating buffer size %d, Heap size is %u", chunk_size, ESP.getFreeHeap()); ESP_LOGD(TAG, "Allocating buffer size %d, Heap size is %u", chunk_size, ESP.getFreeHeap());
this->transfer_buffer_ = new (std::nothrow) uint8_t[chunk_size]; // NOLINT(cppcoreguidelines-owning-memory) // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
this->transfer_buffer_ = new (std::nothrow) uint8_t[chunk_size];
if (this->transfer_buffer_ == nullptr) { // Try a smaller size if (this->transfer_buffer_ == nullptr) { // Try a smaller size
ESP_LOGD(TAG, "Could not allocate buffer size: %d trying 4096 instead", chunk_size); ESP_LOGD(TAG, "Could not allocate buffer size: %d trying 4096 instead", chunk_size);
chunk_size = 4096; chunk_size = 4096;
ESP_LOGD(TAG, "Allocating %d buffer", chunk_size); ESP_LOGD(TAG, "Allocating %d buffer", chunk_size);
this->transfer_buffer_ = new (std::nothrow) uint8_t[chunk_size]; // NOLINT(cppcoreguidelines-owning-memory) // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
this->transfer_buffer_ = new uint8_t[chunk_size];
if (!this->transfer_buffer_) if (!this->transfer_buffer_)
this->upload_end_(); this->upload_end_();
@ -330,7 +332,8 @@ void Nextion::upload_end_() {
WiFiClient *Nextion::get_wifi_client_() { WiFiClient *Nextion::get_wifi_client_() {
if (this->tft_url_.compare(0, 6, "https:") == 0) { if (this->tft_url_.compare(0, 6, "https:") == 0) {
if (this->wifi_client_secure_ == nullptr) { if (this->wifi_client_secure_ == nullptr) {
this->wifi_client_secure_ = new BearSSL::WiFiClientSecure(); // NOLINT(cppcoreguidelines-owning-memory) // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
this->wifi_client_secure_ = new BearSSL::WiFiClientSecure();
this->wifi_client_secure_->setInsecure(); this->wifi_client_secure_->setInsecure();
this->wifi_client_secure_->setBufferSizes(512, 512); this->wifi_client_secure_->setBufferSizes(512, 512);
} }
@ -338,7 +341,8 @@ WiFiClient *Nextion::get_wifi_client_() {
} }
if (this->wifi_client_ == nullptr) { if (this->wifi_client_ == nullptr) {
this->wifi_client_ = new WiFiClient(); // NOLINT(cppcoreguidelines-owning-memory) // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
this->wifi_client_ = new WiFiClient();
} }
return this->wifi_client_; return this->wifi_client_;
} }

View file

@ -34,7 +34,7 @@ void NextionSensor::update() {
return; return;
if (this->wave_chan_id_ == UINT8_MAX) { if (this->wave_chan_id_ == UINT8_MAX) {
this->nextion_->add_to_get_queue(shared_from_this()); this->nextion_->add_to_get_queue(this);
} else { } else {
if (this->send_last_value_) { if (this->send_last_value_) {
this->add_to_wave_buffer(this->last_value_); this->add_to_wave_buffer(this->last_value_);
@ -62,9 +62,9 @@ void NextionSensor::set_state(float state, bool publish, bool send_to_nextion) {
double to_multiply = pow(10, this->precision_); double to_multiply = pow(10, this->precision_);
int state_value = (int) (state * to_multiply); int state_value = (int) (state * to_multiply);
this->nextion_->add_no_result_to_queue_with_set(shared_from_this(), (int) state_value); this->nextion_->add_no_result_to_queue_with_set(this, (int) state_value);
} else { } else {
this->nextion_->add_no_result_to_queue_with_set(shared_from_this(), (int) state); this->nextion_->add_no_result_to_queue_with_set(this, (int) state);
} }
} }
} }
@ -103,7 +103,7 @@ void NextionSensor::wave_update_() {
buffer_to_send, this->wave_buffer_.size(), this->component_id_, this->wave_chan_id_); buffer_to_send, this->wave_buffer_.size(), this->component_id_, this->wave_chan_id_);
#endif #endif
this->nextion_->add_addt_command_to_queue(shared_from_this()); this->nextion_->add_addt_command_to_queue(this);
} }
} // namespace nextion } // namespace nextion

View file

@ -8,10 +8,7 @@ namespace esphome {
namespace nextion { namespace nextion {
class NextionSensor; class NextionSensor;
class NextionSensor : public NextionComponent, class NextionSensor : public NextionComponent, public sensor::Sensor, public PollingComponent {
public sensor::Sensor,
public PollingComponent,
public std::enable_shared_from_this<NextionSensor> {
public: public:
NextionSensor(NextionBase *nextion) { this->nextion_ = nextion; } NextionSensor(NextionBase *nextion) { this->nextion_ = nextion; }
void send_state_to_nextion() override { this->set_state(this->state, false, true); }; void send_state_to_nextion() override { this->set_state(this->state, false, true); };

View file

@ -20,7 +20,7 @@ void NextionSwitch::process_bool(const std::string &variable_name, bool on) {
void NextionSwitch::update() { void NextionSwitch::update() {
if (!this->nextion_->is_setup()) if (!this->nextion_->is_setup())
return; return;
this->nextion_->add_to_get_queue(shared_from_this()); this->nextion_->add_to_get_queue(this);
} }
void NextionSwitch::set_state(bool state, bool publish, bool send_to_nextion) { void NextionSwitch::set_state(bool state, bool publish, bool send_to_nextion) {
@ -32,7 +32,7 @@ void NextionSwitch::set_state(bool state, bool publish, bool send_to_nextion) {
this->needs_to_send_update_ = true; this->needs_to_send_update_ = true;
} else { } else {
this->needs_to_send_update_ = false; this->needs_to_send_update_ = false;
this->nextion_->add_no_result_to_queue_with_set(shared_from_this(), (int) state); this->nextion_->add_no_result_to_queue_with_set(this, (int) state);
} }
} }
if (publish) { if (publish) {

View file

@ -8,10 +8,7 @@ namespace esphome {
namespace nextion { namespace nextion {
class NextionSwitch; class NextionSwitch;
class NextionSwitch : public NextionComponent, class NextionSwitch : public NextionComponent, public switch_::Switch, public PollingComponent {
public switch_::Switch,
public PollingComponent,
public std::enable_shared_from_this<NextionSwitch> {
public: public:
NextionSwitch(NextionBase *nextion) { this->nextion_ = nextion; } NextionSwitch(NextionBase *nextion) { this->nextion_ = nextion; }

View file

@ -18,7 +18,7 @@ void NextionTextSensor::process_text(const std::string &variable_name, const std
void NextionTextSensor::update() { void NextionTextSensor::update() {
if (!this->nextion_->is_setup()) if (!this->nextion_->is_setup())
return; return;
this->nextion_->add_to_get_queue(shared_from_this()); this->nextion_->add_to_get_queue(this);
} }
void NextionTextSensor::set_state(const std::string &state, bool publish, bool send_to_nextion) { void NextionTextSensor::set_state(const std::string &state, bool publish, bool send_to_nextion) {
@ -29,7 +29,7 @@ void NextionTextSensor::set_state(const std::string &state, bool publish, bool s
if (this->nextion_->is_sleeping() || !this->visible_) { if (this->nextion_->is_sleeping() || !this->visible_) {
this->needs_to_send_update_ = true; this->needs_to_send_update_ = true;
} else { } else {
this->nextion_->add_no_result_to_queue_with_set(shared_from_this(), state); this->nextion_->add_no_result_to_queue_with_set(this, state);
} }
} }

View file

@ -8,10 +8,7 @@ namespace esphome {
namespace nextion { namespace nextion {
class NextionTextSensor; class NextionTextSensor;
class NextionTextSensor : public NextionComponent, class NextionTextSensor : public NextionComponent, public text_sensor::TextSensor, public PollingComponent {
public text_sensor::TextSensor,
public PollingComponent,
public std::enable_shared_from_this<NextionTextSensor> {
public: public:
NextionTextSensor(NextionBase *nextion) { this->nextion_ = nextion; } NextionTextSensor(NextionBase *nextion) { this->nextion_ = nextion; }
void update() override; void update() override;