Skip to content

Commit

Permalink
Prevent commands from being sent until synced.
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Jul 5, 2024
1 parent 7347b2e commit e8ba6b1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/secplus_gdo/cover/gdo_door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ void GDODoor::do_action(const cover::CoverCall& call) {
}

void GDODoor::control(const cover::CoverCall& call) {
if (!this->synced_) {
this->publish_state(false);
return;
}

if (call.get_stop()) {
ESP_LOGD(TAG, "Stop command received");
if (this->pre_close_active_) {
Expand Down
5 changes: 5 additions & 0 deletions components/secplus_gdo/cover/gdo_door.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ using namespace esphome::cover;
this->pre_close_end_trigger = trigger;
}

void set_sync_state(bool synced) {
this->synced_ = synced;
}

void do_action(const cover::CoverCall& call);
void do_action_after_warning(const cover::CoverCall& call);
void set_pre_close_warning_duration(uint32_t ms) { this->pre_close_duration_ = ms; }
Expand All @@ -61,6 +65,7 @@ using namespace esphome::cover;
optional<float> target_position_{0};
CoverOperation prev_operation{COVER_OPERATION_IDLE};
gdo_door_state_t state_{GDO_DOOR_STATE_MAX};
bool synced_{false};
};
} // namespace secplus_gdo
} // namespace esphome
9 changes: 9 additions & 0 deletions components/secplus_gdo/light/gdo_light.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class GDOLight : public binary::BinaryLightOutput, public Component {
void setup_state(light::LightState *state) override { this->state_ = state; }

void write_state(light::LightState *state) override {
if (!this->synced_) {
return;
}

bool binary;
state->current_values_as_binary(&binary);
if (binary)
Expand All @@ -50,10 +54,15 @@ class GDOLight : public binary::BinaryLightOutput, public Component {
this->state_->publish_state();
}

void set_sync_state(bool synced) {
this->synced_ = synced;
}

private:
light::LightState *state_{nullptr};
gdo_light_state_t light_state_{GDO_LIGHT_STATE_MAX};
static constexpr auto TAG{"GDOLight"};
bool synced_{false};
}; // GDOLight
} // namespace secplus_gdo
} // namespace esphome
9 changes: 9 additions & 0 deletions components/secplus_gdo/lock/gdo_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace secplus_gdo {
}

void control(const lock::LockCall& call) override {
if (!this->synced_) {
return;
}

auto state = *call.get_state();

if (state == lock::LockState::LOCK_STATE_LOCKED) {
Expand All @@ -48,8 +52,13 @@ namespace secplus_gdo {
}
}

void set_sync_state(bool synced) {
this->synced_ = synced;
}

private:
gdo_lock_state_t lock_state_{GDO_LOCK_STATE_MAX};
bool synced_{false};
static constexpr const char* TAG = "GDOLock";
};

Expand Down
15 changes: 15 additions & 0 deletions components/secplus_gdo/secplus_gdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace secplus_gdo {
gdo->set_protocol_state(status->protocol);
}

gdo->set_sync_state(status->synced);
break;
case GDO_CB_EVENT_LIGHT:
gdo->set_light_state(status->light);
Expand Down Expand Up @@ -148,5 +149,19 @@ namespace secplus_gdo {
ESP_LOGCONFIG(TAG, "Setting up secplus GDO ...");
}

void GDOComponent::set_sync_state(bool synced) {
if (this->door_) {
this->door_->set_sync_state(synced);
}

if (this->light_) {
this->light_->set_sync_state(synced);
}

if (this->lock_) {
this->lock_->set_sync_state(synced);
}
}

} // namespace secplus_gdo
} // namespace esphome
2 changes: 2 additions & 0 deletions components/secplus_gdo/secplus_gdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ namespace secplus_gdo {

void register_toggle_only(GDOSwitch *sw) { this->toggle_only_switch_ = sw; }

void set_sync_state(bool synced);

protected:
gdo_status_t status_{};
std::function<void(uint16_t)> f_openings{nullptr};
Expand Down

0 comments on commit e8ba6b1

Please sign in to comment.