ESPHome  2024.11.1
automation.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #ifdef USE_ESP32
7 
8 namespace esphome {
9 namespace ble_client {
10 
11 class BLETextSensorNotifyTrigger : public Trigger<std::string>, public BLETextSensor {
12  public:
14  void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
15  esp_ble_gattc_cb_param_t *param) override {
16  switch (event) {
17  case ESP_GATTC_SEARCH_CMPL_EVT: {
18  this->sensor_->node_state = espbt::ClientState::ESTABLISHED;
19  break;
20  }
21  case ESP_GATTC_NOTIFY_EVT: {
22  if (param->notify.conn_id != this->sensor_->parent()->get_conn_id() ||
23  param->notify.handle != this->sensor_->handle)
24  break;
25  this->trigger(this->sensor_->parse_data(param->notify.value, param->notify.value_len));
26  }
27  default:
28  break;
29  }
30  }
31 
32  protected:
34 };
35 
36 } // namespace ble_client
37 } // namespace esphome
38 
39 #endif
std::string parse_data(uint8_t *value, uint16_t value_len)
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
BLETextSensorNotifyTrigger(BLETextSensor *sensor)
Definition: automation.h:13
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: automation.h:14
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
esphome::sensor::Sensor * sensor
Definition: statsd.h:38
espbt::ClientState node_state
Definition: ble_client.h:38