diff --git a/components/ratgdo/number/ratgdo_number.cpp b/components/ratgdo/number/ratgdo_number.cpp index 2d794f7..fe0dcfc 100644 --- a/components/ratgdo/number/ratgdo_number.cpp +++ b/components/ratgdo/number/ratgdo_number.cpp @@ -34,11 +34,9 @@ void RATGDONumber::dump_config() case RATGDO_CLOSING_DURATION: ESP_LOGCONFIG(TAG, " Type: Closing Duration"); break; -#ifdef RATGDO_USE_DISTANCE_SENSOR case RATGDO_TARGET_DISTANCE_MEASUREMENT: ESP_LOGCONFIG(TAG, " Type: Target Distance Measurement"); break; -#endif default: break; } @@ -81,13 +79,11 @@ void RATGDONumber::setup() this->update_state(value); }); break; -#ifdef RATGDO_USE_DISTANCE_SENSOR case RATGDO_TARGET_DISTANCE_MEASUREMENT: // this->parent_->subscribe_target_distance_measurement([=](float value) { // this->update_state(value); // }); break; -#endif default: break; } @@ -111,13 +107,11 @@ void RATGDONumber::set_number_type(NumberType number_type_) this->traits.set_min_value(0x539); this->traits.set_max_value(0x7ff539); break; -#ifdef RATGDO_USE_DISTANCE_SENSOR case RATGDO_TARGET_DISTANCE_MEASUREMENT: this->traits.set_step(1); this->traits.set_min_value(5); this->traits.set_max_value(3500); break; -#endif default: break; } @@ -148,11 +142,9 @@ void RATGDONumber::control(float value) value = normalize_client_id(value); this->parent_->call_protocol(SetClientID { static_cast(value) }); break; -#ifdef RATGDO_USE_DISTANCE_SENSOR case RATGDO_TARGET_DISTANCE_MEASUREMENT: this->parent_->set_target_distance_measurement(value); break; -#endif default: break; } diff --git a/components/ratgdo/number/ratgdo_number.h b/components/ratgdo/number/ratgdo_number.h index 1eab932..fd28d32 100644 --- a/components/ratgdo/number/ratgdo_number.h +++ b/components/ratgdo/number/ratgdo_number.h @@ -13,9 +13,7 @@ enum NumberType { RATGDO_ROLLING_CODE_COUNTER, RATGDO_OPENING_DURATION, RATGDO_CLOSING_DURATION, -#ifdef RATGDO_USE_DISTANCE_SENSOR RATGDO_TARGET_DISTANCE_MEASUREMENT, -#endif }; class RATGDONumber : public number::Number, public RATGDOClient, public Component { diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index fbba48c..35c1ce6 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -266,7 +266,6 @@ void RATGDOComponent::set_closing_duration(float duration) this->closing_duration = duration; } -#ifdef RATGDO_USE_DISTANCE_SENSOR void RATGDOComponent::set_target_distance_measurement(int16_t distance) { this->target_distance_measurement = distance; @@ -276,7 +275,6 @@ void RATGDOComponent::set_distance_measurement(int16_t distance) { this->last_distance_measurement = distance; } -#endif Result RATGDOComponent::call_protocol(Args args) { diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 3af528c..7c754e2 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -73,11 +73,9 @@ public: float start_closing { -1 }; single_observable closing_duration { 0 }; -#ifdef RATGDO_USE_DISTANCE_SENSOR single_observable target_distance_measurement { -1 }; std::bitset<256> in_range; // the length of this bitset determines how many out of range readings are required for presence detection to change states observable last_distance_measurement { 0 }; -#endif single_observable openings { 0 }; // number of times the door has been opened @@ -122,10 +120,8 @@ public: void schedule_door_position_sync(float update_period = 500); void door_position_update(); void cancel_position_sync_callbacks(); -#ifdef RATGDO_USE_DISTANCE_SENSOR void set_target_distance_measurement(int16_t distance); void set_distance_measurement(int16_t distance); -#endif // light void light_on(); @@ -204,10 +200,8 @@ public: void subscribe_sync_failed(F&& f); template void subscribe_door_action_delayed(F&& f); -#ifdef RATGDO_USE_DISTANCE_SENSOR template void subscribe_distance_measurement(F&& f); -#endif protected: // Pointers first (4-byte aligned) @@ -223,9 +217,7 @@ protected: // Subscriber counters for defer name allocation uint8_t door_state_sub_num_ { 0 }; uint8_t door_action_delayed_sub_num_ { 0 }; -#ifdef RATGDO_USE_DISTANCE_SENSOR uint8_t distance_sub_num_ { 0 }; -#endif }; // RATGDOComponent void log_subscriber_overflow(const LogString* observable_name, uint32_t max); @@ -255,13 +247,9 @@ namespace scheduler_ids { inline constexpr uint32_t DEFER_DOOR_ACTION_DELAYED_COUNT = RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS; inline constexpr uint32_t DEFER_DOOR_ACTION_DELAYED_BASE = DEFER_DOOR_STATE_BASE + DEFER_DOOR_STATE_COUNT; -#ifdef RATGDO_USE_DISTANCE_SENSOR inline constexpr uint32_t DEFER_DISTANCE_COUNT = RATGDO_MAX_DISTANCE_SUBSCRIBERS; inline constexpr uint32_t DEFER_DISTANCE_BASE = DEFER_DOOR_ACTION_DELAYED_BASE + DEFER_DOOR_ACTION_DELAYED_COUNT; inline constexpr uint32_t DEFER_DISTANCE_END = DEFER_DISTANCE_BASE + DEFER_DISTANCE_COUNT; -#else - inline constexpr uint32_t DEFER_DISTANCE_END = DEFER_DOOR_ACTION_DELAYED_BASE + DEFER_DOOR_ACTION_DELAYED_COUNT; -#endif // Single-subscriber IDs enum : uint32_t { @@ -368,7 +356,6 @@ void RATGDOComponent::subscribe_door_action_delayed(F&& f) }); } -#ifdef RATGDO_USE_DISTANCE_SENSOR template void RATGDOComponent::subscribe_distance_measurement(F&& f) { @@ -378,6 +365,5 @@ void RATGDOComponent::subscribe_distance_measurement(F&& f) defer(id, [f, state] { f(state); }); }); } -#endif } // namespace esphome::ratgdo diff --git a/components/ratgdo/ratgdo_uart_esp32.cpp b/components/ratgdo/ratgdo_uart_esp32.cpp index 4b89447..2755eeb 100644 --- a/components/ratgdo/ratgdo_uart_esp32.cpp +++ b/components/ratgdo/ratgdo_uart_esp32.cpp @@ -1,7 +1,5 @@ #include "ratgdo_uart.h" -#ifdef USE_ESP32 - #include "esphome/core/log.h" #include @@ -183,5 +181,3 @@ void RatgdoUART::on_shutdown() } } // namespace esphome::ratgdo - -#endif diff --git a/components/ratgdo/ratgdo_uart_esp32.h b/components/ratgdo/ratgdo_uart_esp32.h index ad1db2f..e61d1c0 100644 --- a/components/ratgdo/ratgdo_uart_esp32.h +++ b/components/ratgdo/ratgdo_uart_esp32.h @@ -2,8 +2,6 @@ #include "esphome/core/defines.h" -#ifdef USE_ESP32 - #include #include #include @@ -53,5 +51,3 @@ private: }; } // namespace esphome::ratgdo - -#endif diff --git a/components/ratgdo/sensor/__init__.py b/components/ratgdo/sensor/__init__.py index d68e5dc..adabd0f 100644 --- a/components/ratgdo/sensor/__init__.py +++ b/components/ratgdo/sensor/__init__.py @@ -55,12 +55,10 @@ async def to_code(config): cg.add(var.set_ratgdo_sensor_type(config[CONF_TYPE])) await register_ratgdo_child(var, config) - if config["type"] == "distance": - cg.add_library(name="Wire", version=None) - cg.add_library( - name="vl53l4cx", - repository="https://github.com/stm32duino/VL53L4CX", - version=None, - ) - cg.add_define("RATGDO_USE_DISTANCE_SENSOR") - subscribe_distance() + cg.add_library(name="Wire", version=None) + cg.add_library( + name="vl53l4cx", + repository="https://github.com/stm32duino/VL53L4CX", + version=None, + ) + subscribe_distance() diff --git a/components/ratgdo/sensor/ratgdo_sensor.cpp b/components/ratgdo/sensor/ratgdo_sensor.cpp index e8c8f97..f42fae3 100644 --- a/components/ratgdo/sensor/ratgdo_sensor.cpp +++ b/components/ratgdo/sensor/ratgdo_sensor.cpp @@ -17,7 +17,6 @@ void RATGDOSensor::setup() }); break; case RATGDOSensorType::RATGDO_DISTANCE: -#ifdef RATGDO_USE_DISTANCE_SENSOR this->distance_sensor_.setI2cDevice(&I2C); this->distance_sensor_.setXShutPin(32); // I2C.begin(17,16); @@ -27,12 +26,9 @@ void RATGDOSensor::setup() this->distance_sensor_.InitSensor(0x59); this->distance_sensor_.VL53L4CX_SetDistanceMode(VL53L4CX_DISTANCEMODE_LONG); this->distance_sensor_.VL53L4CX_StartMeasurement(); -#ifdef RATGDO_USE_DISTANCE_SENSOR this->parent_->subscribe_distance_measurement([this](int16_t value) { this->publish_state(value); }); -#endif -#endif break; default: break; @@ -54,7 +50,6 @@ void RATGDOSensor::dump_config() } } -#ifdef RATGDO_USE_DISTANCE_SENSOR void RATGDOSensor::loop() { if (this->ratgdo_sensor_type_ == RATGDOSensorType::RATGDO_DISTANCE) { @@ -97,6 +92,5 @@ void RATGDOSensor::loop() } } } -#endif } // namespace esphome::ratgdo diff --git a/components/ratgdo/sensor/ratgdo_sensor.h b/components/ratgdo/sensor/ratgdo_sensor.h index 5112a88..1ef784b 100644 --- a/components/ratgdo/sensor/ratgdo_sensor.h +++ b/components/ratgdo/sensor/ratgdo_sensor.h @@ -6,11 +6,9 @@ #include "esphome/core/component.h" #include "esphome/core/defines.h" -#ifdef RATGDO_USE_DISTANCE_SENSOR #include "Wire.h" #include "vl53l4cx_class.h" #define I2C Wire -#endif namespace esphome::ratgdo { @@ -23,17 +21,13 @@ class RATGDOSensor : public sensor::Sensor, public RATGDOClient, public Componen public: void dump_config() override; void setup() override; -#ifdef RATGDO_USE_DISTANCE_SENSOR void loop() override; -#endif void set_ratgdo_sensor_type(RATGDOSensorType ratgdo_sensor_type_) { this->ratgdo_sensor_type_ = ratgdo_sensor_type_; } protected: RATGDOSensorType ratgdo_sensor_type_; -#ifdef RATGDO_USE_DISTANCE_SENSOR VL53L4CX distance_sensor_; -#endif }; } // namespace esphome::ratgdo