From eee6f5e4d504b08b9522d30740e8207210058ddd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:05:29 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- components/ratgdo/__init__.py | 2 +- .../binary_sensor/ratgdo_binary_sensor.cpp | 6 +- components/ratgdo/number/ratgdo_number.cpp | 4 +- components/ratgdo/output/ratgdo_output.cpp | 79 ++++++++++--------- components/ratgdo/output/ratgdo_output.h | 42 +++++----- components/ratgdo/ratgdo.cpp | 28 ++++--- components/ratgdo/ratgdo.h | 2 +- components/ratgdo/ratgdo_state.h | 2 +- components/ratgdo/sensor/__init__.py | 2 +- components/ratgdo/sensor/ratgdo_sensor.cpp | 12 +-- components/ratgdo/sensor/ratgdo_sensor.h | 6 +- components/ratgdo/switch/__init__.py | 1 - components/ratgdo/switch/ratgdo_switch.cpp | 4 +- components/ratgdo/switch/ratgdo_switch.h | 4 +- static/v32board.yaml | 2 +- static/v32board_drycontact.yaml | 2 +- static/v32board_secplusv1.yaml | 2 +- static/v32disco.yaml | 2 +- static/v32disco_drycontact.yaml | 2 +- static/v32disco_secplusv1.yaml | 2 +- 20 files changed, 107 insertions(+), 99 deletions(-) diff --git a/components/ratgdo/__init__.py b/components/ratgdo/__init__.py index a6493c7..5153cad 100644 --- a/components/ratgdo/__init__.py +++ b/components/ratgdo/__init__.py @@ -144,4 +144,4 @@ async def to_code(config): cg.add(var.set_discrete_open_pin(pin)) if CONF_DISCRETE_CLOSE_PIN in config and config[CONF_DISCRETE_CLOSE_PIN]: pin = await cg.gpio_pin_expression(config[CONF_DISCRETE_CLOSE_PIN]) - cg.add(var.set_discrete_close_pin(pin)) \ No newline at end of file + cg.add(var.set_discrete_close_pin(pin)) diff --git a/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp b/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp index ffd2985..2c50669 100644 --- a/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp +++ b/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp @@ -28,18 +28,18 @@ namespace ratgdo { this->parent_->subscribe_button_state([=](ButtonState state) { this->publish_state(state == ButtonState::PRESSED); }); - } else if(this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_DETECTED) { + } else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_DETECTED) { this->publish_initial_state(false); this->parent_->subscribe_vehicle_detected_state([=](VehicleDetectedState state) { this->publish_state(state == VehicleDetectedState::YES); this->parent_->presence_change(state == VehicleDetectedState::YES); }); - } else if(this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING) { + } else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING) { this->publish_initial_state(false); this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { this->publish_state(state == VehicleArrivingState::YES); }); - } else if(this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_LEAVING) { + } else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_LEAVING) { this->publish_initial_state(false); this->parent_->subscribe_vehicle_leaving_state([=](VehicleLeavingState state) { this->publish_state(state == VehicleLeavingState::YES); diff --git a/components/ratgdo/number/ratgdo_number.cpp b/components/ratgdo/number/ratgdo_number.cpp index da99b5d..40ab378 100644 --- a/components/ratgdo/number/ratgdo_number.cpp +++ b/components/ratgdo/number/ratgdo_number.cpp @@ -74,7 +74,7 @@ namespace ratgdo { this->parent_->subscribe_closing_delay([=](uint32_t value) { this->update_state(value); }); - } else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT){ + } else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) { // this->parent_->subscribe_target_distance_measurement([=](float value) { // this->update_state(value); // }); @@ -98,7 +98,7 @@ namespace ratgdo { this->traits.set_step(0x1000); this->traits.set_min_value(0x539); this->traits.set_max_value(0x7ff539); - } else if(this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) { + } else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) { this->traits.set_step(1); this->traits.set_min_value(5); this->traits.set_max_value(3500); diff --git a/components/ratgdo/output/ratgdo_output.cpp b/components/ratgdo/output/ratgdo_output.cpp index c67a8e1..ba389ba 100644 --- a/components/ratgdo/output/ratgdo_output.cpp +++ b/components/ratgdo/output/ratgdo_output.cpp @@ -5,49 +5,54 @@ namespace esphome { namespace ratgdo { -static const char *TAG = "ratgdo.output"; + static const char* TAG = "ratgdo.output"; -void RATGDOOutput::setup(){ - ESP_LOGD(TAG,"Output was setup"); + void RATGDOOutput::setup() + { + ESP_LOGD(TAG, "Output was setup"); - if(this->output_type_ == OutputType::RATGDO_BEEPER){ - this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); }); + if (this->output_type_ == OutputType::RATGDO_BEEPER) { + this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); }); - this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { - if(state == VehicleArrivingState::YES){ - this->play(); - } - }); - - this->parent_->subscribe_door_action_delayed([=](DoorActionDelayed state) { - if(state == DoorActionDelayed::YES){ - this->play(); - this->repeat_ = true; - } else if(state == DoorActionDelayed::NO) { - this->repeat_ = false; - } - }); + this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { + if (state == VehicleArrivingState::YES) { + this->play(); + } + }); + this->parent_->subscribe_door_action_delayed([=](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::play() + { + this->beeper_->play(this->rtttlSong_); } -} -void RATGDOOutput::set_output_type(OutputType output_type_) { - this->output_type_ = output_type_; -} + void RATGDOOutput::finished_playback() + { + if (this->repeat_) + this->play(); + } -} //namespace ratgdo -} //namespace esphome \ No newline at end of file + 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 ratgdo +} // namespace esphome diff --git a/components/ratgdo/output/ratgdo_output.h b/components/ratgdo/output/ratgdo_output.h index 873bb73..f15a5d6 100644 --- a/components/ratgdo/output/ratgdo_output.h +++ b/components/ratgdo/output/ratgdo_output.h @@ -1,32 +1,32 @@ #pragma once #include "../ratgdo.h" -#include "esphome/core/component.h" #include "esphome/components/rtttl/rtttl.h" +#include "esphome/core/component.h" namespace esphome { namespace ratgdo { - enum OutputType { - RATGDO_BEEPER - }; + 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; } + 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_; - }; + protected: + OutputType output_type_; + rtttl::Rtttl* beeper_; + std::string rtttlSong_; + bool repeat_; + }; -} //namespace ratgdo -} //namespace esphome \ No newline at end of file +} // namespace ratgdo +} // namespace esphome diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 154371f..309ff85 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -63,14 +63,14 @@ namespace ratgdo { this->subscribe_door_state([=](DoorState state, float position) { static DoorState lastState = DoorState::UNKNOWN; - if(lastState != DoorState::UNKNOWN && state != DoorState::CLOSED && !this->presence_detect_window_active_){ + if (lastState != DoorState::UNKNOWN && state != DoorState::CLOSED && !this->presence_detect_window_active_) { this->presence_detect_window_active_ = true; set_timeout("presence_detect_window", PRESENCE_DETECT_WINDOW, [=] { this->presence_detect_window_active_ = false; }); } - if(state == DoorState::CLOSED){ + if (state == DoorState::CLOSED) { this->presence_detect_window_active_ = false; cancel_timeout("presence_detect_window"); } @@ -361,13 +361,15 @@ namespace ratgdo { this->closing_duration = duration; } - void RATGDOComponent::set_target_distance_measurement(int16_t distance){ + void RATGDOComponent::set_target_distance_measurement(int16_t distance) + { this->target_distance_measurement = distance; } void RATGDOComponent::set_distance_measurement(int16_t distance) { - if(distance > 0 && distance < MIN_DISTANCE) return; + if (distance > 0 && distance < MIN_DISTANCE) + return; this->last_distance_measurement = distance; @@ -394,9 +396,11 @@ namespace ratgdo { all_out_of_range = false; } } - - if(all_in_range) this->vehicle_detected_state = VehicleDetectedState::YES; - if(all_out_of_range) this->vehicle_detected_state = VehicleDetectedState::NO; + + if (all_in_range) + this->vehicle_detected_state = VehicleDetectedState::YES; + if (all_out_of_range) + this->vehicle_detected_state = VehicleDetectedState::NO; // auto k = this->distance_measurement; // ESP_LOGD(TAG,"measure: %i,%i,%i,%i,%i,%i,%i,%i,%i,%i; target: %i; all_in: %s; all_out: %s;", k[0],k[1],k[2],k[3],k[4],k[5],k[6],k[7],k[8],k[9], *this->target_distance_measurement, all_in_range ? "y" : "n", all_out_of_range ? "y" : "n"); @@ -404,14 +408,14 @@ namespace ratgdo { void RATGDOComponent::presence_change(bool sensor_value) { - if(this->presence_detect_window_active_){ - if(sensor_value){ + if (this->presence_detect_window_active_) { + if (sensor_value) { this->vehicle_arriving_state = VehicleArrivingState::YES; this->vehicle_leaving_state = VehicleLeavingState::NO; set_timeout(CLEAR_PRESENCE, [=] { this->vehicle_arriving_state = VehicleArrivingState::NO; }); - }else{ + } else { this->vehicle_arriving_state = VehicleArrivingState::NO; this->vehicle_leaving_state = VehicleLeavingState::YES; set_timeout(CLEAR_PRESENCE, [=] { @@ -584,13 +588,13 @@ namespace ratgdo { void RATGDOComponent::door_action(DoorAction action) { - if(*this->closing_delay > 0 && action == DoorAction::CLOSE){ + if (*this->closing_delay > 0 && action == DoorAction::CLOSE) { this->door_action_delayed = DoorActionDelayed::YES; set_timeout("door_action", *this->closing_delay * 1000, [=] { this->door_action_delayed = DoorActionDelayed::NO; this->protocol_->door_action(DoorAction::CLOSE); }); - }else{ + } else { this->protocol_->door_action(action); } } diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index a6524ac..35a9b46 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -65,7 +65,7 @@ namespace ratgdo { observable closing_delay { 0 }; observable target_distance_measurement { -1 }; - std::vector distance_measurement{std::vector(10,-1)}; // the length of this vector determines how many in-range readings are required for presence detection to change states + std::vector distance_measurement { std::vector(10, -1) }; // the length of this vector determines how many in-range readings are required for presence detection to change states observable last_distance_measurement { 0 }; 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 f541e6e..679cc8b 100644 --- a/components/ratgdo/ratgdo_state.h +++ b/components/ratgdo/ratgdo_state.h @@ -25,7 +25,7 @@ namespace ratgdo { (STOPPED, 3), (OPENING, 4), (CLOSING, 5)) - + ENUM(DoorActionDelayed, uint8_t, (NO, 0), (YES, 1)) diff --git a/components/ratgdo/sensor/__init__.py b/components/ratgdo/sensor/__init__.py index 70b44dd..d87d320 100644 --- a/components/ratgdo/sensor/__init__.py +++ b/components/ratgdo/sensor/__init__.py @@ -40,7 +40,7 @@ async def to_code(config): await cg.register_component(var, 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", diff --git a/components/ratgdo/sensor/ratgdo_sensor.cpp b/components/ratgdo/sensor/ratgdo_sensor.cpp index c79cfe6..e90017f 100644 --- a/components/ratgdo/sensor/ratgdo_sensor.cpp +++ b/components/ratgdo/sensor/ratgdo_sensor.cpp @@ -38,7 +38,7 @@ namespace ratgdo { this->distance_sensor_.setI2cDevice(&I2C); this->distance_sensor_.setXShutPin(32); // I2C.begin(17,16); - I2C.begin(19,18); + I2C.begin(19, 18); this->distance_sensor_.begin(); this->distance_sensor_.VL53L4CX_Off(); this->distance_sensor_.InitSensor(0x59); @@ -77,7 +77,7 @@ namespace ratgdo { #ifdef USE_DISTANCE if (this->ratgdo_sensor_type_ == RATGDOSensorType::RATGDO_DISTANCE) { VL53L4CX_MultiRangingData_t distanceData; - VL53L4CX_MultiRangingData_t *pDistanceData = &distanceData; + VL53L4CX_MultiRangingData_t* pDistanceData = &distanceData; uint8_t dataReady = 0; int objCount = 0; int16_t maxDistance = 0; @@ -86,15 +86,15 @@ namespace ratgdo { if (this->distance_sensor_.VL53L4CX_GetMeasurementDataReady(&dataReady) == 0 && dataReady) { status = this->distance_sensor_.VL53L4CX_GetMultiRangingData(pDistanceData); objCount = pDistanceData->NumberOfObjectsFound; - + maxDistance = objCount == 0 ? -1 : pDistanceData->RangeData[objCount - 1].RangeMilliMeter; - /* if(maxDistance < 0) maxDistance = -1; - * if the sensor is pointed at glass, there are many error readings which will fill the + /* if(maxDistance < 0) maxDistance = -1; + * if the sensor is pointed at glass, there are many error readings which will fill the * vector with out of range data. The sensor should be sensitive enough to detect the floor * in most situations, unless its mounted really far away. * If this doesn't work, then the vector size will have to increase substantially */ - if(maxDistance > 0){ + if (maxDistance > 0) { this->parent_->set_distance_measurement(maxDistance); } diff --git a/components/ratgdo/sensor/ratgdo_sensor.h b/components/ratgdo/sensor/ratgdo_sensor.h index cf405d4..d7cfdaf 100644 --- a/components/ratgdo/sensor/ratgdo_sensor.h +++ b/components/ratgdo/sensor/ratgdo_sensor.h @@ -6,9 +6,9 @@ #include "esphome/core/component.h" #ifdef USE_DISTANCE - #include "Wire.h" - #include "vl53l4cx_class.h" - #define I2C Wire +#include "Wire.h" +#include "vl53l4cx_class.h" +#define I2C Wire #endif namespace esphome { diff --git a/components/ratgdo/switch/__init__.py b/components/ratgdo/switch/__init__.py index 786d9c8..c13265b 100644 --- a/components/ratgdo/switch/__init__.py +++ b/components/ratgdo/switch/__init__.py @@ -39,4 +39,3 @@ async def to_code(config): if CONF_PIN in config: pin = await cg.gpio_pin_expression(config[CONF_PIN]) cg.add(var.set_pin(pin)) - diff --git a/components/ratgdo/switch/ratgdo_switch.cpp b/components/ratgdo/switch/ratgdo_switch.cpp index 18a589a..11b85dd 100644 --- a/components/ratgdo/switch/ratgdo_switch.cpp +++ b/components/ratgdo/switch/ratgdo_switch.cpp @@ -21,7 +21,7 @@ namespace ratgdo { this->parent_->subscribe_learn_state([=](LearnState state) { this->publish_state(state == LearnState::ACTIVE); }); - }else if(this->switch_type_ == SwitchType::RATGDO_LED) { + } else if (this->switch_type_ == SwitchType::RATGDO_LED) { this->pin_->setup(); this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { this->write_state(state == VehicleArrivingState::YES); @@ -37,7 +37,7 @@ namespace ratgdo { } else { this->parent_->inactivate_learn(); } - } else if(this->switch_type_ == SwitchType::RATGDO_LED){ + } else if (this->switch_type_ == SwitchType::RATGDO_LED) { this->pin_->digital_write(state); this->publish_state(state); } diff --git a/components/ratgdo/switch/ratgdo_switch.h b/components/ratgdo/switch/ratgdo_switch.h index 8b195df..f4631c4 100644 --- a/components/ratgdo/switch/ratgdo_switch.h +++ b/components/ratgdo/switch/ratgdo_switch.h @@ -20,11 +20,11 @@ namespace ratgdo { void set_switch_type(SwitchType switch_type_) { this->switch_type_ = switch_type_; } void write_state(bool state) override; - void set_pin(GPIOPin *pin) { pin_ = pin; } + void set_pin(GPIOPin* pin) { pin_ = pin; } protected: SwitchType switch_type_; - GPIOPin *pin_; + GPIOPin* pin_; }; } // namespace ratgdo diff --git a/static/v32board.yaml b/static/v32board.yaml index 2f9a0a3..743973f 100644 --- a/static/v32board.yaml +++ b/static/v32board.yaml @@ -62,4 +62,4 @@ improv_serial: wifi: ap: -logger: \ No newline at end of file +logger: diff --git a/static/v32board_drycontact.yaml b/static/v32board_drycontact.yaml index 7f89fe7..e9df584 100644 --- a/static/v32board_drycontact.yaml +++ b/static/v32board_drycontact.yaml @@ -61,4 +61,4 @@ improv_serial: wifi: ap: -logger: \ No newline at end of file +logger: diff --git a/static/v32board_secplusv1.yaml b/static/v32board_secplusv1.yaml index 2a0f75a..e433ae1 100644 --- a/static/v32board_secplusv1.yaml +++ b/static/v32board_secplusv1.yaml @@ -62,4 +62,4 @@ improv_serial: wifi: ap: -logger: \ No newline at end of file +logger: diff --git a/static/v32disco.yaml b/static/v32disco.yaml index b850723..01b3307 100644 --- a/static/v32disco.yaml +++ b/static/v32disco.yaml @@ -149,4 +149,4 @@ sensor: # - clamp: # min_value: 0 # max_value: 100 - # unit_of_measurement: "%" \ No newline at end of file + # unit_of_measurement: "%" diff --git a/static/v32disco_drycontact.yaml b/static/v32disco_drycontact.yaml index ab24738..a87f691 100644 --- a/static/v32disco_drycontact.yaml +++ b/static/v32disco_drycontact.yaml @@ -141,4 +141,4 @@ sensor: filters: - calibrate_linear: - 1.16 -> 5 - - 2.783 -> 12 \ No newline at end of file + - 2.783 -> 12 diff --git a/static/v32disco_secplusv1.yaml b/static/v32disco_secplusv1.yaml index 58ce207..bb80b95 100644 --- a/static/v32disco_secplusv1.yaml +++ b/static/v32disco_secplusv1.yaml @@ -142,4 +142,4 @@ sensor: filters: - calibrate_linear: - 1.16 -> 5 - - 2.783 -> 12 \ No newline at end of file + - 2.783 -> 12