Apply review: state before fan-out, refusal breadcrumbs, write status log

This commit is contained in:
J. Nick Koston
2026-08-09 03:13:06 -05:00
parent ac7d39a8c1
commit 93f9d4a1ad
3 changed files with 11 additions and 1 deletions
@@ -56,6 +56,8 @@ FILTER_SOURCE_FILES = filter_source_files_from_platform(
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
# Every framework of every bluetooth_connection.GATT_CLIENT_PLATFORMS
# entry except esp32; extend when the registry gains a platform.
"ble_client_gatt.cpp": {PlatformFramework.RP2_ARDUINO},
}
)
@@ -149,6 +149,10 @@ template<typename... Ts> class BLEClientWriteAction final : public Action<Ts...>
void on_write_result(uint16_t handle, int error) override {
if (this->resolved_ && handle == this->char_handle_ && this->num_running_ != 0) {
if (error != 0) {
// Continue the chain (legacy parity) but leave a breadcrumb.
esph_log_w(Automation::TAG, "Write completed with status %d", error);
}
this->ble_client_->run_later([this]() { this->play_next_tuple_(this->var_); });
}
}
@@ -95,6 +95,8 @@ void BLEClient::on_connection_state(bool connected, uint16_t mtu, int error) {
this->state_ = State::DISCOVERING;
if (this->backend_->discover_services() != 0) {
// Synchronous refusal: no discovery completion will follow.
ESP_LOGW(TAG, "[%s] Service discovery refused", this->address_str_);
this->register_failure_();
this->disconnect();
}
return;
@@ -130,12 +132,14 @@ void BLEClient::on_service_discovery_done(int error) {
this->disconnect();
return;
}
// CONNECTED before the fan-out so nodes may consult connected() from
// their own on_connected().
this->state_ = State::CONNECTED;
auto table = this->backend_->get_service_table();
for (auto *node : this->nodes_) {
node->on_connected(table);
}
this->backend_->release_services();
this->state_ = State::CONNECTED;
this->consecutive_failures_ = 0;
this->hold_off_ms_ = 0;
ESP_LOGI(TAG, "[%s] Connected", this->address_str_);