ESPHome  2024.5.4
ble_switch.cpp
Go to the documentation of this file.
1 #include "ble_switch.h"
2 #include "esphome/core/log.h"
4 
5 #ifdef USE_ESP32
6 
7 namespace esphome {
8 namespace ble_client {
9 
10 static const char *const TAG = "ble_switch";
11 
13  this->parent_->set_enabled(state);
14  this->publish_state(state);
15 }
16 
17 void BLEClientSwitch::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
18  esp_ble_gattc_cb_param_t *param) {
19  switch (event) {
20  case ESP_GATTC_CLOSE_EVT:
21  this->publish_state(this->parent_->enabled);
22  break;
23  case ESP_GATTC_SEARCH_CMPL_EVT:
24  this->node_state = espbt::ClientState::ESTABLISHED;
25  this->publish_state(this->parent_->enabled);
26  break;
27  default:
28  break;
29  }
30 }
31 
32 void BLEClientSwitch::dump_config() { LOG_SWITCH("", "BLE Client Switch", this); }
33 
34 } // namespace ble_client
35 } // namespace esphome
36 #endif
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
Definition: ble_switch.cpp:17
void set_enabled(bool enabled)
Definition: ble_client.cpp:38
void write_state(bool state) override
Definition: ble_switch.cpp:12
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition: switch.cpp:47
bool state
Definition: fan.h:34
espbt::ClientState node_state
Definition: ble_client.h:38