mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 09:44:12 +01:00
Trial this
This commit is contained in:
parent
5d30d43612
commit
866b448db9
2 changed files with 16 additions and 7 deletions
|
@ -145,6 +145,7 @@ void EbyteLoraComponent::loop() {
|
||||||
this->read_byte(&c);
|
this->read_byte(&c);
|
||||||
data.push_back(c);
|
data.push_back(c);
|
||||||
}
|
}
|
||||||
|
// if it is only push info
|
||||||
if (data[0] == SWITCH_PUSH) {
|
if (data[0] == SWITCH_PUSH) {
|
||||||
ESP_LOGD(TAG, "GOT SWITCH PUSH ", data.size());
|
ESP_LOGD(TAG, "GOT SWITCH PUSH ", data.size());
|
||||||
ESP_LOGD(TAG, "Total: %u ", data.size());
|
ESP_LOGD(TAG, "Total: %u ", data.size());
|
||||||
|
@ -158,14 +159,25 @@ void EbyteLoraComponent::loop() {
|
||||||
for (auto *sensor : this->sensors_) {
|
for (auto *sensor : this->sensors_) {
|
||||||
if (sensor->get_pin() == data[1]) {
|
if (sensor->get_pin() == data[1]) {
|
||||||
ESP_LOGD(TAG, "Updating switch");
|
ESP_LOGD(TAG, "Updating switch");
|
||||||
sensor->got_state_message(data[2]);
|
sensor->publish_state(data[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
send_switch_info_();
|
send_switch_info_();
|
||||||
}
|
}
|
||||||
|
// starting info loop
|
||||||
if (data[0] == SWITCH_INFO) {
|
if (data[0] == SWITCH_INFO) {
|
||||||
|
for (int i = 0; i < data.size(); i++) {
|
||||||
|
if (data[i] == SWITCH_INFO) {
|
||||||
ESP_LOGD(TAG, "GOT INFO ", data.size());
|
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);
|
ESP_LOGD(TAG, "RSSI: %u % ", (data[data.size() - 1] / 255.0) * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,6 +186,7 @@ void EbyteLoraComponent::send_switch_info_() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
|
|
||||||
for (auto *sensor : this->sensors_) {
|
for (auto *sensor : this->sensors_) {
|
||||||
uint8_t pin = sensor->get_pin();
|
uint8_t pin = sensor->get_pin();
|
||||||
uint8_t value = sensor->state;
|
uint8_t value = sensor->state;
|
||||||
|
|
|
@ -72,10 +72,6 @@ class EbyteLoraSwitch : public switch_::Switch, public Component {
|
||||||
void set_parent(EbyteLoraComponent *parent) { parent_ = parent; }
|
void set_parent(EbyteLoraComponent *parent) { parent_ = parent; }
|
||||||
void set_pin(uint8_t pin) { pin_ = pin; }
|
void set_pin(uint8_t pin) { pin_ = pin; }
|
||||||
uint8_t get_pin() { return 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:
|
protected:
|
||||||
void write_state(bool state) override { this->parent_->digital_write(this->pin_, state); }
|
void write_state(bool state) override { this->parent_->digital_write(this->pin_, state); }
|
||||||
|
|
Loading…
Reference in a new issue