ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
5
6#ifdef USE_ESP32
7
8namespace esphome::ble_client {
9
10class BLESensorNotifyTrigger : public Trigger<float>, public BLESensor {
11 public:
12 explicit BLESensorNotifyTrigger(BLESensor *sensor) { sensor_ = sensor; }
13 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
14 esp_ble_gattc_cb_param_t *param) override {
15 switch (event) {
16 case ESP_GATTC_NOTIFY_EVT: {
17 if (param->notify.handle == this->sensor_->handle)
18 this->trigger(this->sensor_->parent()->parse_char_value(param->notify.value, param->notify.value_len));
19 break;
20 }
21 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
22 // confirms notifications are being listened for. While enabling of notifications may still be in
23 // progress by the parent, we assume it will happen.
24 if (param->reg_for_notify.status == ESP_GATT_OK && param->reg_for_notify.handle == this->sensor_->handle)
25 this->node_state = espbt::ClientState::ESTABLISHED;
26 break;
27 }
28 default:
29 break;
30 }
31 }
32
33 protected:
35};
36
37} // namespace esphome::ble_client
38
39#endif
void trigger(const Ts &...x)
Definition automation.h:204
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:13
float parse_char_value(uint8_t *value, uint16_t length)