Implement more dump_configs (#791)

This commit is contained in:
Otto Winter 2019-10-23 14:43:41 +02:00 committed by GitHub
parent d63cd8b4cd
commit 8ff742d9ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 110 additions and 29 deletions

View file

@ -31,6 +31,10 @@ uint8_t I2CAS3935Component::read_register(uint8_t reg) {
} }
return value; return value;
} }
void I2CAS3935Component::dump_config() {
AS3935Component::dump_config();
LOG_I2C_DEVICE(this);
}
} // namespace as3935_i2c } // namespace as3935_i2c
} // namespace esphome } // namespace esphome

View file

@ -10,6 +10,9 @@ namespace esphome {
namespace as3935_i2c { namespace as3935_i2c {
class I2CAS3935Component : public as3935::AS3935Component, public i2c::I2CDevice { class I2CAS3935Component : public as3935::AS3935Component, public i2c::I2CDevice {
public:
void dump_config() override;
protected: protected:
void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) override; void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) override;
uint8_t read_register(uint8_t reg) override; uint8_t read_register(uint8_t reg) override;

View file

@ -145,6 +145,14 @@ Trigger<> *BangBangClimate::get_cool_trigger() const { return this->cool_trigger
void BangBangClimate::set_supports_cool(bool supports_cool) { this->supports_cool_ = supports_cool; } void BangBangClimate::set_supports_cool(bool supports_cool) { this->supports_cool_ = supports_cool; }
Trigger<> *BangBangClimate::get_heat_trigger() const { return this->heat_trigger_; } Trigger<> *BangBangClimate::get_heat_trigger() const { return this->heat_trigger_; }
void BangBangClimate::set_supports_heat(bool supports_heat) { this->supports_heat_ = supports_heat; } void BangBangClimate::set_supports_heat(bool supports_heat) { this->supports_heat_ = supports_heat; }
void BangBangClimate::dump_config() {
LOG_CLIMATE("", "Bang Bang Climate", this);
ESP_LOGCONFIG(TAG, " Supports HEAT: %s", YESNO(this->supports_heat_));
ESP_LOGCONFIG(TAG, " Supports COOL: %s", YESNO(this->supports_cool_));
ESP_LOGCONFIG(TAG, " Supports AWAY mode: %s", YESNO(this->supports_away_));
ESP_LOGCONFIG(TAG, " Default Target Temperature Low: %.1f°C", this->normal_config_.default_temperature_low);
ESP_LOGCONFIG(TAG, " Default Target Temperature High: %.1f°C", this->normal_config_.default_temperature_high);
}
BangBangClimateTargetTempConfig::BangBangClimateTargetTempConfig() = default; BangBangClimateTargetTempConfig::BangBangClimateTargetTempConfig() = default;
BangBangClimateTargetTempConfig::BangBangClimateTargetTempConfig(float default_temperature_low, BangBangClimateTargetTempConfig::BangBangClimateTargetTempConfig(float default_temperature_low,

View file

@ -21,6 +21,7 @@ class BangBangClimate : public climate::Climate, public Component {
public: public:
BangBangClimate(); BangBangClimate();
void setup() override; void setup() override;
void dump_config() override;
void set_sensor(sensor::Sensor *sensor); void set_sensor(sensor::Sensor *sensor);
Trigger<> *get_idle_trigger() const; Trigger<> *get_idle_trigger() const;

View file

@ -10,9 +10,9 @@ namespace binary_sensor {
#define LOG_BINARY_SENSOR(prefix, type, obj) \ #define LOG_BINARY_SENSOR(prefix, type, obj) \
if (obj != nullptr) { \ if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, prefix type " '%s'", obj->get_name().c_str()); \ ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
if (!obj->get_device_class().empty()) { \ if (!obj->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, prefix " Device Class: '%s'", obj->get_device_class().c_str()); \ ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str()); \
} \ } \
} }

View file

@ -166,6 +166,7 @@ float CaptivePortal::get_setup_priority() const {
// Before WiFi // Before WiFi
return setup_priority::WIFI + 1.0f; return setup_priority::WIFI + 1.0f;
} }
void CaptivePortal::dump_config() { ESP_LOGCONFIG(TAG, "Captive Portal:"); }
CaptivePortal *global_captive_portal = nullptr; CaptivePortal *global_captive_portal = nullptr;

View file

@ -18,6 +18,7 @@ class CaptivePortal : public AsyncWebHandler, public Component {
public: public:
CaptivePortal(web_server_base::WebServerBase *base); CaptivePortal(web_server_base::WebServerBase *base);
void setup() override; void setup() override;
void dump_config() override;
void loop() override { void loop() override {
if (this->dns_server_ != nullptr) if (this->dns_server_ != nullptr)
this->dns_server_->processNextRequest(); this->dns_server_->processNextRequest();

View file

@ -9,6 +9,11 @@
namespace esphome { namespace esphome {
namespace climate { namespace climate {
#define LOG_CLIMATE(prefix, type, obj) \
if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
}
class Climate; class Climate;
/** This class is used to encode all control actions on a climate device. /** This class is used to encode all control actions on a climate device.

View file

@ -1,8 +1,11 @@
#include "climate_ir.h" #include "climate_ir.h"
#include "esphome/core/log.h"
namespace esphome { namespace esphome {
namespace climate { namespace climate {
static const char *TAG = "climate_ir";
climate::ClimateTraits ClimateIR::traits() { climate::ClimateTraits ClimateIR::traits() {
auto traits = climate::ClimateTraits(); auto traits = climate::ClimateTraits();
traits.set_supports_current_temperature(this->sensor_ != nullptr); traits.set_supports_current_temperature(this->sensor_ != nullptr);
@ -52,6 +55,13 @@ void ClimateIR::control(const climate::ClimateCall &call) {
this->transmit_state(); this->transmit_state();
this->publish_state(); this->publish_state();
} }
void ClimateIR::dump_config() {
LOG_CLIMATE("", "IR Climate", this);
ESP_LOGCONFIG(TAG, " Min. Temperature: %.1f°C", this->minimum_temperature_);
ESP_LOGCONFIG(TAG, " Max. Temperature: %.1f°C", this->maximum_temperature_);
ESP_LOGCONFIG(TAG, " Supports HEAT: %s", YESNO(this->supports_heat_));
ESP_LOGCONFIG(TAG, " Supports COOL: %s", YESNO(this->supports_cool_));
}
} // namespace climate } // namespace climate
} // namespace esphome } // namespace esphome

View file

@ -25,6 +25,7 @@ class ClimateIR : public climate::Climate, public Component, public remote_base:
} }
void setup() override; void setup() override;
void dump_config() override;
void set_transmitter(remote_transmitter::RemoteTransmitterComponent *transmitter) { void set_transmitter(remote_transmitter::RemoteTransmitterComponent *transmitter) {
this->transmitter_ = transmitter; this->transmitter_ = transmitter;
} }

View file

@ -13,13 +13,13 @@ const extern float COVER_CLOSED;
#define LOG_COVER(prefix, type, obj) \ #define LOG_COVER(prefix, type, obj) \
if (obj != nullptr) { \ if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, prefix type " '%s'", obj->get_name().c_str()); \ ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
auto traits_ = obj->get_traits(); \ auto traits_ = obj->get_traits(); \
if (traits_.get_is_assumed_state()) { \ if (traits_.get_is_assumed_state()) { \
ESP_LOGCONFIG(TAG, prefix " Assumed State: YES"); \ ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
} \ } \
if (!obj->get_device_class().empty()) { \ if (!obj->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, prefix " Device Class: '%s'", obj->get_device_class().c_str()); \ ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str()); \
} \ } \
} }

View file

@ -115,6 +115,10 @@ void DFPlayer::loop() {
this->read_pos_++; this->read_pos_++;
} }
} }
void DFPlayer::dump_config() {
ESP_LOGCONFIG(TAG, "DFPlayer:");
this->check_uart_settings(9600);
}
} // namespace dfplayer } // namespace dfplayer
} // namespace esphome } // namespace esphome

View file

@ -52,6 +52,7 @@ class DFPlayer : public uart::UARTDevice, public Component {
void random() { this->send_cmd_(0x18); } void random() { this->send_cmd_(0x18); }
bool is_playing() { return is_playing_; } bool is_playing() { return is_playing_; }
void dump_config() override;
void add_on_finished_playback_callback(std::function<void()> callback) { void add_on_finished_playback_callback(std::function<void()> callback) {
this->on_finished_playback_callback_.add(std::move(callback)); this->on_finished_playback_callback_.add(std::move(callback));

View file

@ -84,8 +84,8 @@ using display_writer_t = std::function<void(DisplayBuffer &)>;
#define LOG_DISPLAY(prefix, type, obj) \ #define LOG_DISPLAY(prefix, type, obj) \
if (obj != nullptr) { \ if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, prefix type); \ ESP_LOGCONFIG(TAG, prefix type); \
ESP_LOGCONFIG(TAG, prefix " Rotations: %d °", obj->rotation_); \ ESP_LOGCONFIG(TAG, "%s Rotations: %d °", prefix, obj->rotation_); \
ESP_LOGCONFIG(TAG, prefix " Dimensions: %dpx x %dpx", obj->get_width(), obj->get_height()); \ ESP_LOGCONFIG(TAG, "%s Dimensions: %dpx x %dpx", prefix, obj->get_width(), obj->get_height()); \
} }
class DisplayBuffer { class DisplayBuffer {

View file

@ -31,6 +31,11 @@ static esp_ble_adv_params_t ble_adv_params = {
static esp_ble_ibeacon_head_t ibeacon_common_head = { static esp_ble_ibeacon_head_t ibeacon_common_head = {
.flags = {0x02, 0x01, 0x06}, .length = 0x1A, .type = 0xFF, .company_id = 0x004C, .beacon_type = 0x1502}; .flags = {0x02, 0x01, 0x06}, .length = 0x1A, .type = 0xFF, .company_id = 0x004C, .beacon_type = 0x1502};
void ESP32BLEBeacon::dump_config() {
ESP_LOGCONFIG(TAG, "ESP32 BLE Beacon:");
ESP_LOGCONFIG(TAG, " Major: %u, Minor: %u", this->major_, this->minor_);
}
void ESP32BLEBeacon::setup() { void ESP32BLEBeacon::setup() {
ESP_LOGCONFIG(TAG, "Setting up ESP32 BLE beacon..."); ESP_LOGCONFIG(TAG, "Setting up ESP32 BLE beacon...");
global_esp32_ble_beacon = this; global_esp32_ble_beacon = this;

View file

@ -34,6 +34,7 @@ class ESP32BLEBeacon : public Component {
explicit ESP32BLEBeacon(const std::array<uint8_t, 16> &uuid) : uuid_(uuid) {} explicit ESP32BLEBeacon(const std::array<uint8_t, 16> &uuid) : uuid_(uuid) {}
void setup() override; void setup() override;
void dump_config() override;
float get_setup_priority() const override; float get_setup_priority() const override;
void set_major(uint16_t major) { this->major_ = major; } void set_major(uint16_t major) { this->major_ = major; }

View file

@ -19,9 +19,9 @@ void NTC::process_(float value) {
return; return;
} }
float lr = logf(value); double lr = log(double(value));
float v = this->a_ + this->b_ * lr + this->c_ * lr * lr * lr; double v = this->a_ + this->b_ * lr + this->c_ * lr * lr * lr;
float temp = 1 / v - 273.15f; auto temp = float(1.0 / v - 273.15);
ESP_LOGD(TAG, "'%s' - Temperature: %.1f°C", this->name_.c_str(), temp); ESP_LOGD(TAG, "'%s' - Temperature: %.1f°C", this->name_.c_str(), temp);
this->publish_state(temp); this->publish_state(temp);

View file

@ -9,9 +9,9 @@ namespace ntc {
class NTC : public Component, public sensor::Sensor { class NTC : public Component, public sensor::Sensor {
public: public:
void set_sensor(Sensor *sensor) { sensor_ = sensor; } void set_sensor(Sensor *sensor) { sensor_ = sensor; }
void set_a(float a) { a_ = a; } void set_a(double a) { a_ = a; }
void set_b(float b) { b_ = b; } void set_b(double b) { b_ = b; }
void set_c(float c) { c_ = c; } void set_c(double c) { c_ = c; }
void setup() override; void setup() override;
void dump_config() override; void dump_config() override;
float get_setup_priority() const override; float get_setup_priority() const override;
@ -20,9 +20,9 @@ class NTC : public Component, public sensor::Sensor {
void process_(float value); void process_(float value);
sensor::Sensor *sensor_; sensor::Sensor *sensor_;
float a_; double a_;
float b_; double b_;
float c_; double c_;
}; };
} // namespace ntc } // namespace ntc

View file

@ -98,6 +98,12 @@ void PZEM004T::write_state_(PZEM004T::PZEM004TReadState state) {
this->write_array(data); this->write_array(data);
this->read_state_ = state; this->read_state_ = state;
} }
void PZEM004T::dump_config() {
ESP_LOGCONFIG(TAG, "PZEM004T:");
LOG_SENSOR("", "Voltage", this->voltage_sensor_);
LOG_SENSOR("", "Current", this->current_sensor_);
LOG_SENSOR("", "Power", this->power_sensor_);
}
} // namespace pzem004t } // namespace pzem004t
} // namespace esphome } // namespace esphome

View file

@ -17,6 +17,8 @@ class PZEM004T : public PollingComponent, public uart::UARTDevice {
void update() override; void update() override;
void dump_config() override;
protected: protected:
sensor::Sensor *voltage_sensor_; sensor::Sensor *voltage_sensor_;
sensor::Sensor *current_sensor_; sensor::Sensor *current_sensor_;

View file

@ -57,6 +57,15 @@ void PZEMAC::on_modbus_data(const std::vector<uint8_t> &data) {
} }
void PZEMAC::update() { this->send(PZEM_CMD_READ_IN_REGISTERS, 0, PZEM_REGISTER_COUNT); } void PZEMAC::update() { this->send(PZEM_CMD_READ_IN_REGISTERS, 0, PZEM_REGISTER_COUNT); }
void PZEMAC::dump_config() {
ESP_LOGCONFIG(TAG, "PZEMAC:");
ESP_LOGCONFIG(TAG, " Address: 0x%02X", this->address_);
LOG_SENSOR("", "Voltage", this->voltage_sensor_);
LOG_SENSOR("", "Current", this->current_sensor_);
LOG_SENSOR("", "Power", this->power_sensor_);
LOG_SENSOR("", "Frequency", this->frequency_sensor_);
LOG_SENSOR("", "Power Factor", this->power_factor_sensor_);
}
} // namespace pzemac } // namespace pzemac
} // namespace esphome } // namespace esphome

View file

@ -19,6 +19,8 @@ class PZEMAC : public PollingComponent, public modbus::ModbusDevice {
void on_modbus_data(const std::vector<uint8_t> &data) override; void on_modbus_data(const std::vector<uint8_t> &data) override;
void dump_config() override;
protected: protected:
sensor::Sensor *voltage_sensor_; sensor::Sensor *voltage_sensor_;
sensor::Sensor *current_sensor_; sensor::Sensor *current_sensor_;

View file

@ -47,6 +47,13 @@ void PZEMDC::on_modbus_data(const std::vector<uint8_t> &data) {
} }
void PZEMDC::update() { this->send(PZEM_CMD_READ_IN_REGISTERS, 0, 8); } void PZEMDC::update() { this->send(PZEM_CMD_READ_IN_REGISTERS, 0, 8); }
void PZEMDC::dump_config() {
ESP_LOGCONFIG(TAG, "PZEMDC:");
ESP_LOGCONFIG(TAG, " Address: 0x%02X", this->address_);
LOG_SENSOR("", "Voltage", this->voltage_sensor_);
LOG_SENSOR("", "Current", this->current_sensor_);
LOG_SENSOR("", "Power", this->power_sensor_);
}
} // namespace pzemdc } // namespace pzemdc
} // namespace esphome } // namespace esphome

View file

@ -19,6 +19,8 @@ class PZEMDC : public PollingComponent, public modbus::ModbusDevice {
void on_modbus_data(const std::vector<uint8_t> &data) override; void on_modbus_data(const std::vector<uint8_t> &data) override;
void dump_config() override;
protected: protected:
sensor::Sensor *voltage_sensor_; sensor::Sensor *voltage_sensor_;
sensor::Sensor *current_sensor_; sensor::Sensor *current_sensor_;

View file

@ -9,17 +9,17 @@ namespace sensor {
#define LOG_SENSOR(prefix, type, obj) \ #define LOG_SENSOR(prefix, type, obj) \
if (obj != nullptr) { \ if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, prefix type " '%s'", obj->get_name().c_str()); \ ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
ESP_LOGCONFIG(TAG, prefix " Unit of Measurement: '%s'", obj->get_unit_of_measurement().c_str()); \ ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, obj->get_unit_of_measurement().c_str()); \
ESP_LOGCONFIG(TAG, prefix " Accuracy Decimals: %d", obj->get_accuracy_decimals()); \ ESP_LOGCONFIG(TAG, "%s Accuracy Decimals: %d", prefix, obj->get_accuracy_decimals()); \
if (!obj->get_icon().empty()) { \ if (!obj->get_icon().empty()) { \
ESP_LOGCONFIG(TAG, prefix " Icon: '%s'", obj->get_icon().c_str()); \ ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, obj->get_icon().c_str()); \
} \ } \
if (!obj->unique_id().empty()) { \ if (!obj->unique_id().empty()) { \
ESP_LOGV(TAG, prefix " Unique ID: '%s'", obj->unique_id().c_str()); \ ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, obj->unique_id().c_str()); \
} \ } \
if (obj->get_force_update()) { \ if (obj->get_force_update()) { \
ESP_LOGV(TAG, prefix " Force Update: YES"); \ ESP_LOGV(TAG, "%s Force Update: YES", prefix); \
} \ } \
} }

View file

@ -255,6 +255,10 @@ void Sim800LComponent::send_sms(std::string recipient, std::string message) {
this->send_pending_ = true; this->send_pending_ = true;
this->update(); this->update();
} }
void Sim800LComponent::dump_config() {
ESP_LOGCONFIG(TAG, "SIM800L:");
ESP_LOGCONFIG(TAG, " RSSI: %d dB", this->rssi_);
}
} // namespace sim800l } // namespace sim800l
} // namespace esphome } // namespace esphome

View file

@ -37,6 +37,7 @@ class Sim800LComponent : public uart::UARTDevice, public PollingComponent {
/// Retrieve the latest sensor values. This operation takes approximately 16ms. /// Retrieve the latest sensor values. This operation takes approximately 16ms.
void update() override; void update() override;
void loop() override; void loop() override;
void dump_config() override;
void add_on_sms_received_callback(std::function<void(std::string, std::string)> callback) { void add_on_sms_received_callback(std::function<void(std::string, std::string)> callback) {
this->callback_.add(std::move(callback)); this->callback_.add(std::move(callback));
} }

View file

@ -9,15 +9,15 @@ namespace switch_ {
#define LOG_SWITCH(prefix, type, obj) \ #define LOG_SWITCH(prefix, type, obj) \
if (obj != nullptr) { \ if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, prefix type " '%s'", obj->get_name().c_str()); \ ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
if (!obj->get_icon().empty()) { \ if (!obj->get_icon().empty()) { \
ESP_LOGCONFIG(TAG, prefix " Icon: '%s'", obj->get_icon().c_str()); \ ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, obj->get_icon().c_str()); \
} \ } \
if (obj->assumed_state()) { \ if (obj->assumed_state()) { \
ESP_LOGCONFIG(TAG, prefix " Assumed State: YES"); \ ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
} \ } \
if (obj->is_inverted()) { \ if (obj->is_inverted()) { \
ESP_LOGCONFIG(TAG, prefix " Inverted: YES"); \ ESP_LOGCONFIG(TAG, "%s Inverted: YES", prefix); \
} \ } \
} }

View file

@ -8,12 +8,12 @@ namespace text_sensor {
#define LOG_TEXT_SENSOR(prefix, type, obj) \ #define LOG_TEXT_SENSOR(prefix, type, obj) \
if (obj != nullptr) { \ if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, prefix type " '%s'", obj->get_name().c_str()); \ ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
if (!obj->get_icon().empty()) { \ if (!obj->get_icon().empty()) { \
ESP_LOGCONFIG(TAG, prefix " Icon: '%s'", obj->get_icon().c_str()); \ ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, obj->get_icon().c_str()); \
} \ } \
if (!obj->unique_id().empty()) { \ if (!obj->unique_id().empty()) { \
ESP_LOGV(TAG, prefix " Unique ID: '%s'", obj->unique_id().c_str()); \ ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, obj->unique_id().c_str()); \
} \ } \
} }

View file

@ -27,6 +27,7 @@ void UptimeSensor::update() {
} }
std::string UptimeSensor::unique_id() { return get_mac_address() + "-uptime"; } std::string UptimeSensor::unique_id() { return get_mac_address() + "-uptime"; }
float UptimeSensor::get_setup_priority() const { return setup_priority::HARDWARE; } float UptimeSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
void UptimeSensor::dump_config() { LOG_SENSOR("", "Uptime Sensor", this); }
} // namespace uptime } // namespace uptime
} // namespace esphome } // namespace esphome

View file

@ -9,6 +9,7 @@ namespace uptime {
class UptimeSensor : public sensor::Sensor, public PollingComponent { class UptimeSensor : public sensor::Sensor, public PollingComponent {
public: public:
void update() override; void update() override;
void dump_config() override;
float get_setup_priority() const override; float get_setup_priority() const override;

View file

@ -325,6 +325,7 @@ def lint_pragma_once(fname, content):
'esphome/components/stepper/stepper.h', 'esphome/components/stepper/stepper.h',
'esphome/components/switch/switch.h', 'esphome/components/switch/switch.h',
'esphome/components/text_sensor/text_sensor.h', 'esphome/components/text_sensor/text_sensor.h',
'esphome/components/climate/climate.h',
'esphome/core/component.h', 'esphome/core/component.h',
'esphome/core/esphal.h', 'esphome/core/esphal.h',
'esphome/core/log.h', 'esphome/core/log.h',