Skip to content

Commit c603f01

Browse files
authored
chore: add clang pre-commit (#299)
1 parent a90b6fb commit c603f01

11 files changed

+50
-44
lines changed

.pre-commit-config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ repos:
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
99
- id: check-added-large-files
10+
- repo: https://github.com/pre-commit/mirrors-clang-format
11+
rev: v18.1.8
12+
hooks:
13+
- id: clang-format
14+
types_or:
15+
- "c++"
16+
- "c"
17+
- "cuda"
18+
args: [-style=Webkit, -i]

components/ratgdo/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def validate_protocol(config):
5151
raise cv.Invalid("dry_contact_close_sensor and dry_contact_open_sensor are only valid when using protocol drycontact")
5252
# if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and CONF_DRY_CONTACT_OPEN_SENSOR not in config:
5353
# raise cv.Invalid("dry_contact_open_sensor is required when using protocol drycontact")
54-
return config
54+
return config
5555

5656
CONFIG_SCHEMA = cv.All(
5757
cv.Schema(
@@ -144,4 +144,4 @@ async def to_code(config):
144144
cg.add(var.set_discrete_open_pin(pin))
145145
if CONF_DISCRETE_CLOSE_PIN in config and config[CONF_DISCRETE_CLOSE_PIN]:
146146
pin = await cg.gpio_pin_expression(config[CONF_DISCRETE_CLOSE_PIN])
147-
cg.add(var.set_discrete_close_pin(pin))
147+
cg.add(var.set_discrete_close_pin(pin))

components/ratgdo/common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#pragma once
22

33
#define ESP_LOG1 ESP_LOGV
4-
#define ESP_LOG2 ESP_LOGV
4+
#define ESP_LOG2 ESP_LOGV

components/ratgdo/dry_contact.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#include "dry_contact.h"
33
#include "ratgdo.h"
44

5+
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
56
#include "esphome/core/gpio.h"
67
#include "esphome/core/log.h"
78
#include "esphome/core/scheduler.h"
8-
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
99

1010
namespace esphome {
1111
namespace ratgdo {
@@ -19,7 +19,7 @@ namespace ratgdo {
1919
this->scheduler_ = scheduler;
2020
this->tx_pin_ = tx_pin;
2121
this->rx_pin_ = rx_pin;
22-
22+
2323
this->open_limit_reached_ = 0;
2424
this->last_open_limit_ = 0;
2525
this->close_limit_reached_ = 0;
@@ -58,18 +58,19 @@ namespace ratgdo {
5858
this->close_limit_reached_ = state;
5959
this->send_door_state();
6060
}
61-
62-
void DryContact::send_door_state(){
63-
if(this->open_limit_reached_){
61+
62+
void DryContact::send_door_state()
63+
{
64+
if (this->open_limit_reached_) {
6465
this->door_state_ = DoorState::OPEN;
65-
}else if(this->close_limit_reached_){
66+
} else if (this->close_limit_reached_) {
6667
this->door_state_ = DoorState::CLOSED;
67-
}else if(!this->close_limit_reached_ && !this->open_limit_reached_){
68-
if(this->last_close_limit_){
68+
} else if (!this->close_limit_reached_ && !this->open_limit_reached_) {
69+
if (this->last_close_limit_) {
6970
this->door_state_ = DoorState::OPENING;
7071
}
7172

72-
if(this->last_open_limit_){
73+
if (this->last_open_limit_) {
7374
this->door_state_ = DoorState::CLOSING;
7475
}
7576
}
@@ -102,14 +103,14 @@ namespace ratgdo {
102103

103104
ESP_LOG1(TAG, "Door action: %s", DoorAction_to_string(action));
104105

105-
if (action == DoorAction::OPEN){
106+
if (action == DoorAction::OPEN) {
106107
this->discrete_open_pin_->digital_write(1);
107108
this->scheduler_->set_timeout(this->ratgdo_, "", 500, [=] {
108109
this->discrete_open_pin_->digital_write(0);
109110
});
110111
}
111112

112-
if (action == DoorAction::CLOSE){
113+
if (action == DoorAction::CLOSE) {
113114
this->discrete_close_pin_->digital_write(1);
114115
this->scheduler_->set_timeout(this->ratgdo_, "", 500, [=] {
115116
this->discrete_close_pin_->digital_write(0);

components/ratgdo/dry_contact.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

33
#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial
4-
#include "esphome/core/optional.h"
5-
#include "esphome/core/gpio.h"
64
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
5+
#include "esphome/core/gpio.h"
6+
#include "esphome/core/optional.h"
77

88
#include "callbacks.h"
99
#include "observable.h"
@@ -36,13 +36,15 @@ namespace ratgdo {
3636
void set_close_limit(bool state);
3737
void send_door_state();
3838

39-
void set_discrete_open_pin(InternalGPIOPin* pin) {
39+
void set_discrete_open_pin(InternalGPIOPin* pin)
40+
{
4041
this->discrete_open_pin_ = pin;
4142
this->discrete_open_pin_->setup();
4243
this->discrete_open_pin_->pin_mode(gpio::FLAG_OUTPUT);
4344
}
4445

45-
void set_discrete_close_pin(InternalGPIOPin* pin) {
46+
void set_discrete_close_pin(InternalGPIOPin* pin)
47+
{
4648
this->discrete_close_pin_ = pin;
4749
this->discrete_close_pin_->setup();
4850
this->discrete_close_pin_->pin_mode(gpio::FLAG_OUTPUT);
@@ -68,7 +70,6 @@ namespace ratgdo {
6870
bool last_open_limit_;
6971
bool close_limit_reached_;
7072
bool last_close_limit_;
71-
7273
};
7374

7475
} // namespace secplus1

components/ratgdo/ratgdo.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -690,21 +690,17 @@ namespace ratgdo {
690690
void RATGDOComponent::set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor)
691691
{
692692
dry_contact_open_sensor_ = dry_contact_open_sensor;
693-
dry_contact_open_sensor_->add_on_state_callback([this](bool sensor_value)
694-
{
693+
dry_contact_open_sensor_->add_on_state_callback([this](bool sensor_value) {
695694
this->protocol_->set_open_limit(sensor_value);
696-
}
697-
);
695+
});
698696
}
699697

700698
void RATGDOComponent::set_dry_contact_close_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor)
701699
{
702700
dry_contact_close_sensor_ = dry_contact_close_sensor;
703-
dry_contact_close_sensor_->add_on_state_callback([this](bool sensor_value)
704-
{
701+
dry_contact_close_sensor_->add_on_state_callback([this](bool sensor_value) {
705702
this->protocol_->set_close_limit(sensor_value);
706-
}
707-
);
703+
});
708704
}
709705

710706
} // namespace ratgdo

components/ratgdo/ratgdo.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
#pragma once
1515

16+
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
1617
#include "esphome/core/component.h"
1718
#include "esphome/core/hal.h"
1819
#include "esphome/core/preferences.h"
19-
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
2020

2121
#include "callbacks.h"
2222
#include "macros.h"
@@ -95,8 +95,8 @@ namespace ratgdo {
9595
// dry contact methods
9696
void set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_);
9797
void set_dry_contact_close_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_);
98-
void set_discrete_open_pin(InternalGPIOPin* pin){ this->protocol_->set_discrete_open_pin(pin); }
99-
void set_discrete_close_pin(InternalGPIOPin* pin){ this->protocol_->set_discrete_close_pin(pin); }
98+
void set_discrete_open_pin(InternalGPIOPin* pin) { this->protocol_->set_discrete_open_pin(pin); }
99+
void set_discrete_close_pin(InternalGPIOPin* pin) { this->protocol_->set_discrete_close_pin(pin); }
100100

101101
Result call_protocol(Args args);
102102

components/ratgdo/secplus1.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ namespace ratgdo {
9797
const Traits& traits() const { return this->traits_; }
9898

9999
// methods not used by secplus1
100-
void set_open_limit(bool state){}
101-
void set_close_limit(bool state){}
102-
void set_discrete_open_pin(InternalGPIOPin* pin){}
103-
void set_discrete_close_pin(InternalGPIOPin* pin){}
104-
100+
void set_open_limit(bool state) { }
101+
void set_close_limit(bool state) { }
102+
void set_discrete_open_pin(InternalGPIOPin* pin) { }
103+
void set_discrete_close_pin(InternalGPIOPin* pin) { }
105104

106105
protected:
107106
void wall_panel_emulation(size_t index = 0);

components/ratgdo/secplus2.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ namespace ratgdo {
102102
const Traits& traits() const { return this->traits_; }
103103

104104
// methods not used by secplus2
105-
void set_open_limit(bool state){}
106-
void set_close_limit(bool state){}
107-
void set_discrete_open_pin(InternalGPIOPin* pin){}
108-
void set_discrete_close_pin(InternalGPIOPin* pin){}
105+
void set_open_limit(bool state) { }
106+
void set_close_limit(bool state) { }
107+
void set_discrete_open_pin(InternalGPIOPin* pin) { }
108+
void set_discrete_close_pin(InternalGPIOPin* pin) { }
109109

110110
protected:
111111
void increment_rolling_code_counter(int delta = 1);

static/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,25 @@ <h3>Advanced Users</h3>
289289
const button = document.querySelector("esp-web-install-button");
290290
var protocol = document.querySelector('input[name="protocol"]:checked').value;
291291
var hardware = document.querySelector('input[name="hardware"]:checked').value;
292-
292+
293293
if(protocol === "drycontact"){
294294
document.querySelector("#wiring_diagram").src = "wiring_diagrams/dry_contact_diagram.png";
295295
}else{
296296
document.querySelector("#wiring_diagram").src = "wiring_diagrams/secplus_diagram.png";
297297
}
298-
298+
299299
if(protocol !== "secplusv2" && (hardware === "v2board_esp8266_d1_mini" || hardware === "v2board_esp32_d1_mini")){
300300
alert("ratgdo version 2.0 only works with Security + 2.0");
301301
document.querySelector('input[name="protocol"][value="secplusv2"]').checked = true;
302302
return;
303303
}
304-
304+
305305
if(protocol === "secplusv2"){
306306
protocol = "";
307307
}else{
308308
protocol = `_${protocol}`;
309309
}
310-
310+
311311
button.manifest = `${hardware}${protocol}-manifest.json`;
312312
})
313313
);

static/v25iboard_drycontact.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ wifi:
4848
ap:
4949

5050
logger:
51-
level: DEBUG
51+
level: DEBUG

0 commit comments

Comments
 (0)