ESPHome  2022.9.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:
13  explicit BLETextSensorNotifyTrigger(BLETextSensor *sensor) { sensor_ = sensor; }
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()->conn_id || param->notify.handle != this->sensor_->handle)
23  break;
24  this->trigger(this->sensor_->parse_data(param->notify.value, param->notify.value_len));
25  }
26  default:
27  break;
28  }
29  }
30 
31  protected:
33 };
34 
35 } // namespace ble_client
36 } // namespace esphome
37 
38 #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
Definition: a4988.cpp:4
espbt::ClientState node_state
Definition: ble_client.h:35