Skip to content

Commit 8361045

Browse files
authored
Merge pull request #10 from GelidusResearch/vl53lxx
Add VL53L1x ToF Add-on Sensor Support
2 parents dc00f29 + c8b1164 commit 8361045

20 files changed

+660
-207
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Secplus GDO is an ESPHome component for controlling Security+ and Security+ 2.0
44
made by Chamberlain Group, including garage door openers sold since 1997 under the Chamberlain,
55
LiftMaster, Craftsman and Merlin brands.
66

7-
## Adapted from [RATGDO](https://github.com/ratgdo) and [Secplus GDO](https://github.com/konnected-io)
7+
## Adapted from [RATGDO](https://github.com/ratgdo) and [Secplus GDO](https://github.com/konnected-io)
88

99

1010

components/secplus_gdo/__init__.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import voluptuous as vol
2424
from esphome import pins
2525
from esphome.const import CONF_ID
26+
from esphome import core
2627

2728
DEPENDENCIES = ["preferences"]
2829
MULTI_CONF = True
@@ -37,6 +38,8 @@
3738
CONF_INPUT_OBST = "input_obst_pin"
3839
CONF_RF_OUTPUT_PIN = "rf_tx_pin"
3940
CONF_RF_INPUT_PIN = "rf_rx_pin"
41+
CONF_TOF_SDA_PIN = "tof_sda_pin"
42+
CONF_TOF_SCL_PIN = "tof_scl_pin"
4043
CONF_SECPLUS_GDO_ID = "secplus_gdo_id"
4144

4245
CONFIG_SCHEMA = cv.Schema(
@@ -46,6 +49,8 @@
4649
cv.Required(CONF_INPUT_GDO): pins.gpio_input_pin_schema,
4750
cv.Optional(CONF_RF_OUTPUT_PIN): pins.gpio_output_pin_schema,
4851
cv.Optional(CONF_RF_INPUT_PIN): pins.gpio_input_pin_schema,
52+
cv.Optional(CONF_TOF_SDA_PIN): pins.gpio_input_pin_schema,
53+
cv.Optional(CONF_TOF_SCL_PIN): pins.gpio_input_pin_schema,
4954
cv.Optional(CONF_INPUT_OBST): cv.Any(cv.none, pins.gpio_input_pin_schema),
5055
}
5156
).extend(cv.COMPONENT_SCHEMA)
@@ -65,8 +70,23 @@ async def to_code(config):
6570
cg.add_define("GDO_RF_TX_PIN", config[CONF_RF_OUTPUT_PIN]["number"])
6671
if CONF_RF_INPUT_PIN in config and config[CONF_RF_INPUT_PIN]:
6772
cg.add_define("GDO_RF_RX_PIN", config[CONF_RF_INPUT_PIN]["number"])
73+
if CONF_TOF_SDA_PIN in config and config[CONF_TOF_SDA_PIN]:
74+
cg.add_define("GDO_TOF_SDA_PIN", config[CONF_TOF_SDA_PIN]["number"])
75+
cg.add_build_flag("-DTOF_SENSOR")
76+
if CONF_TOF_SCL_PIN in config and config[CONF_TOF_SCL_PIN]:
77+
cg.add_define("GDO_TOF_SCL_PIN", config[CONF_TOF_SCL_PIN]["number"])
6878
if CONF_INPUT_OBST in config and config[CONF_INPUT_OBST]:
6979
cg.add_define("GDO_OBST_INPUT_PIN", config[CONF_INPUT_OBST]["number"])
7080
cg.add_define("GDO_OBST_FROM_STATE", False)
7181
else:
72-
cg.add_define("GDO_OBST_FROM_STATE", True)
82+
cg.add_define("GDO_OBST_FROM_STATE", True)
83+
cg.add_library(
84+
name="VL53L1",
85+
repository="https://github.com/gelidusresearch/VL53L1_ESPIDF.git",
86+
version="v1.0.0",
87+
)
88+
cg.add_library(
89+
name="GDOLIB",
90+
repository="https://github.com/gelidusresearch/gdolib.git",
91+
version="v1.1.5",
92+
)

components/secplus_gdo/binary_sensor/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from esphome.const import CONF_ID
2424

2525
from .. import SECPLUS_GDO_CONFIG_SCHEMA, secplus_gdo_ns, CONF_SECPLUS_GDO_ID
26+
from .. import CONF_TOF_SDA_PIN
2627

2728
DEPENDENCIES = ["secplus_gdo"]
2829

@@ -37,6 +38,9 @@
3738
"motor": "register_motor",
3839
"button": "register_button",
3940
"sync": "register_sync",
41+
"vehicle_parked": "register_vehicle_parked",
42+
"vehicle_arriving": "register_vehicle_arriving",
43+
"vehicle_leaving": "register_vehicle_leaving",
4044
}
4145

4246

components/secplus_gdo/cover/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def to_code(config):
6464
if CONF_PRE_CLOSE_WARNING_DURATION in config:
6565
cg.add(
6666
var.set_pre_close_warning_duration(config[CONF_PRE_CLOSE_WARNING_DURATION])
67-
)
67+
)
6868
for conf in config.get(CONF_PRE_CLOSE_WARNING_START, []):
6969
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
7070
await automation.build_automation(trigger, [], conf)

components/secplus_gdo/cover/gdo_door.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void GDODoor::do_action_after_warning(const cover::CoverCall &call) {
8181
}
8282

8383

