From ff57cb8b2cda2fcdcb394838806d8acab89b8750 Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Wed, 27 May 2026 12:13:01 +0000 Subject: [PATCH] Further clean up garage-gate --- components/ratgdo/binary_sensor/__init__.py | 73 ------------------- .../binary_sensor/ratgdo_binary_sensor.cpp | 57 --------------- .../binary_sensor/ratgdo_binary_sensor.h | 29 -------- components/ratgdo/output/__init__.py | 41 ----------- components/ratgdo/output/ratgdo_output.cpp | 50 ------------- components/ratgdo/output/ratgdo_output.h | 30 -------- components/ratgdo/ratgdo.h | 2 - components/ratgdo/ratgdo_state.h | 4 - 8 files changed, 286 deletions(-) delete mode 100644 components/ratgdo/binary_sensor/__init__.py delete mode 100644 components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp delete mode 100644 components/ratgdo/binary_sensor/ratgdo_binary_sensor.h delete mode 100644 components/ratgdo/output/__init__.py delete mode 100644 components/ratgdo/output/ratgdo_output.cpp delete mode 100644 components/ratgdo/output/ratgdo_output.h diff --git a/components/ratgdo/binary_sensor/__init__.py b/components/ratgdo/binary_sensor/__init__.py deleted file mode 100644 index b92f2ca..0000000 --- a/components/ratgdo/binary_sensor/__init__.py +++ /dev/null @@ -1,73 +0,0 @@ -import esphome.codegen as cg -from esphome.components import binary_sensor -import esphome.config_validation as cv -from esphome.const import CONF_ID - -from .. import ( - RATGDO_CLIENT_SCHMEA, - ratgdo_ns, - register_ratgdo_child, - subscribe_vehicle_arriving, - subscribe_vehicle_detected, - subscribe_vehicle_leaving, -) - -DEPENDENCIES = ["ratgdo"] - -# Track which sensor types have been used -USED_TYPES: set[str] = set() - -RATGDOBinarySensor = ratgdo_ns.class_( - "RATGDOBinarySensor", binary_sensor.BinarySensor, cg.Component -) -SensorType = ratgdo_ns.enum("SensorType") - -CONF_TYPE = "type" -TYPES = { - "vehicle_detected": SensorType.RATGDO_SENSOR_VEHICLE_DETECTED, - "vehicle_arriving": SensorType.RATGDO_SENSOR_VEHICLE_ARRIVING, - "vehicle_leaving": SensorType.RATGDO_SENSOR_VEHICLE_LEAVING, -} - -# Sensor types that require vehicle sensor support -VEHICLE_SENSOR_TYPES = {"vehicle_detected", "vehicle_arriving", "vehicle_leaving"} - - -def validate_unique_type(config): - """Validate that each sensor type is only used once.""" - sensor_type = config[CONF_TYPE] - if sensor_type in USED_TYPES: - raise cv.Invalid(f"Only one binary sensor of type '{sensor_type}' is allowed") - USED_TYPES.add(sensor_type) - return config - - -CONFIG_SCHEMA = cv.All( - binary_sensor.binary_sensor_schema(RATGDOBinarySensor) - .extend( - { - cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True), - } - ) - .extend(RATGDO_CLIENT_SCHMEA), - validate_unique_type, -) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await binary_sensor.register_binary_sensor(var, config) - await cg.register_component(var, config) - cg.add(var.set_binary_sensor_type(config[CONF_TYPE])) - await register_ratgdo_child(var, config) - - # Add defines for enabled features and register observable subscriptions - sensor_type = config[CONF_TYPE] - if sensor_type in VEHICLE_SENSOR_TYPES: - cg.add_define("RATGDO_USE_VEHICLE_SENSORS") - if sensor_type == "vehicle_detected": - subscribe_vehicle_detected() - elif sensor_type == "vehicle_arriving": - subscribe_vehicle_arriving() - elif sensor_type == "vehicle_leaving": - subscribe_vehicle_leaving() diff --git a/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp b/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp deleted file mode 100644 index fa05b8a..0000000 --- a/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "ratgdo_binary_sensor.h" -#include "../ratgdo_state.h" -#include "esphome/core/log.h" - -namespace esphome::ratgdo { - -static const char* const TAG = "ratgdo.binary_sensor"; - -void RATGDOBinarySensor::setup() -{ - // Initialize all sensors to false - this->publish_initial_state(false); - - switch (this->binary_sensor_type_) { -#ifdef RATGDO_USE_VEHICLE_SENSORS - case SensorType::RATGDO_SENSOR_VEHICLE_DETECTED: - this->parent_->subscribe_vehicle_detected_state([this](VehicleDetectedState state) { - this->publish_state(state == VehicleDetectedState::YES); - }); - break; - case SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING: - this->parent_->subscribe_vehicle_arriving_state([this](VehicleArrivingState state) { - this->publish_state(state == VehicleArrivingState::YES); - }); - break; - case SensorType::RATGDO_SENSOR_VEHICLE_LEAVING: - this->parent_->subscribe_vehicle_leaving_state([this](VehicleLeavingState state) { - this->publish_state(state == VehicleLeavingState::YES); - }); - break; -#endif - default: - break; - } -} - -void RATGDOBinarySensor::dump_config() -{ - LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this); - switch (this->binary_sensor_type_) { -#ifdef RATGDO_USE_VEHICLE_SENSORS - case SensorType::RATGDO_SENSOR_VEHICLE_DETECTED: - ESP_LOGCONFIG(TAG, " Type: VehicleDetected"); - break; - case SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING: - ESP_LOGCONFIG(TAG, " Type: VehicleArriving"); - break; - case SensorType::RATGDO_SENSOR_VEHICLE_LEAVING: - ESP_LOGCONFIG(TAG, " Type: VehicleLeaving"); - break; -#endif - default: - break; - } -} - -} // namespace esphome::ratgdo diff --git a/components/ratgdo/binary_sensor/ratgdo_binary_sensor.h b/components/ratgdo/binary_sensor/ratgdo_binary_sensor.h deleted file mode 100644 index f2a1c9c..0000000 --- a/components/ratgdo/binary_sensor/ratgdo_binary_sensor.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "../ratgdo.h" -#include "../ratgdo_state.h" -#include "esphome/components/binary_sensor/binary_sensor.h" -#include "esphome/core/component.h" -#include "esphome/core/defines.h" - -namespace esphome::ratgdo { - -enum SensorType : uint8_t { -#ifdef RATGDO_USE_VEHICLE_SENSORS - RATGDO_SENSOR_VEHICLE_DETECTED = 4, - RATGDO_SENSOR_VEHICLE_ARRIVING, - RATGDO_SENSOR_VEHICLE_LEAVING, -#endif -}; - -class RATGDOBinarySensor : public binary_sensor::BinarySensor, public RATGDOClient, public Component { -public: - void setup() override; - void dump_config() override; - void set_binary_sensor_type(SensorType binary_sensor_type) { this->binary_sensor_type_ = binary_sensor_type; } - -protected: - SensorType binary_sensor_type_; -}; - -} // namespace esphome::ratgdo diff --git a/components/ratgdo/output/__init__.py b/components/ratgdo/output/__init__.py deleted file mode 100644 index 082d53e..0000000 --- a/components/ratgdo/output/__init__.py +++ /dev/null @@ -1,41 +0,0 @@ -import esphome.codegen as cg -from esphome.components import rtttl -import esphome.config_validation as cv -from esphome.const import CONF_ID - -from .. import ( - RATGDO_CLIENT_SCHMEA, - ratgdo_ns, - register_ratgdo_child, - subscribe_door_action_delayed, -) - -CONF_RTTTL = "rtttl" -CONF_SONG = "song" - -DEPENDENCIES = ["esp32", "ratgdo", "rtttl"] - -RATGDOOutput = ratgdo_ns.class_("RATGDOOutput", cg.Component) -OutputType = ratgdo_ns.enum("OutputType") - -CONF_TYPE = "type" -TYPES = {"beeper": OutputType.RATGDO_BEEPER} - -CONFIG_SCHEMA = cv.Schema( - { - cv.Required(CONF_ID): cv.declare_id(RATGDOOutput), - cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True), - cv.Required(CONF_RTTTL): cv.use_id(rtttl), - cv.Required(CONF_SONG): cv.string, - } -).extend(RATGDO_CLIENT_SCHMEA) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - rtttl = await cg.get_variable(config[CONF_RTTTL]) - cg.add(var.set_rtttl(rtttl)) - cg.add(var.set_song(config[CONF_SONG])) - await register_ratgdo_child(var, config) - subscribe_door_action_delayed() diff --git a/components/ratgdo/output/ratgdo_output.cpp b/components/ratgdo/output/ratgdo_output.cpp deleted file mode 100644 index a9d394a..0000000 --- a/components/ratgdo/output/ratgdo_output.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "ratgdo_output.h" -#include "../ratgdo_state.h" -#include "esphome/core/log.h" - -namespace esphome::ratgdo { - -static const char* TAG = "ratgdo.output"; - -void RATGDOOutput::setup() -{ - ESP_LOGD(TAG, "Output was setup"); - - if (this->output_type_ == OutputType::RATGDO_BEEPER) { - this->beeper_->add_on_finished_playback_callback([this] { this->finished_playback(); }); - - this->parent_->subscribe_door_action_delayed([this](DoorActionDelayed state) { - if (state == DoorActionDelayed::YES) { - this->play(); - this->repeat_ = true; - } else if (state == DoorActionDelayed::NO) { - this->repeat_ = false; - } - }); - } -} - -void RATGDOOutput::play() -{ - this->beeper_->play(this->rtttlSong_); -} - -void RATGDOOutput::finished_playback() -{ - if (this->repeat_) - this->play(); -} - -void RATGDOOutput::dump_config() -{ - if (this->output_type_ == OutputType::RATGDO_BEEPER) { - ESP_LOGCONFIG(TAG, " Type: Beeper"); - } -} - -void RATGDOOutput::set_output_type(OutputType output_type_) -{ - this->output_type_ = output_type_; -} - -} // namespace esphome::ratgdo diff --git a/components/ratgdo/output/ratgdo_output.h b/components/ratgdo/output/ratgdo_output.h deleted file mode 100644 index 10c9303..0000000 --- a/components/ratgdo/output/ratgdo_output.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "../ratgdo.h" -#include "esphome/components/rtttl/rtttl.h" -#include "esphome/core/component.h" - -namespace esphome::ratgdo { - -enum OutputType { - RATGDO_BEEPER -}; - -class RATGDOOutput : public RATGDOClient, public Component { -public: - void setup() override; - void play(); - void finished_playback(); - void dump_config() override; - void set_output_type(OutputType output_type); - void set_song(std::string rtttlSong) { this->rtttlSong_ = rtttlSong; } - void set_rtttl(rtttl::Rtttl* output) { this->beeper_ = output; } - -protected: - OutputType output_type_; - rtttl::Rtttl* beeper_; - std::string rtttlSong_; - bool repeat_; -}; - -} // namespace esphome::ratgdo diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 7968c31..0af6ed5 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -18,7 +18,6 @@ #include "esphome/core/hal.h" #include "esphome/core/preferences.h" -#include #include #include @@ -59,7 +58,6 @@ public: float start_closing { -1 }; single_observable closing_duration { 0 }; - 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 }; single_observable openings { 0 }; // number of times the door has been opened diff --git a/components/ratgdo/ratgdo_state.h b/components/ratgdo/ratgdo_state.h index 17244d9..8932140 100644 --- a/components/ratgdo/ratgdo_state.h +++ b/components/ratgdo/ratgdo_state.h @@ -26,10 +26,6 @@ ENUM(DoorState, uint8_t, (OPENING, 4), (CLOSING, 5)) -ENUM(DoorActionDelayed, uint8_t, - (NO, 0), - (YES, 1)) - /// Enum for all states a the light can be in. ENUM(LightState, uint8_t, (OFF, 0),