Skip to content

Commit

Permalink
Refactor event notification handling in NukiLockComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
AzonInc committed Feb 6, 2025
1 parent 00c413d commit c63cb7c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions components/nuki_lock/nuki_lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,20 +1391,25 @@ void NukiLockComponent::dump_config() {
}

void NukiLockComponent::notify(Nuki::EventType event_type) {
ESP_LOGI(TAG, "Event notified %d", event_type);

if(event_type == Nuki::EventType::KeyTurnerStatusReset) {
// IDK
} else if (event_type == Nuki::EventType::ERROR_BAD_PIN) {
// Invalid Pin
} else if(event_type == Nuki::EventType::KeyTurnerStatusUpdated) {
// Request status update
this->status_update_ = true;

// Ignore bad pin error to prevent loop
if (event_type == Nuki::EventType::ERROR_BAD_PIN) {
return;
}

this->status_update_ = true;

// Request event logs after every notify
if (this->send_events_) {
this->event_log_update_ = true;
// Request event logs
if (this->send_events_) {
this->event_log_update_ = true;
}
} else if(event_type == Nuki::EventType::BLE_ERROR_ON_DISCONNECT) {
ESP_LOGI(TAG, "Failed to disconnect from Nuki. Restarting ESP...");
delay(100); // NOLINT
App.safe_reboot();
}

ESP_LOGI(TAG, "event notified %d", event_type);
}

void NukiLockComponent::unpair() {
Expand Down

0 comments on commit c63cb7c

Please sign in to comment.