ESPHome  2024.12.2
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 BLESensorNotifyTrigger : public Trigger<float>, public BLESensor {
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_NOTIFY_EVT: {
18  if (param->notify.handle == this->sensor_->handle)
19  this->trigger(this->sensor_->parent()->parse_char_value(param->notify.value, param->notify.value_len));
20  break;
21  }
22  case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
23  // confirms notifications are being listened for. While enabling of notifications may still be in
24  // progress by the parent, we assume it will happen.
25  if (param->reg_for_notify.status == ESP_GATT_OK && param->reg_for_notify.handle == this->sensor_->handle)
26  this->node_state = espbt::ClientState::ESTABLISHED;
27  break;
28  }
29  default:
30  break;
31  }
32  }
33 
34  protected:
36 };
37 
38 } // namespace ble_client
39 } // namespace esphome
40 
41 #endif
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
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
float parse_char_value(uint8_t *value, uint16_t length)
esphome::sensor::Sensor * sensor
Definition: statsd.h:38
espbt::ClientState node_state
Definition: ble_client.h:38