Skip to content

Commit

Permalink
BLE Host: Added support for ESPHome 2023.11.x and older
Browse files Browse the repository at this point in the history
  • Loading branch information
myhomeiot committed Nov 23, 2023
1 parent 2a21369 commit d23c761
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion components/myhomeiot_ble_host/myhomeiot_ble_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace myhomeiot_ble_host {

static const char *const TAG = "myhomeiot_ble_host";

void MyHomeIOT_BLEHost::setup() {
void MyHomeIOT_BLEHost::init() {
auto status = esp_ble_gattc_app_register(this->app_id);
if (status) {
ESP_LOGE(TAG, "app_register failed, app_id (%d) status (%d)", this->app_id, status);
Expand All @@ -18,11 +18,26 @@ void MyHomeIOT_BLEHost::setup() {
this->set_state(MYHOMEIOT_IDLE);
}

void MyHomeIOT_BLEHost::setup() {
#if ESPHOME_VERSION_CODE < VERSION_CODE(2023, 11, 0)
init();
#endif
}

void MyHomeIOT_BLEHost::dump_config() {
ESP_LOGCONFIG(TAG, "MyHomeIOT BLE Host");
}

void MyHomeIOT_BLEHost::loop() {
#if ESPHOME_VERSION_CODE >= VERSION_CODE(2023, 11, 0)
if (!esp32_ble::global_ble->is_active()) {
this->set_state(esp32_ble_tracker::ClientState::INIT);
return;
}
if (this->state_ == esp32_ble_tracker::ClientState::INIT)
init();
#endif

if (current)
{
current->loop();
Expand Down
1 change: 1 addition & 0 deletions components/myhomeiot_ble_host/myhomeiot_ble_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MyHomeIOT_BLEHost : public Component, public esp32_ble_tracker::ESPBTClien
protected:
MyHomeIOT_BLEClientNode *current{nullptr};
std::vector<MyHomeIOT_BLEClientNode *> clients_;
void init();
};

} // namespace myhomeiot_ble_host
Expand Down

0 comments on commit d23c761

Please sign in to comment.