mirror of
https://github.com/esphome/esphome.git
synced 2025-04-09 12:20:30 +01:00
Co-authored-by: Ben Buxton <bb@cactii.net> Co-authored-by: Otto Winter <otto@otto-winter.com> Co-authored-by: Stefan Agner <stefan@agner.ch> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: René Klomp <rene@klomp.ws> Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> Co-authored-by: Geoff Davis <geoff@geoffdavis.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: dentra <dentra@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com> Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Barry Loong <loongyh@users.noreply.github.com> Co-authored-by: Sergey V. DUDANOV <sergey.dudanov@gmail.com> Co-authored-by: Balazs Scheidler <bazsi77@gmail.com>
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/ble_client/ble_client.h"
|
|
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
#include "esphome/components/am43/am43_base.h"
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
#include <esp_gattc_api.h>
|
|
|
|
namespace esphome {
|
|
namespace am43 {
|
|
|
|
namespace espbt = esphome::esp32_ble_tracker;
|
|
|
|
class Am43 : public esphome::ble_client::BLEClientNode, public PollingComponent {
|
|
public:
|
|
void setup() override;
|
|
void update() override;
|
|
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
|
|
esp_ble_gattc_cb_param_t *param) override;
|
|
void dump_config() override;
|
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
|
void set_battery(sensor::Sensor *battery) { battery_ = battery; }
|
|
void set_illuminance(sensor::Sensor *illuminance) { illuminance_ = illuminance; }
|
|
|
|
protected:
|
|
uint16_t char_handle_;
|
|
Am43Encoder *encoder_;
|
|
Am43Decoder *decoder_;
|
|
bool logged_in_;
|
|
sensor::Sensor *battery_{nullptr};
|
|
sensor::Sensor *illuminance_{nullptr};
|
|
uint8_t current_sensor_;
|
|
// The AM43 often gets into a state where it spams loads of battery update
|
|
// notifications. Here we will limit to no more than every 10s.
|
|
uint8_t last_battery_update_;
|
|
};
|
|
|
|
} // namespace am43
|
|
} // namespace esphome
|
|
|
|
#endif
|