diff --git a/components/ratgdo/automation.h b/components/ratgdo/automation.h index 6aef9f7..f0db6d9 100644 --- a/components/ratgdo/automation.h +++ b/components/ratgdo/automation.h @@ -11,8 +11,8 @@ class SyncFailed : public Trigger<> { public: explicit SyncFailed(RATGDOComponent* parent) { - parent->subscribe_sync_failed([this](bool state) { - if (state) + parent->subscribe_sync_failed([this](optional state) { + if (state.value_or(false)) this->trigger(); }); } diff --git a/components/ratgdo/cover/ratgdo_cover.cpp b/components/ratgdo/cover/ratgdo_cover.cpp index e9d8c7a..24ba360 100644 --- a/components/ratgdo/cover/ratgdo_cover.cpp +++ b/components/ratgdo/cover/ratgdo_cover.cpp @@ -26,7 +26,7 @@ void RATGDOCover::setup() void RATGDOCover::on_door_state(DoorState state, float position) { - if (state == DoorState::UNKNOWN) { + if (!*this->parent_->synced || state == DoorState::UNKNOWN) { return; } // ESP_LOGD("ON_DOOR_STATE", "%s %f", LOG_STR_ARG(DoorState_to_string(state)), position); diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index c46a330..d4b7059 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -54,6 +54,15 @@ void RATGDOComponent::setup() // many things happening at startup, use some delay for sync this->set_timeout(SYNC_DELAY, [this] { this->sync(); }); + + this->synced.subscribe([this](bool is_synced) { + if (is_synced) { + this->door_state.notify(); + this->light_state.notify(); + this->lock_state.notify(); + } + }); + ESP_LOGD(TAG, " _____ _____ _____ _____ ____ _____ "); ESP_LOGD(TAG, "| __ | _ |_ _| __| \\| |"); ESP_LOGD(TAG, "| -| | | | | | | | | | |"); diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 0af31b3..fde140b 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -78,7 +78,7 @@ public: OnceCallbacks on_door_state_; single_observable synced { false }; - single_observable sync_failed { false }; + single_observable> sync_failed { nullopt }; void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; } void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; } diff --git a/components/ratgdo/secplus2.cpp b/components/ratgdo/secplus2.cpp index fdf0320..a4b9849 100644 --- a/components/ratgdo/secplus2.cpp +++ b/components/ratgdo/secplus2.cpp @@ -163,7 +163,6 @@ namespace secplus2 { { ESP_LOGD(TAG, "Starting sync..."); this->ratgdo_->synced = false; - this->ratgdo_->sync_failed = false; this->scheduler_->cancel_timeout(this->ratgdo_, TIMEOUT_SYNC); this->sync_helper(millis(), 500, 0); } diff --git a/garage-gate.yaml b/garage-gate.yaml index 9a3aac5..59f6e50 100644 --- a/garage-gate.yaml +++ b/garage-gate.yaml @@ -49,7 +49,7 @@ time: binary_sensor: - platform: template name: "Sync failed" - lambda: 'return !*id(garage_gate).synced;' + lambda: 'return *id(garage_gate).sync_failed;' device_class: problem entity_category: diagnostic