diff --git a/tw7100.cpp b/tw7100.cpp index c5f92c4..b69d9a9 100644 --- a/tw7100.cpp +++ b/tw7100.cpp @@ -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"); diff --git a/tw7100.h b/tw7100.h index 1b11ff3..ce2cc19 100644 --- a/tw7100.h +++ b/tw7100.h @@ -30,6 +30,18 @@ #include "number/tw7100_number.h" #endif +#ifndef USE_BINARY_SENSOR +namespace esphome { +namespace binary_sensor { +class BinarySensor : public Component { + private: + public: + void publish_state(bool state) { ESP_LOGW("dummy_binary_sensor", "skipping updating value for this unconfigured sensor"); }; +}; +} +} +#endif + namespace esphome { namespace tw7100 { @@ -121,10 +133,8 @@ class tw7100Component : public PollingComponent, public uart::UARTDevice { protected: -#ifdef USE_BINARY_SENSOR - binary_sensor::BinarySensor *powered_{nullptr}; - binary_sensor::BinarySensor *has_signal_{nullptr}; -#endif + binary_sensor::BinarySensor *powered_ = new binary_sensor::BinarySensor(); + binary_sensor::BinarySensor *has_signal_ = new binary_sensor::BinarySensor(); #ifdef USE_SENSOR sensor::Sensor *lamp_hours_{nullptr}; sensor::Sensor *power_status_{nullptr};