[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-11-10 18:05:29 +00:00
parent fd43050842
commit eee6f5e4d5
20 changed files with 107 additions and 99 deletions

View File

@ -144,4 +144,4 @@ async def to_code(config):
cg.add(var.set_discrete_open_pin(pin)) cg.add(var.set_discrete_open_pin(pin))
if CONF_DISCRETE_CLOSE_PIN in config and config[CONF_DISCRETE_CLOSE_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]) pin = await cg.gpio_pin_expression(config[CONF_DISCRETE_CLOSE_PIN])
cg.add(var.set_discrete_close_pin(pin)) cg.add(var.set_discrete_close_pin(pin))

View File

@ -28,18 +28,18 @@ namespace ratgdo {
this->parent_->subscribe_button_state([=](ButtonState state) { this->parent_->subscribe_button_state([=](ButtonState state) {
this->publish_state(state == ButtonState::PRESSED); 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->publish_initial_state(false);
this->parent_->subscribe_vehicle_detected_state([=](VehicleDetectedState state) { this->parent_->subscribe_vehicle_detected_state([=](VehicleDetectedState state) {
this->publish_state(state == VehicleDetectedState::YES); this->publish_state(state == VehicleDetectedState::YES);
this->parent_->presence_change(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->publish_initial_state(false);
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
this->publish_state(state == VehicleArrivingState::YES); 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->publish_initial_state(false);
this->parent_->subscribe_vehicle_leaving_state([=](VehicleLeavingState state) { this->parent_->subscribe_vehicle_leaving_state([=](VehicleLeavingState state) {
this->publish_state(state == VehicleLeavingState::YES); this->publish_state(state == VehicleLeavingState::YES);

View File

@ -74,7 +74,7 @@ namespace ratgdo {
this->parent_->subscribe_closing_delay([=](uint32_t value) { this->parent_->subscribe_closing_delay([=](uint32_t value) {
this->update_state(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->parent_->subscribe_target_distance_measurement([=](float value) {
// this->update_state(value); // this->update_state(value);
// }); // });
@ -98,7 +98,7 @@ namespace ratgdo {
this->traits.set_step(0x1000); this->traits.set_step(0x1000);
this->traits.set_min_value(0x539); this->traits.set_min_value(0x539);
this->traits.set_max_value(0x7ff539); 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_step(1);
this->traits.set_min_value(5); this->traits.set_min_value(5);
this->traits.set_max_value(3500); this->traits.set_max_value(3500);

View File

@ -5,49 +5,54 @@
namespace esphome { namespace esphome {
namespace ratgdo { namespace ratgdo {
static const char *TAG = "ratgdo.output"; static const char* TAG = "ratgdo.output";
void RATGDOOutput::setup(){ void RATGDOOutput::setup()
ESP_LOGD(TAG,"Output was setup"); {
ESP_LOGD(TAG, "Output was setup");
if(this->output_type_ == OutputType::RATGDO_BEEPER){ if (this->output_type_ == OutputType::RATGDO_BEEPER) {
this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); }); this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); });
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
if(state == VehicleArrivingState::YES){ if (state == VehicleArrivingState::YES) {
this->play(); 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_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(){ void RATGDOOutput::play()
this->beeper_->play(this->rtttlSong_); {
} 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_) { void RATGDOOutput::finished_playback()
this->output_type_ = output_type_; {
} if (this->repeat_)
this->play();
}
} //namespace ratgdo void RATGDOOutput::dump_config()
} //namespace esphome {
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

View File

@ -1,32 +1,32 @@
#pragma once #pragma once
#include "../ratgdo.h" #include "../ratgdo.h"
#include "esphome/core/component.h"
#include "esphome/components/rtttl/rtttl.h" #include "esphome/components/rtttl/rtttl.h"
#include "esphome/core/component.h"
namespace esphome { namespace esphome {
namespace ratgdo { namespace ratgdo {
enum OutputType { enum OutputType {
RATGDO_BEEPER RATGDO_BEEPER
}; };
class RATGDOOutput : public RATGDOClient, public Component { class RATGDOOutput : public RATGDOClient, public Component {
public: public:
void setup() override; void setup() override;
void play(); void play();
void finished_playback(); void finished_playback();
void dump_config() override; void dump_config() override;
void set_output_type(OutputType output_type); void set_output_type(OutputType output_type);
void set_song(std::string rtttlSong){ this->rtttlSong_ = rtttlSong; } void set_song(std::string rtttlSong) { this->rtttlSong_ = rtttlSong; }
void set_rtttl(rtttl::Rtttl *output){ this->beeper_ = output; } void set_rtttl(rtttl::Rtttl* output) { this->beeper_ = output; }
protected: protected:
OutputType output_type_; OutputType output_type_;
rtttl::Rtttl* beeper_; rtttl::Rtttl* beeper_;
std::string rtttlSong_; std::string rtttlSong_;
bool repeat_; bool repeat_;
}; };
} //namespace ratgdo } // namespace ratgdo
} //namespace esphome } // namespace esphome

View File

@ -63,14 +63,14 @@ namespace ratgdo {
this->subscribe_door_state([=](DoorState state, float position) { this->subscribe_door_state([=](DoorState state, float position) {
static DoorState lastState = DoorState::UNKNOWN; 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; this->presence_detect_window_active_ = true;
set_timeout("presence_detect_window", PRESENCE_DETECT_WINDOW, [=] { set_timeout("presence_detect_window", PRESENCE_DETECT_WINDOW, [=] {
this->presence_detect_window_active_ = false; this->presence_detect_window_active_ = false;
}); });
} }
if(state == DoorState::CLOSED){ if (state == DoorState::CLOSED) {
this->presence_detect_window_active_ = false; this->presence_detect_window_active_ = false;
cancel_timeout("presence_detect_window"); cancel_timeout("presence_detect_window");
} }
@ -361,13 +361,15 @@ namespace ratgdo {
this->closing_duration = duration; 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; this->target_distance_measurement = distance;
} }
void RATGDOComponent::set_distance_measurement(int16_t 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; this->last_distance_measurement = distance;
@ -394,9 +396,11 @@ namespace ratgdo {
all_out_of_range = false; all_out_of_range = false;
} }
} }
if(all_in_range) this->vehicle_detected_state = VehicleDetectedState::YES; if (all_in_range)
if(all_out_of_range) this->vehicle_detected_state = VehicleDetectedState::NO; this->vehicle_detected_state = VehicleDetectedState::YES;
if (all_out_of_range)
this->vehicle_detected_state = VehicleDetectedState::NO;
// auto k = this->distance_measurement; // 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"); // 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) void RATGDOComponent::presence_change(bool sensor_value)
{ {
if(this->presence_detect_window_active_){ if (this->presence_detect_window_active_) {
if(sensor_value){ if (sensor_value) {
this->vehicle_arriving_state = VehicleArrivingState::YES; this->vehicle_arriving_state = VehicleArrivingState::YES;
this->vehicle_leaving_state = VehicleLeavingState::NO; this->vehicle_leaving_state = VehicleLeavingState::NO;
set_timeout(CLEAR_PRESENCE, [=] { set_timeout(CLEAR_PRESENCE, [=] {
this->vehicle_arriving_state = VehicleArrivingState::NO; this->vehicle_arriving_state = VehicleArrivingState::NO;
}); });
}else{ } else {
this->vehicle_arriving_state = VehicleArrivingState::NO; this->vehicle_arriving_state = VehicleArrivingState::NO;
this->vehicle_leaving_state = VehicleLeavingState::YES; this->vehicle_leaving_state = VehicleLeavingState::YES;
set_timeout(CLEAR_PRESENCE, [=] { set_timeout(CLEAR_PRESENCE, [=] {
@ -584,13 +588,13 @@ namespace ratgdo {
void RATGDOComponent::door_action(DoorAction action) 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; this->door_action_delayed = DoorActionDelayed::YES;
set_timeout("door_action", *this->closing_delay * 1000, [=] { set_timeout("door_action", *this->closing_delay * 1000, [=] {
this->door_action_delayed = DoorActionDelayed::NO; this->door_action_delayed = DoorActionDelayed::NO;
this->protocol_->door_action(DoorAction::CLOSE); this->protocol_->door_action(DoorAction::CLOSE);
}); });
}else{ } else {
this->protocol_->door_action(action); this->protocol_->door_action(action);
} }
} }

View File

@ -65,7 +65,7 @@ namespace ratgdo {
observable<uint32_t> closing_delay { 0 }; observable<uint32_t> closing_delay { 0 };
observable<int16_t> target_distance_measurement { -1 }; observable<int16_t> target_distance_measurement { -1 };
std::vector<int16_t> distance_measurement{std::vector<int16_t>(10,-1)}; // the length of this vector determines how many in-range readings are required for presence detection to change states std::vector<int16_t> distance_measurement { std::vector<int16_t>(10, -1) }; // the length of this vector determines how many in-range readings are required for presence detection to change states
observable<int16_t> last_distance_measurement { 0 }; observable<int16_t> last_distance_measurement { 0 };
observable<uint16_t> openings { 0 }; // number of times the door has been opened observable<uint16_t> openings { 0 }; // number of times the door has been opened

View File

@ -25,7 +25,7 @@ namespace ratgdo {
(STOPPED, 3), (STOPPED, 3),
(OPENING, 4), (OPENING, 4),
(CLOSING, 5)) (CLOSING, 5))
ENUM(DoorActionDelayed, uint8_t, ENUM(DoorActionDelayed, uint8_t,
(NO, 0), (NO, 0),
(YES, 1)) (YES, 1))

View File

@ -40,7 +40,7 @@ async def to_code(config):
await cg.register_component(var, config) await cg.register_component(var, config)
cg.add(var.set_ratgdo_sensor_type(config[CONF_TYPE])) cg.add(var.set_ratgdo_sensor_type(config[CONF_TYPE]))
await register_ratgdo_child(var, config) await register_ratgdo_child(var, config)
if config['type'] == 'distance': if config['type'] == 'distance':
cg.add_library( cg.add_library(
name="Wire", name="Wire",

View File

@ -38,7 +38,7 @@ namespace ratgdo {
this->distance_sensor_.setI2cDevice(&I2C); this->distance_sensor_.setI2cDevice(&I2C);
this->distance_sensor_.setXShutPin(32); this->distance_sensor_.setXShutPin(32);
// I2C.begin(17,16); // I2C.begin(17,16);
I2C.begin(19,18); I2C.begin(19, 18);
this->distance_sensor_.begin(); this->distance_sensor_.begin();
this->distance_sensor_.VL53L4CX_Off(); this->distance_sensor_.VL53L4CX_Off();
this->distance_sensor_.InitSensor(0x59); this->distance_sensor_.InitSensor(0x59);
@ -77,7 +77,7 @@ namespace ratgdo {
#ifdef USE_DISTANCE #ifdef USE_DISTANCE
if (this->ratgdo_sensor_type_ == RATGDOSensorType::RATGDO_DISTANCE) { if (this->ratgdo_sensor_type_ == RATGDOSensorType::RATGDO_DISTANCE) {
VL53L4CX_MultiRangingData_t distanceData; VL53L4CX_MultiRangingData_t distanceData;
VL53L4CX_MultiRangingData_t *pDistanceData = &distanceData; VL53L4CX_MultiRangingData_t* pDistanceData = &distanceData;
uint8_t dataReady = 0; uint8_t dataReady = 0;
int objCount = 0; int objCount = 0;
int16_t maxDistance = 0; int16_t maxDistance = 0;
@ -86,15 +86,15 @@ namespace ratgdo {
if (this->distance_sensor_.VL53L4CX_GetMeasurementDataReady(&dataReady) == 0 && dataReady) { if (this->distance_sensor_.VL53L4CX_GetMeasurementDataReady(&dataReady) == 0 && dataReady) {
status = this->distance_sensor_.VL53L4CX_GetMultiRangingData(pDistanceData); status = this->distance_sensor_.VL53L4CX_GetMultiRangingData(pDistanceData);
objCount = pDistanceData->NumberOfObjectsFound; objCount = pDistanceData->NumberOfObjectsFound;
maxDistance = objCount == 0 ? -1 : pDistanceData->RangeData[objCount - 1].RangeMilliMeter; maxDistance = objCount == 0 ? -1 : pDistanceData->RangeData[objCount - 1].RangeMilliMeter;
/* if(maxDistance < 0) maxDistance = -1; /* if(maxDistance < 0) maxDistance = -1;
* if the sensor is pointed at glass, there are many error readings which will fill the * 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 * 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. * in most situations, unless its mounted really far away.
* If this doesn't work, then the vector size will have to increase substantially * 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); this->parent_->set_distance_measurement(maxDistance);
} }

View File

@ -6,9 +6,9 @@
#include "esphome/core/component.h" #include "esphome/core/component.h"
#ifdef USE_DISTANCE #ifdef USE_DISTANCE
#include "Wire.h" #include "Wire.h"
#include "vl53l4cx_class.h" #include "vl53l4cx_class.h"
#define I2C Wire #define I2C Wire
#endif #endif
namespace esphome { namespace esphome {

View File

@ -39,4 +39,3 @@ async def to_code(config):
if CONF_PIN in config: if CONF_PIN in config:
pin = await cg.gpio_pin_expression(config[CONF_PIN]) pin = await cg.gpio_pin_expression(config[CONF_PIN])
cg.add(var.set_pin(pin)) cg.add(var.set_pin(pin))

View File

@ -21,7 +21,7 @@ namespace ratgdo {
this->parent_->subscribe_learn_state([=](LearnState state) { this->parent_->subscribe_learn_state([=](LearnState state) {
this->publish_state(state == LearnState::ACTIVE); 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->pin_->setup();
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
this->write_state(state == VehicleArrivingState::YES); this->write_state(state == VehicleArrivingState::YES);
@ -37,7 +37,7 @@ namespace ratgdo {
} else { } else {
this->parent_->inactivate_learn(); 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->pin_->digital_write(state);
this->publish_state(state); this->publish_state(state);
} }

View File

@ -20,11 +20,11 @@ namespace ratgdo {
void set_switch_type(SwitchType switch_type_) { this->switch_type_ = switch_type_; } void set_switch_type(SwitchType switch_type_) { this->switch_type_ = switch_type_; }
void write_state(bool state) override; void write_state(bool state) override;
void set_pin(GPIOPin *pin) { pin_ = pin; } void set_pin(GPIOPin* pin) { pin_ = pin; }
protected: protected:
SwitchType switch_type_; SwitchType switch_type_;
GPIOPin *pin_; GPIOPin* pin_;
}; };
} // namespace ratgdo } // namespace ratgdo

View File

@ -62,4 +62,4 @@ improv_serial:
wifi: wifi:
ap: ap:
logger: logger:

View File

@ -61,4 +61,4 @@ improv_serial:
wifi: wifi:
ap: ap:
logger: logger:

View File

@ -62,4 +62,4 @@ improv_serial:
wifi: wifi:
ap: ap:
logger: logger:

View File

@ -149,4 +149,4 @@ sensor:
# - clamp: # - clamp:
# min_value: 0 # min_value: 0
# max_value: 100 # max_value: 100
# unit_of_measurement: "%" # unit_of_measurement: "%"

View File

@ -141,4 +141,4 @@ sensor:
filters: filters:
- calibrate_linear: - calibrate_linear:
- 1.16 -> 5 - 1.16 -> 5
- 2.783 -> 12 - 2.783 -> 12

View File

@ -142,4 +142,4 @@ sensor:
filters: filters:
- calibrate_linear: - calibrate_linear:
- 1.16 -> 5 - 1.16 -> 5
- 2.783 -> 12 - 2.783 -> 12