More logging

This commit is contained in:
Daniël Koek 2024-03-28 11:33:17 +00:00
parent 5bcb7cf27e
commit 687eb008e8
3 changed files with 5 additions and 36 deletions

View file

@ -1,19 +1,18 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome import pins from esphome import pins
from esphome.components import sensor, text_sensor, uart from esphome.components import sensor, uart
from esphome.const import ( from esphome.const import (
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
CONF_ID, CONF_ID,
ENTITY_CATEGORY_NONE,
UNIT_PERCENT, UNIT_PERCENT,
) )
CODEOWNERS = ["@danielkoek"] CODEOWNERS = ["@danielkoek"]
DEPENDENCIES = ["uart"] DEPENDENCIES = ["uart"]
AUTO_LOAD = ["uart", "sensor", "text_sensor"] AUTO_LOAD = ["uart", "sensor"]
MULTI_CONF = True MULTI_CONF = True
ebyte_lora_ns = cg.esphome_ns.namespace("ebyte_lora") ebyte_lora_ns = cg.esphome_ns.namespace("ebyte_lora")
@ -24,7 +23,6 @@ CONF_EBYTE_LORA = "ebyte_lora"
CONF_PIN_AUX = "pin_aux" CONF_PIN_AUX = "pin_aux"
CONF_PIN_M0 = "pin_m0" CONF_PIN_M0 = "pin_m0"
CONF_PIN_M1 = "pin_m1" CONF_PIN_M1 = "pin_m1"
CONF_LORA_MESSAGE = "lora_message"
CONF_LORA_RSSI = "lora_rssi" CONF_LORA_RSSI = "lora_rssi"
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
cv.Schema( cv.Schema(
@ -36,10 +34,6 @@ CONFIG_SCHEMA = (
cv.Required(CONF_PIN_M0): pins.gpio_output_pin_schema, cv.Required(CONF_PIN_M0): pins.gpio_output_pin_schema,
# for communication set the mode # for communication set the mode
cv.Required(CONF_PIN_M1): pins.gpio_output_pin_schema, cv.Required(CONF_PIN_M1): pins.gpio_output_pin_schema,
# if you want to see the raw messages
cv.Optional(CONF_LORA_MESSAGE): text_sensor.text_sensor_schema(
entity_category=ENTITY_CATEGORY_NONE,
),
# if you want to see the rssi # if you want to see the rssi
cv.Optional(CONF_LORA_RSSI): sensor.sensor_schema( cv.Optional(CONF_LORA_RSSI): sensor.sensor_schema(
device_class=DEVICE_CLASS_SIGNAL_STRENGTH, device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
@ -66,10 +60,6 @@ async def to_code(config):
cg.add(var.set_pin_m0(pin_m0)) cg.add(var.set_pin_m0(pin_m0))
pin_m1 = await cg.gpio_pin_expression(config[CONF_PIN_M1]) pin_m1 = await cg.gpio_pin_expression(config[CONF_PIN_M1])
cg.add(var.set_pin_m1(pin_m1)) cg.add(var.set_pin_m1(pin_m1))
if CONF_LORA_MESSAGE in config:
sens = await text_sensor.new_text_sensor(config[CONF_LORA_MESSAGE])
cg.add(var.set_message_sensor(sens))
if CONF_LORA_RSSI in config: if CONF_LORA_RSSI in config:
sens = await sensor.new_sensor(config[CONF_LORA_RSSI]) sens = await sensor.new_sensor(config[CONF_LORA_RSSI])
cg.add(var.set_rssi_sensor(sens)) cg.add(var.set_rssi_sensor(sens))

View file

@ -2,19 +2,6 @@
namespace esphome { namespace esphome {
namespace ebyte_lora { namespace ebyte_lora {
void EbyteLoraComponent::update() {
can_send_message_();
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 EbyteLoraComponent::setup() { void EbyteLoraComponent::setup() {
this->pin_aux_->setup(); this->pin_aux_->setup();
this->pin_m0_->setup(); this->pin_m0_->setup();
@ -135,7 +122,7 @@ void EbyteLoraComponent::send_pin_info_(uint8_t pin, bool value) {
return; return;
} }
uint8_t data[3]; uint8_t data[3];
data[1] = 0xFF; // just some bit to indicate, yo this is pin info data[1] = 1; // number one to indicate
data[1] = pin; // Pin to send data[1] = pin; // Pin to send
data[2] = value; // Inverted for the pcf8574 data[2] = value; // Inverted for the pcf8574
ESP_LOGD(TAG, "Sending message"); ESP_LOGD(TAG, "Sending message");
@ -158,14 +145,12 @@ void EbyteLoraComponent::loop() {
} }
if (data.size() >= 4) { if (data.size() >= 4) {
ESP_LOGD(TAG, "Total: %u ", data.size()); ESP_LOGD(TAG, "Total: %u ", data.size());
ESP_LOGD(TAG, "Start bit: %#02x ", data[0]); ESP_LOGD(TAG, "Start bit: ", data[0]);
ESP_LOGD(TAG, "PIN: %u ", data[1]); ESP_LOGD(TAG, "PIN: %u ", data[1]);
ESP_LOGD(TAG, "VALUE: %u ", data[2]); ESP_LOGD(TAG, "VALUE: %u ", data[2]);
ESP_LOGD(TAG, "RSSI: %#02x ", data[3]); ESP_LOGD(TAG, "RSSI: %u % ", (data[3] / 255.0) * 100);
if (this->rssi_sensor_ != nullptr) if (this->rssi_sensor_ != nullptr)
this->rssi_sensor_->publish_state((data[3] / 255.0) * 100); this->rssi_sensor_->publish_state((data[3] / 255.0) * 100);
if (this->message_text_sensor_ != nullptr)
this->message_text_sensor_->publish_state("Got something");
for (auto *sensor : this->sensors_) { for (auto *sensor : this->sensors_) {
if (sensor->get_pin() == data[1]) { if (sensor->get_pin() == data[1]) {
@ -173,8 +158,6 @@ void EbyteLoraComponent::loop() {
sensor->got_state_message(data[2]); sensor->got_state_message(data[2]);
} }
} }
} else {
ESP_LOGD(TAG, "WEIRD");
} }
} }
} // namespace ebyte_lora } // namespace ebyte_lora

View file

@ -3,7 +3,6 @@
#include <vector> #include <vector>
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/text_sensor/text_sensor.h"
#include "esphome/components/switch/switch.h" #include "esphome/components/switch/switch.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "esphome/components/uart/uart.h" #include "esphome/components/uart/uart.h"
@ -33,12 +32,10 @@ class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
public: public:
void setup() override; void setup() override;
float get_setup_priority() const override { return setup_priority::HARDWARE; } float get_setup_priority() const override { return setup_priority::HARDWARE; }
void update() override;
void loop() override; void loop() override;
void dump_config() override; void dump_config() override;
/// Helper function to write the value of a pin. /// Helper function to write the value of a pin.
void digital_write(uint8_t pin, bool value); void digital_write(uint8_t pin, bool value);
void set_message_sensor(text_sensor::TextSensor *message_text_sensor) { message_text_sensor_ = message_text_sensor; }
void set_rssi_sensor(sensor::Sensor *rssi_sensor) { rssi_sensor_ = rssi_sensor; } void set_rssi_sensor(sensor::Sensor *rssi_sensor) { rssi_sensor_ = rssi_sensor; }
void set_pin_aux(GPIOPin *pin_aux) { pin_aux_ = pin_aux; } void set_pin_aux(GPIOPin *pin_aux) { pin_aux_ = pin_aux; }
void register_sensor(EbyteLoraSwitch *obj) { this->sensors_.push_back(obj); } void register_sensor(EbyteLoraSwitch *obj) { this->sensors_.push_back(obj); }
@ -62,7 +59,6 @@ class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
uint32_t starting_to_check_; uint32_t starting_to_check_;
uint32_t time_out_after_; uint32_t time_out_after_;
std::string raw_message_; std::string raw_message_;
text_sensor::TextSensor *message_text_sensor_{nullptr};
sensor::Sensor *rssi_sensor_{nullptr}; sensor::Sensor *rssi_sensor_{nullptr};
GPIOPin *pin_aux_; GPIOPin *pin_aux_;
GPIOPin *pin_m0_; GPIOPin *pin_m0_;