mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 11:44:13 +01:00
153aadadae
* Added ble_scanner component * ble_scanner: time.h changed to ctime * ble_scanner: Test added. * ble_scanner: fixed code formatting. * Removed duplicate binary sensor tests from test2 and test3 to decrease memory requirements. * Removed another duplicate test from test2.yaml and moved stepper test to yaml3.yaml to reduce memory requirements of test2.yaml. * Reverted the last stepper test change * Moved some sensor tests from test2.yaml to test3.yaml to save memory. * Moved ruuvitag back to test2.yaml as it requires component esp32_ble_tracker. * removed apds9960 as it is duplicated Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <ctime>
|
|
#include <string>
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
|
|
#include "esphome/components/text_sensor/text_sensor.h"
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
namespace esphome {
|
|
namespace ble_scanner {
|
|
|
|
class BLEScanner : public text_sensor::TextSensor, public esp32_ble_tracker::ESPBTDeviceListener, public Component {
|
|
public:
|
|
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override {
|
|
this->publish_state("{\"timestamp\":" + to_string(::time(NULL)) +
|
|
","
|
|
"\"address\":\"" +
|
|
device.address_str() +
|
|
"\","
|
|
"\"rssi\":" +
|
|
to_string(device.get_rssi()) +
|
|
","
|
|
"\"name\":\"" +
|
|
device.get_name() + "\"}");
|
|
|
|
return true;
|
|
}
|
|
void dump_config() override;
|
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
|
};
|
|
|
|
} // namespace ble_scanner
|
|
} // namespace esphome
|
|
|
|
#endif
|