2021-07-22 05:21:08 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esphome/core/component.h"
|
|
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
|
|
|
|
|
2021-09-20 11:47:51 +02:00
|
|
|
#ifdef USE_ESP32
|
2021-07-22 05:21:08 +02:00
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace pvvx_mithermometer {
|
|
|
|
|
|
|
|
struct ParseResult {
|
|
|
|
optional<float> temperature;
|
|
|
|
optional<float> humidity;
|
|
|
|
optional<float> battery_level;
|
|
|
|
optional<float> battery_voltage;
|
|
|
|
int raw_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PVVXMiThermometer : public Component, public esp32_ble_tracker::ESPBTDeviceListener {
|
|
|
|
public:
|
|
|
|
void set_address(uint64_t address) { address_ = address; };
|
|
|
|
|
|
|
|
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override;
|
|
|
|
void dump_config() override;
|
|
|
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
|
|
|
void set_temperature(sensor::Sensor *temperature) { temperature_ = temperature; }
|
|
|
|
void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
|
|
|
|
void set_battery_level(sensor::Sensor *battery_level) { battery_level_ = battery_level; }
|
|
|
|
void set_battery_voltage(sensor::Sensor *battery_voltage) { battery_voltage_ = battery_voltage; }
|
2022-08-07 21:30:30 +02:00
|
|
|
void set_signal_strength(sensor::Sensor *signal_strength) { signal_strength_ = signal_strength; }
|
2021-07-22 05:21:08 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
uint64_t address_;
|
|
|
|
sensor::Sensor *temperature_{nullptr};
|
|
|
|
sensor::Sensor *humidity_{nullptr};
|
|
|
|
sensor::Sensor *battery_level_{nullptr};
|
|
|
|
sensor::Sensor *battery_voltage_{nullptr};
|
2022-08-07 21:30:30 +02:00
|
|
|
sensor::Sensor *signal_strength_{nullptr};
|
2021-07-22 05:21:08 +02:00
|
|
|
|
2021-09-24 18:02:28 +02:00
|
|
|
optional<ParseResult> parse_header_(const esp32_ble_tracker::ServiceData &service_data);
|
|
|
|
bool parse_message_(const std::vector<uint8_t> &message, ParseResult &result);
|
|
|
|
bool report_results_(const optional<ParseResult> &result, const std::string &address);
|
2021-07-22 05:21:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace pvvx_mithermometer
|
|
|
|
} // namespace esphome
|
|
|
|
|
|
|
|
#endif
|