ESPHome 2025.12.1
Loading...
Searching...
No Matches
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
7namespace esphome::ble_client {
8
9static const char *const TAG = "ble_switch";
10
12 this->parent_->set_enabled(state);
13 this->publish_state(state);
14}
15
16void BLEClientSwitch::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
17 esp_ble_gattc_cb_param_t *param) {
18 switch (event) {
19 case ESP_GATTC_CLOSE_EVT:
20 this->publish_state(this->parent_->enabled);
21 break;
22 case ESP_GATTC_SEARCH_CMPL_EVT:
23 this->node_state = espbt::ClientState::ESTABLISHED;
24 this->publish_state(this->parent_->enabled);
25 break;
26 default:
27 break;
28 }
29}
30
31void BLEClientSwitch::dump_config() { LOG_SWITCH("", "BLE Client Switch", this); }
32
33} // namespace esphome::ble_client
34#endif
void set_enabled(bool enabled)
void write_state(bool state) override
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:57
bool state
Definition fan.h:0