From 866b448db9cc902281bee6003c2f030b30290c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Koek?= Date: Thu, 28 Mar 2024 12:25:49 +0000 Subject: [PATCH] Trial this --- esphome/components/ebyte_lora/ebyte_lora.cpp | 19 ++++++++++++++++--- esphome/components/ebyte_lora/ebyte_lora.h | 4 ---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/esphome/components/ebyte_lora/ebyte_lora.cpp b/esphome/components/ebyte_lora/ebyte_lora.cpp index e24237af09..5d691841cd 100644 --- a/esphome/components/ebyte_lora/ebyte_lora.cpp +++ b/esphome/components/ebyte_lora/ebyte_lora.cpp @@ -145,6 +145,7 @@ void EbyteLoraComponent::loop() { this->read_byte(&c); data.push_back(c); } + // if it is only push info if (data[0] == SWITCH_PUSH) { ESP_LOGD(TAG, "GOT SWITCH PUSH ", data.size()); ESP_LOGD(TAG, "Total: %u ", data.size()); @@ -158,14 +159,25 @@ void EbyteLoraComponent::loop() { for (auto *sensor : this->sensors_) { if (sensor->get_pin() == data[1]) { ESP_LOGD(TAG, "Updating switch"); - sensor->got_state_message(data[2]); + sensor->publish_state(data[2]); } } send_switch_info_(); } + // starting info loop if (data[0] == SWITCH_INFO) { - ESP_LOGD(TAG, "GOT INFO ", data.size()); - + for (int i = 0; i < data.size(); i++) { + if (data[i] == SWITCH_INFO) { + ESP_LOGD(TAG, "GOT INFO ", data.size()); + uint8_t pin = data[i + 1]; + bool value = data[i + 2]; + for (auto *sensor : this->sensors_) { + if (pin == sensor->get_pin()) { + sensor->publish_state(value); + } + } + } + } ESP_LOGD(TAG, "RSSI: %u % ", (data[data.size() - 1] / 255.0) * 100); } } @@ -174,6 +186,7 @@ void EbyteLoraComponent::send_switch_info_() { return; } std::vector data; + for (auto *sensor : this->sensors_) { uint8_t pin = sensor->get_pin(); uint8_t value = sensor->state; diff --git a/esphome/components/ebyte_lora/ebyte_lora.h b/esphome/components/ebyte_lora/ebyte_lora.h index 777fce383a..4be11d4ffd 100644 --- a/esphome/components/ebyte_lora/ebyte_lora.h +++ b/esphome/components/ebyte_lora/ebyte_lora.h @@ -72,10 +72,6 @@ class EbyteLoraSwitch : public switch_::Switch, public Component { void set_parent(EbyteLoraComponent *parent) { parent_ = parent; } void set_pin(uint8_t pin) { pin_ = pin; } uint8_t get_pin() { return pin_; } - void got_state_message(bool state) { - ESP_LOGD("ebyte_lora_switch", "Got an update"); - this->publish_state(state); - }; protected: void write_state(bool state) override { this->parent_->digital_write(this->pin_, state); }