Skip to content

Commit

Permalink
Add selective log messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Jul 2, 2024
1 parent 22ca041 commit 7664489
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
6 changes: 6 additions & 0 deletions components/secplus_gdo/cover/gdo_door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions components/secplus_gdo/light/gdo_light.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
23 changes: 10 additions & 13 deletions components/secplus_gdo/lock/gdo_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 7664489

Please sign in to comment.