Introduce dummy class
This commit is contained in:
parent
ad1cc45768
commit
8ae2dd3300
|
@ -236,10 +236,8 @@ void tw7100Component::update_sensor(std::pair<std::string, std::string> data) {
|
|||
#endif
|
||||
} else if (cmd == "SIGNAL") {
|
||||
ESP_LOGV(TAG, "updating signal sensors");
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
int value = std::stoi(value_string);
|
||||
if (has_signal_) has_signal_->publish_state(value > 0);
|
||||
#endif
|
||||
has_signal_->publish_state(value > 0);
|
||||
if (signal_status_) signal_status_->publish_state(value);
|
||||
} else if (cmd == "LUMINANCE") {
|
||||
ESP_LOGV(TAG, "updating luminance sensors");
|
||||
|
|
40
tw7100.h
40
tw7100.h
|
@ -30,6 +30,27 @@
|
|||
#include "number/tw7100_number.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
#ifndef USE_SENSOR
|
||||
namespace sensor {
|
||||
class Sensor : public Component {
|
||||
public:
|
||||
void publish_state(float state) { ESP_LOGW("dummy_sensor", "skipping updating value for this unconfigured sensor"); };
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef USE_BINARY_SENSOR
|
||||
namespace binary_sensor {
|
||||
class BinarySensor : public Component {
|
||||
public:
|
||||
void publish_state(bool state) { ESP_LOGW("dummy_binary_sensor", "skipping updating value for this unconfigured sensor"); };
|
||||
};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace esphome {
|
||||
namespace tw7100 {
|
||||
|
||||
|
@ -119,18 +140,17 @@ class tw7100Component : public PollingComponent, public uart::UARTDevice {
|
|||
void set_set_destrength(tw7100::tw7100Number *number_) { this->destrength_number_ = number_; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
binary_sensor::BinarySensor *dummy_binary_sensor = new binary_sensor::BinarySensor();
|
||||
sensor::Sensor *dummy_sensor = new sensor::Sensor();
|
||||
|
||||
protected:
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
binary_sensor::BinarySensor *powered_{nullptr};
|
||||
binary_sensor::BinarySensor *has_signal_{nullptr};
|
||||
#endif
|
||||
#ifdef USE_SENSOR
|
||||
sensor::Sensor *lamp_hours_{nullptr};
|
||||
sensor::Sensor *power_status_{nullptr};
|
||||
sensor::Sensor *signal_status_{nullptr};
|
||||
sensor::Sensor *luminance_level_{nullptr};
|
||||
#endif
|
||||
binary_sensor::BinarySensor *powered_ = dummy_binary_sensor;
|
||||
binary_sensor::BinarySensor *has_signal_ = dummy_binary_sensor;
|
||||
sensor::Sensor *lamp_hours_ = dummy_sensor;
|
||||
sensor::Sensor *power_status_ = dummy_sensor;
|
||||
sensor::Sensor *signal_status_ = dummy_sensor;
|
||||
sensor::Sensor *luminance_level_ = dummy_sensor;
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
text_sensor::TextSensor *serial_{nullptr};
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue