ESPHome  2022.6.3
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_REG_EVT:
21  this->publish_state(this->parent_->enabled);
22  break;
23  case ESP_GATTC_OPEN_EVT:
24  this->node_state = espbt::ClientState::ESTABLISHED;
25  break;
26  case ESP_GATTC_DISCONNECT_EVT:
28  this->publish_state(this->parent_->enabled);
29  break;
30  default:
31  break;
32  }
33 }
34 
35 void BLEClientSwitch::dump_config() { LOG_SWITCH("", "BLE Client Switch", this); }
36 
37 } // namespace ble_client
38 } // namespace esphome
39 #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:71
void write_state(bool state) override
Definition: ble_switch.cpp:12
Definition: a4988.cpp:4
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition: switch.cpp:31
bool state
Definition: fan.h:34
espbt::ClientState node_state
Definition: ble_client.h:35