mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 19:32:19 +01:00
[binary_sensor] Convert LOG_BINARY_SENSOR macro to function to reduce flash usage
This commit is contained in:
@@ -7,6 +7,19 @@ namespace binary_sensor {
|
|||||||
|
|
||||||
static const char *const TAG = "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) {
|
void BinarySensor::publish_state(bool new_state) {
|
||||||
if (this->filter_list_ == nullptr) {
|
if (this->filter_list_ == nullptr) {
|
||||||
this->send_state_internal(new_state);
|
this->send_state_internal(new_state);
|
||||||
|
@@ -10,13 +10,12 @@ namespace esphome {
|
|||||||
|
|
||||||
namespace binary_sensor {
|
namespace binary_sensor {
|
||||||
|
|
||||||
#define LOG_BINARY_SENSOR(prefix, type, obj) \
|
// Forward declaration
|
||||||
if ((obj) != nullptr) { \
|
class BinarySensor;
|
||||||
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
|
void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj);
|
||||||
if (!(obj)->get_device_class().empty()) { \
|
|
||||||
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \
|
// 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) \
|
#define SUB_BINARY_SENSOR(name) \
|
||||||
protected: \
|
protected: \
|
||||||
|
Reference in New Issue
Block a user