and update

This commit is contained in:
Daniël Koek 2024-03-25 16:41:53 +00:00
parent 3d4e589bcb
commit 752fdeff90
2 changed files with 6 additions and 0 deletions

View file

@ -3,12 +3,16 @@
namespace esphome {
namespace lora {
void Lora::update() {
if (!this->update_needed_)
return;
if (this->rssi_sensor_ != nullptr)
this->rssi_sensor_->publish_state(this->rssi_);
// raw info
if (this->message_text_sensor_ != nullptr)
this->message_text_sensor_->publish_state(this->raw_message_);
// reset the updater
this->update_needed_ = false;
}
void Lora::setup() {
this->pin_aux_->setup();
@ -157,6 +161,7 @@ void Lora::loop() {
data.push_back(c);
}
}
this->update_needed_ = true;
ESP_LOGD(TAG, "Got %s", buffer.c_str());
if (!data.empty()) {
ESP_LOGD(TAG, "Found pin data!");

View file

@ -54,6 +54,7 @@ class Lora : public PollingComponent, public uart::UARTDevice {
bool send_pin_info_(uint8_t pin, bool value);
protected:
bool update_needed_ = false;
int rssi_ = 0;
float latitude_ = -1;
float longitude_ = -1;