84-
this->set_timeout("pre_close", this->pre_close_duration_, [=]() {
84+
this->set_timeout("pre_close", this->pre_close_duration_, [this, call]() {
8585
this->pre_close_active_ = false;
8686
if (this->pre_close_end_trigger) {
8787
this->pre_close_end_trigger->trigger();

components/secplus_gdo/cover/gdo_door.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "automation.h"
2121
#include "esphome/components/cover/cover.h"
2222
#include "esphome/core/component.h"
23-
#include "gdo.h"
23+
#include "include/gdo.h"
2424

2525
namespace esphome {
2626
namespace secplus_gdo {

components/secplus_gdo/light/gdo_light.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "esphome/components/light/light_output.h"
2222
#include "esphome/core/component.h"
23-
#include "gdo.h"
23+
#include "include/gdo.h"
2424

2525

2626
namespace esphome {

components/secplus_gdo/lock/gdo_lock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "esphome/components/lock/lock.h"
2121
#include "esphome/core/component.h"
22-
#include "gdo.h"
22+
#include "include/gdo.h"
2323

2424
namespace esphome {
2525
namespace secplus_gdo {

components/secplus_gdo/number/__init__.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
from esphome.const import CONF_ID
2424

2525
from .. import SECPLUS_GDO_CONFIG_SCHEMA, secplus_gdo_ns, CONF_SECPLUS_GDO_ID
26+
from .. import CONF_TOF_SDA_PIN
2627

2728
DEPENDENCIES = ["secplus_gdo"]
2829

2930
GDONumber = secplus_gdo_ns.class_("GDONumber", number.Number, cg.Component)
30-
3131
CONF_TYPE = "type"
3232
TYPES = {
3333
"open_duration": "register_open_duration",
@@ -36,6 +36,7 @@
3636
"rolling_code": "register_rolling_code",
3737
"min_command_interval": "register_min_command_interval",
3838
"time_to_close": "register_time_to_close",
39+
"vehicle_parked_threshold": "register_vehicle_parked_threshold",
3940
}
4041

4142
CONFIG_SCHEMA = (
@@ -45,28 +46,34 @@
4546
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
4647
cv.Optional('min_command_interval', default=50): cv.uint32_t,
4748
cv.Optional('time_to_close', default=300): cv.uint16_t,
49+
cv.Optional('vehicle_parked_threshold', default=100): cv.uint16_t,
4850
}
4951
)
5052
.extend(SECPLUS_GDO_CONFIG_SCHEMA)
5153
)
5254

5355

56+
57+
5458
async def to_code(config):
5559
var = cg.new_Pvariable(config[CONF_ID])
56-
if "duration" in str(config[CONF_TYPE]):
60+
if config[CONF_TYPE] == "duration":
5761
await number.register_number(var, config, min_value=0x0, max_value=0xffff, step=1)
58-
elif "client_id" in str(config[CONF_TYPE]):
62+
elif config[CONF_TYPE] == "client_id":
5963
await number.register_number(var, config, min_value=0x666, max_value=0x7ff666, step=1)
60-
elif "min_command_interval" in str(config[CONF_TYPE]):
64+
elif config[CONF_TYPE] == "min_command_interval":
6165
await number.register_number(var, config, min_value=50, max_value=1000, step=50)
62-
elif "time_to_close" in str(config[CONF_TYPE]):
66+
elif config[CONF_TYPE] == "time_to_close":
6367
await number.register_number(var, config, min_value=0, max_value=65535, step=60)
68+
elif config[CONF_TYPE] == "vehicle_parked_threshold":
69+
await number.register_number(var, config, min_value=10, max_value=400, step=1)
6470
else:
6571
await number.register_number(var, config, min_value=0x0, max_value=0xffffffff, step=1)
72+
6673
await cg.register_component(var, config)
6774
parent = await cg.get_variable(config[CONF_SECPLUS_GDO_ID])
6875
fcall = str(parent) + "->" + str(TYPES[config[CONF_TYPE]])
6976
text = fcall + "(" + str(var) + ")"
7077
cg.add((cg.RawExpression(text)))
7178
text = "gdo_set_" + str(config[CONF_TYPE])
72-
cg.add(var.set_control_function(cg.RawExpression(text)))
79+
cg.add(var.set_control_function(cg.RawExpression(text)))

components/secplus_gdo/number/gdo_number.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@
1717

1818
#pragma once
1919

20+
#include "esphome/components/number/number.h"
2021
#include "esphome/core/component.h"
2122
#include "esphome/core/preferences.h"
22-
#include "esphome/components/number/number.h"
23+
2324

2425
namespace esphome {
2526
namespace secplus_gdo {
2627

2728
class GDONumber : public number::Number, public Component {
28-
public:
29+
public:
2930
void dump_config() override {}
31+
3032
void setup() override {
3133
float value;
32-
this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash());
34+
this->pref_ =
35+
global_preferences->make_preference<float>(this->get_object_id_hash());
3336
if (!this->pref_.load(&value)) {
3437
value = 0;
3538
}
@@ -58,11 +61,11 @@ class GDONumber : public number::Number, public Component {
5861
}
5962
}
6063

61-
void set_control_function(std::function<int(float)> f) { f_control = f; }
64+
void set_control_function(std::function<void(float)> f) { f_control = f; }
6265

6366
protected:
6467
ESPPreferenceObject pref_;
65-
std::function<int(float)> f_control{nullptr};
68+
std::function<void(float)> f_control{nullptr};
6669
};
67-
} // namespace secplus_gdo
68-
} // namespace esphome
70+
} // namespace secplus_gdo
71+
} // namespace esphome

0 commit comments

Comments
 (0)