7 namespace pvvx_mithermometer {
9 static const char *
const TAG =
"pvvx_mithermometer";
12 ESP_LOGCONFIG(TAG,
"PVVX MiThermometer");
14 LOG_SENSOR(
" ",
"Humidity", this->
humidity_);
21 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
24 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str().c_str());
29 if (!res.has_value()) {
38 if (res->temperature.has_value() && this->
temperature_ !=
nullptr)
40 if (res->humidity.has_value() && this->
humidity_ !=
nullptr)
42 if (res->battery_level.has_value() && this->
battery_level_ !=
nullptr)
57 ESP_LOGVV(TAG,
"parse_header(): no service data UUID magic bytes.");
63 static uint8_t last_frame_count = 0;
64 if (last_frame_count ==
raw[13]) {
65 ESP_LOGVV(TAG,
"parse_header(): duplicate data packet received (%hhu).", last_frame_count);
68 last_frame_count =
raw[13];
88 const uint8_t *data = message.data();
89 const int data_length = 15;
91 if (message.size() != data_length) {
92 ESP_LOGVV(TAG,
"parse_message(): payload has wrong size (%d)!", message.size());
97 const int16_t
temperature = int16_t(data[6]) | (int16_t(data[7]) << 8);
101 const int16_t humidity = uint16_t(data[8]) | (uint16_t(data[9]) << 8);
102 result.
humidity = humidity / 1.0e2f;
105 const int16_t battery_voltage = uint16_t(data[10]) | (uint16_t(data[11]) << 8);
116 ESP_LOGVV(TAG,
"report_results(): no results available.");
120 ESP_LOGD(TAG,
"Got PVVX MiThermometer (%s):", address.c_str());
123 ESP_LOGD(TAG,
" Temperature: %.2f °C", *result->temperature);
126 ESP_LOGD(TAG,
" Humidity: %.2f %%", *result->humidity);
129 ESP_LOGD(TAG,
" Battery Level: %.0f %%", *result->battery_level);
131 if (result->battery_voltage.
has_value()) {
132 ESP_LOGD(TAG,
" Battery Voltage: %.3f V", *result->battery_voltage);
bool parse_message_(const std::vector< uint8_t > &message, ParseResult &result)
optional< float > battery_voltage
void dump_config() override
sensor::Sensor * signal_strength_
std::string address_str() const
optional< float > temperature
bool report_results_(const optional< ParseResult > &result, const std::string &address)
sensor::Sensor * battery_voltage_
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * humidity_
const std::vector< ServiceData > & get_service_datas() const
sensor::Sensor * temperature_
uint64_t address_uint64() const
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
optional< float > humidity
bool contains(uint8_t data1, uint8_t data2) const
Implementation of SPI Controller mode.
optional< float > battery_level
optional< ParseResult > parse_header_(const esp32_ble_tracker::ServiceData &service_data)
sensor::Sensor * battery_level_