ESPHome 2025.5.0
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 {
9namespace ble_client {
10
11class BLESensorNotifyTrigger : public Trigger<float>, public BLESensor {
12 public:
13 explicit BLESensorNotifyTrigger(BLESensor *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_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 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)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7