mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 11:22:24 +01:00
Merge branch 'integration' into memory_api
This commit is contained in:
@@ -7,6 +7,19 @@ namespace binary_sensor {
|
||||
|
||||
static const char *const TAG = "binary_sensor";
|
||||
|
||||
// Function implementation of LOG_BINARY_SENSOR macro to reduce code size
|
||||
void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj) {
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
|
||||
|
||||
if (!obj->get_device_class().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void BinarySensor::publish_state(bool new_state) {
|
||||
if (this->filter_list_ == nullptr) {
|
||||
this->send_state_internal(new_state);
|
||||
|
@@ -10,13 +10,12 @@ namespace esphome {
|
||||
|
||||
namespace binary_sensor {
|
||||
|
||||
#define LOG_BINARY_SENSOR(prefix, type, obj) \
|
||||
if ((obj) != nullptr) { \
|
||||
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
|
||||
if (!(obj)->get_device_class().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \
|
||||
} \
|
||||
}
|
||||
// Forward declaration
|
||||
class BinarySensor;
|
||||
void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj);
|
||||
|
||||
// Macro that calls the function - kept for backward compatibility
|
||||
#define LOG_BINARY_SENSOR(prefix, type, obj) log_binary_sensor(TAG, prefix, LOG_STR_LITERAL(type), obj)
|
||||
|
||||
#define SUB_BINARY_SENSOR(name) \
|
||||
protected: \
|
||||
|
@@ -6,6 +6,19 @@ namespace button {
|
||||
|
||||
static const char *const TAG = "button";
|
||||
|
||||
// Function implementation of LOG_BUTTON macro to reduce code size
|
||||
void log_button(const char *tag, const char *prefix, const char *type, Button *obj) {
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
|
||||
|
||||
if (!obj->get_icon().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, obj->get_icon().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Button::press() {
|
||||
ESP_LOGD(TAG, "'%s' Pressed.", this->get_name().c_str());
|
||||
this->press_action();
|
||||
|
@@ -7,13 +7,12 @@
|
||||
namespace esphome {
|
||||
namespace button {
|
||||
|
||||
#define LOG_BUTTON(prefix, type, obj) \
|
||||
if ((obj) != nullptr) { \
|
||||
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
|
||||
if (!(obj)->get_icon().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
|
||||
} \
|
||||
}
|
||||
// Forward declaration
|
||||
class Button;
|
||||
void log_button(const char *tag, const char *prefix, const char *type, Button *obj);
|
||||
|
||||
// Macro that calls the function - kept for backward compatibility
|
||||
#define LOG_BUTTON(prefix, type, obj) log_button(TAG, prefix, LOG_STR_LITERAL(type), obj)
|
||||
|
||||
#define SUB_BUTTON(name) \
|
||||
protected: \
|
||||
|
@@ -153,8 +153,8 @@ void CCS811Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "CCS811");
|
||||
LOG_I2C_DEVICE(this)
|
||||
LOG_UPDATE_INTERVAL(this)
|
||||
LOG_SENSOR(" ", "CO2 Sensor", this->co2_)
|
||||
LOG_SENSOR(" ", "TVOC Sensor", this->tvoc_)
|
||||
LOG_SENSOR(" ", "CO2 Sensor", this->co2_);
|
||||
LOG_SENSOR(" ", "TVOC Sensor", this->tvoc_);
|
||||
LOG_TEXT_SENSOR(" ", "Firmware Version Sensor", this->version_)
|
||||
if (this->baseline_) {
|
||||
ESP_LOGCONFIG(TAG, " Baseline: %04X", *this->baseline_);
|
||||
|
@@ -58,10 +58,10 @@ void GroveGasMultichannelV2Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Grove Multichannel Gas Sensor V2");
|
||||
LOG_I2C_DEVICE(this)
|
||||
LOG_UPDATE_INTERVAL(this)
|
||||
LOG_SENSOR(" ", "Nitrogen Dioxide", this->nitrogen_dioxide_sensor_)
|
||||
LOG_SENSOR(" ", "Ethanol", this->ethanol_sensor_)
|
||||
LOG_SENSOR(" ", "Carbon Monoxide", this->carbon_monoxide_sensor_)
|
||||
LOG_SENSOR(" ", "TVOC", this->tvoc_sensor_)
|
||||
LOG_SENSOR(" ", "Nitrogen Dioxide", this->nitrogen_dioxide_sensor_);
|
||||
LOG_SENSOR(" ", "Ethanol", this->ethanol_sensor_);
|
||||
LOG_SENSOR(" ", "Carbon Monoxide", this->carbon_monoxide_sensor_);
|
||||
LOG_SENSOR(" ", "TVOC", this->tvoc_sensor_);
|
||||
|
||||
if (this->is_failed()) {
|
||||
switch (this->error_code_) {
|
||||
|
@@ -43,10 +43,10 @@ void HLW8012Component::dump_config() {
|
||||
" Voltage Divider: %.1f",
|
||||
this->change_mode_every_, this->current_resistor_ * 1000.0f, this->voltage_divider_);
|
||||
LOG_UPDATE_INTERVAL(this)
|
||||
LOG_SENSOR(" ", "Voltage", this->voltage_sensor_)
|
||||
LOG_SENSOR(" ", "Current", this->current_sensor_)
|
||||
LOG_SENSOR(" ", "Power", this->power_sensor_)
|
||||
LOG_SENSOR(" ", "Energy", this->energy_sensor_)
|
||||
LOG_SENSOR(" ", "Voltage", this->voltage_sensor_);
|
||||
LOG_SENSOR(" ", "Current", this->current_sensor_);
|
||||
LOG_SENSOR(" ", "Power", this->power_sensor_);
|
||||
LOG_SENSOR(" ", "Energy", this->energy_sensor_);
|
||||
}
|
||||
float HLW8012Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
void HLW8012Component::update() {
|
||||
|
@@ -6,6 +6,27 @@ namespace number {
|
||||
|
||||
static const char *const TAG = "number";
|
||||
|
||||
// Function implementation of LOG_NUMBER macro to reduce code size
|
||||
void log_number(const char *tag, const char *prefix, const char *type, Number *obj) {
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
|
||||
|
||||
if (!obj->get_icon().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, obj->get_icon().c_str());
|
||||
}
|
||||
|
||||
if (!obj->traits.get_unit_of_measurement().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Unit of Measurement: '%s'", prefix, obj->traits.get_unit_of_measurement().c_str());
|
||||
}
|
||||
|
||||
if (!obj->traits.get_device_class().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, obj->traits.get_device_class().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Number::publish_state(float state) {
|
||||
this->set_has_state(true);
|
||||
this->state = state;
|
||||
|
@@ -9,19 +9,12 @@
|
||||
namespace esphome {
|
||||
namespace number {
|
||||
|
||||
#define LOG_NUMBER(prefix, type, obj) \
|
||||
if ((obj) != nullptr) { \
|
||||
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
|
||||
if (!(obj)->get_icon().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
|
||||
} \
|
||||
if (!(obj)->traits.get_unit_of_measurement().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, (obj)->traits.get_unit_of_measurement().c_str()); \
|
||||
} \
|
||||
if (!(obj)->traits.get_device_class().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->traits.get_device_class().c_str()); \
|
||||
} \
|
||||
}
|
||||
// Forward declaration
|
||||
class Number;
|
||||
void log_number(const char *tag, const char *prefix, const char *type, Number *obj);
|
||||
|
||||
// Macro that calls the function - kept for backward compatibility
|
||||
#define LOG_NUMBER(prefix, type, obj) log_number(TAG, prefix, LOG_STR_LITERAL(type), obj)
|
||||
|
||||
#define SUB_NUMBER(name) \
|
||||
protected: \
|
||||
|
@@ -17,7 +17,7 @@ void IRAM_ATTR PulseWidthSensorStore::gpio_intr(PulseWidthSensorStore *arg) {
|
||||
}
|
||||
|
||||
void PulseWidthSensor::dump_config() {
|
||||
LOG_SENSOR("", "Pulse Width", this)
|
||||
LOG_SENSOR("", "Pulse Width", this);
|
||||
LOG_UPDATE_INTERVAL(this)
|
||||
LOG_PIN(" Pin: ", this->pin_);
|
||||
}
|
||||
|
@@ -6,6 +6,33 @@ namespace sensor {
|
||||
|
||||
static const char *const TAG = "sensor";
|
||||
|
||||
// Function implementation of LOG_SENSOR macro to reduce code size
|
||||
void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *obj) {
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(tag,
|
||||
"%s%s '%s'\n"
|
||||
"%s State Class: '%s'\n"
|
||||
"%s Unit of Measurement: '%s'\n"
|
||||
"%s Accuracy Decimals: %d",
|
||||
prefix, type, obj->get_name().c_str(), prefix, state_class_to_string(obj->get_state_class()).c_str(),
|
||||
prefix, obj->get_unit_of_measurement().c_str(), prefix, obj->get_accuracy_decimals());
|
||||
|
||||
if (!obj->get_device_class().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str());
|
||||
}
|
||||
|
||||
if (!obj->get_icon().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, obj->get_icon().c_str());
|
||||
}
|
||||
|
||||
if (obj->get_force_update()) {
|
||||
ESP_LOGV(tag, "%s Force Update: YES", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
std::string state_class_to_string(StateClass state_class) {
|
||||
switch (state_class) {
|
||||
case STATE_CLASS_MEASUREMENT:
|
||||
|
@@ -12,26 +12,11 @@
|
||||
namespace esphome {
|
||||
namespace sensor {
|
||||
|
||||
#define LOG_SENSOR(prefix, type, obj) \
|
||||
if ((obj) != nullptr) { \
|
||||
ESP_LOGCONFIG(TAG, \
|
||||
"%s%s '%s'\n" \
|
||||
"%s State Class: '%s'\n" \
|
||||
"%s Unit of Measurement: '%s'\n" \
|
||||
"%s Accuracy Decimals: %d", \
|
||||
prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str(), prefix, \
|
||||
state_class_to_string((obj)->get_state_class()).c_str(), prefix, \
|
||||
(obj)->get_unit_of_measurement().c_str(), prefix, (obj)->get_accuracy_decimals()); \
|
||||
if (!(obj)->get_device_class().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \
|
||||
} \
|
||||
if (!(obj)->get_icon().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
|
||||
} \
|
||||
if ((obj)->get_force_update()) { \
|
||||
ESP_LOGV(TAG, "%s Force Update: YES", prefix); \
|
||||
} \
|
||||
}
|
||||
// Forward declaration
|
||||
void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *obj);
|
||||
|
||||
// Macro that calls the function - kept for backward compatibility
|
||||
#define LOG_SENSOR(prefix, type, obj) log_sensor(TAG, prefix, LOG_STR_LITERAL(type), obj)
|
||||
|
||||
#define SUB_SENSOR(name) \
|
||||
protected: \
|
||||
|
@@ -105,9 +105,9 @@ void UFireECComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "uFire-EC");
|
||||
LOG_I2C_DEVICE(this)
|
||||
LOG_UPDATE_INTERVAL(this)
|
||||
LOG_SENSOR(" ", "EC Sensor", this->ec_sensor_)
|
||||
LOG_SENSOR(" ", "Temperature Sensor", this->temperature_sensor_)
|
||||
LOG_SENSOR(" ", "Temperature Sensor external", this->temperature_sensor_external_)
|
||||
LOG_SENSOR(" ", "EC Sensor", this->ec_sensor_);
|
||||
LOG_SENSOR(" ", "Temperature Sensor", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Temperature Sensor external", this->temperature_sensor_external_);
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" Temperature Compensation: %f\n"
|
||||
" Temperature Coefficient: %f",
|
||||
|
@@ -142,9 +142,9 @@ void UFireISEComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "uFire-ISE");
|
||||
LOG_I2C_DEVICE(this)
|
||||
LOG_UPDATE_INTERVAL(this)
|
||||
LOG_SENSOR(" ", "PH Sensor", this->ph_sensor_)
|
||||
LOG_SENSOR(" ", "Temperature Sensor", this->temperature_sensor_)
|
||||
LOG_SENSOR(" ", "Temperature Sensor external", this->temperature_sensor_external_)
|
||||
LOG_SENSOR(" ", "PH Sensor", this->ph_sensor_);
|
||||
LOG_SENSOR(" ", "Temperature Sensor", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Temperature Sensor external", this->temperature_sensor_external_);
|
||||
}
|
||||
|
||||
} // namespace ufire_ise
|
||||
|
Reference in New Issue
Block a user