ESPHome 2025.5.0
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 {
8namespace ble_client {
9
10static const char *const TAG = "ble_switch";
11
13 this->parent_->set_enabled(state);
14 this->publish_state(state);
15}
16
17void 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
32void BLEClientSwitch::dump_config() { LOG_SWITCH("", "BLE Client Switch", this); }
33
34} // namespace ble_client
35} // namespace esphome
36#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:47
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7