From 0970e88b8e8f02360108857a05b5e771499f5455 Mon Sep 17 00:00:00 2001 From: h2zero Date: Sun, 7 Jul 2024 09:48:20 -0600 Subject: [PATCH] Add synced state binary sensor. --- components/secplus_gdo/binary_sensor/__init__.py | 1 + components/secplus_gdo/secplus_gdo.cpp | 4 ++++ components/secplus_gdo/secplus_gdo.h | 3 +++ garage-door-GDOv2-Q.yaml | 1 + packages/secplus-gdo.yaml | 6 ++++++ 5 files changed, 15 insertions(+) diff --git a/components/secplus_gdo/binary_sensor/__init__.py b/components/secplus_gdo/binary_sensor/__init__.py index 19bac01..a285b92 100644 --- a/components/secplus_gdo/binary_sensor/__init__.py +++ b/components/secplus_gdo/binary_sensor/__init__.py @@ -36,6 +36,7 @@ "obstruction": "register_obstruction", "motor": "register_motor", "button": "register_button", + "sync": "register_sync", } diff --git a/components/secplus_gdo/secplus_gdo.cpp b/components/secplus_gdo/secplus_gdo.cpp index 0d6656f..a11ad93 100644 --- a/components/secplus_gdo/secplus_gdo.cpp +++ b/components/secplus_gdo/secplus_gdo.cpp @@ -164,6 +164,10 @@ namespace secplus_gdo { if (this->lock_) { this->lock_->set_sync_state(synced); } + + if (this->f_sync) { + this->f_sync(synced); + } } } // namespace secplus_gdo diff --git a/components/secplus_gdo/secplus_gdo.h b/components/secplus_gdo/secplus_gdo.h index a3cd573..e976b05 100644 --- a/components/secplus_gdo/secplus_gdo.h +++ b/components/secplus_gdo/secplus_gdo.h @@ -59,6 +59,8 @@ namespace secplus_gdo { void register_motor(std::function f) { f_motor = f; } void set_motor_state(gdo_motor_state_t state) { if (f_motor) { f_motor(state == GDO_MOTOR_STATE_ON); } } + void register_sync(std::function f) { f_sync = f; } + void register_openings(std::function f) { f_openings = f; } void set_openings(uint16_t openings) { if (f_openings) { f_openings(openings); } } @@ -99,6 +101,7 @@ namespace secplus_gdo { std::function f_obstruction{nullptr}; std::function f_button{nullptr}; std::function f_motor{nullptr}; + std::function f_sync{nullptr}; GDODoor* door_{nullptr}; GDOLight* light_{nullptr}; GDOLock* lock_{nullptr}; diff --git a/garage-door-GDOv2-Q.yaml b/garage-door-GDOv2-Q.yaml index 7bd512a..36851d9 100644 --- a/garage-door-GDOv2-Q.yaml +++ b/garage-door-GDOv2-Q.yaml @@ -66,6 +66,7 @@ substitutions: garage_obstruction_name: Obstruction garage_motor_name: Motor garage_button_name: Wall Button + garage_sync_name: Synced #### diff --git a/packages/secplus-gdo.yaml b/packages/secplus-gdo.yaml index a9744ce..c70be3f 100644 --- a/packages/secplus-gdo.yaml +++ b/packages/secplus-gdo.yaml @@ -66,6 +66,12 @@ binary_sensor: id: gdo_button secplus_gdo_id: gdo_blaq type: button + - platform: secplus_gdo + name: $garage_sync_name + id: gdo_synced + secplus_gdo_id: gdo_blaq + type: sync + device_class: connectivity switch: - platform: secplus_gdo