mirror of
https://github.com/esphome/esphome.git
synced 2025-04-14 23:00:29 +01:00
40 lines
1007 B
C++
40 lines
1007 B
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
namespace esphome {
|
|
namespace ble_rssi {
|
|
|
|
class BLERSSISensor : public sensor::Sensor, public esp32_ble_tracker::ESPBTDeviceListener, public Component {
|
|
public:
|
|
void set_address(uint64_t address) { address_ = address; }
|
|
void on_scan_end() override {
|
|
if (!this->found_)
|
|
this->publish_state(NAN);
|
|
this->found_ = false;
|
|
}
|
|
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override {
|
|
if (device.address_uint64() == this->address_) {
|
|
this->publish_state(device.get_rssi());
|
|
this->found_ = true;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
void dump_config() override;
|
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
|
|
|
protected:
|
|
bool found_{false};
|
|
uint64_t address_;
|
|
};
|
|
|
|
} // namespace ble_rssi
|
|
} // namespace esphome
|
|
|
|
#endif
|