From 7664489d4a91115861b76b7593d906206d2a85ff Mon Sep 17 00:00:00 2001 From: Ryan Powell Date: Mon, 1 Jul 2024 21:24:53 -0600 Subject: [PATCH] Add selective log messages. --- components/secplus_gdo/cover/gdo_door.cpp | 6 ++++++ components/secplus_gdo/light/gdo_light.h | 8 ++++++++ components/secplus_gdo/lock/gdo_lock.h | 23 ++++++++++------------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/components/secplus_gdo/cover/gdo_door.cpp b/components/secplus_gdo/cover/gdo_door.cpp index a8dcdaa..56d4790 100644 --- a/components/secplus_gdo/cover/gdo_door.cpp +++ b/components/secplus_gdo/cover/gdo_door.cpp @@ -23,6 +23,12 @@ void GDODoor::set_state(gdo_door_state_t state, float position) { } } + if (this->state_ == state && this->position == position) { + return; + } + + ESP_LOGI(TAG, "Door state: %s, position: %.0f%%", gdo_door_state_to_string(state), position); + switch (state) { case GDO_DOOR_STATE_OPEN: this->position = COVER_OPEN; diff --git a/components/secplus_gdo/light/gdo_light.h b/components/secplus_gdo/light/gdo_light.h index 9431610..6cea89b 100644 --- a/components/secplus_gdo/light/gdo_light.h +++ b/components/secplus_gdo/light/gdo_light.h @@ -38,6 +38,12 @@ class GDOLight : public binary::BinaryLightOutput, public Component { } void set_state(gdo_light_state_t state) { + if (state == this->light_state_) { + return; + } + + this->light_state_ = state; + ESP_LOGI(TAG, "Light state: %s", gdo_light_state_to_string(state)); bool is_on = state == GDO_LIGHT_STATE_ON; this->state_->current_values.set_state(is_on); this->state_->remote_values.set_state(is_on); @@ -46,6 +52,8 @@ class GDOLight : public binary::BinaryLightOutput, public Component { private: light::LightState *state_{nullptr}; + gdo_light_state_t light_state_{GDO_LIGHT_STATE_MAX}; + static constexpr auto TAG{"GDOLight"}; }; // GDOLight } // namespace secplus_gdo } // namespace esphome diff --git a/components/secplus_gdo/lock/gdo_lock.h b/components/secplus_gdo/lock/gdo_lock.h index 39d998a..6af958e 100644 --- a/components/secplus_gdo/lock/gdo_lock.h +++ b/components/secplus_gdo/lock/gdo_lock.h @@ -27,20 +27,15 @@ namespace secplus_gdo { class GDOLock : public lock::Lock, public Component { public: void set_state(gdo_lock_state_t state) { - if (state == GDO_LOCK_STATE_LOCKED && this->state == lock::LockState::LOCK_STATE_LOCKED) { - return; - } - if (state == GDO_LOCK_STATE_UNLOCKED && this->state == lock::LockState::LOCK_STATE_UNLOCKED) { + if (state == this->lock_state_) { return; } - auto call = this->make_call(); - if (state == GDO_LOCK_STATE_LOCKED) { - call.set_state(lock::LockState::LOCK_STATE_LOCKED); - } else if (state == GDO_LOCK_STATE_UNLOCKED) { - call.set_state(lock::LockState::LOCK_STATE_UNLOCKED); - } - this->control(call); + this->lock_state_ = state; + ESP_LOGI(TAG, "Lock state: %s", gdo_lock_state_to_string(state)); + this->publish_state(state == GDO_LOCK_STATE_LOCKED ? + lock::LockState::LOCK_STATE_LOCKED : + lock::LockState::LOCK_STATE_UNLOCKED); } void control(const lock::LockCall& call) override { @@ -51,9 +46,11 @@ namespace secplus_gdo { } else if (state == lock::LockState::LOCK_STATE_UNLOCKED) { gdo_unlock(); } - - this->publish_state(state); } + + private: + gdo_lock_state_t lock_state_{GDO_LOCK_STATE_MAX}; + static constexpr const char* TAG = "GDOLock"; }; } // namespace secplus_gdo