7 namespace atc_mithermometer {
9 static const char *
const TAG =
"atc_mithermometer";
12 ESP_LOGCONFIG(TAG,
"ATC 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[12]) {
65 ESP_LOGVV(TAG,
"parse_header(): duplicate data packet received (%hhu).", last_frame_count);
68 last_frame_count =
raw[12];
81 const uint8_t *data = message.data();
82 const int data_length = 13;
84 if (message.size() != data_length) {
85 ESP_LOGVV(TAG,
"parse_message(): payload has wrong size (%d)!", message.size());
90 const int16_t
temperature = uint16_t(data[7]) | (uint16_t(data[6]) << 8);
100 const int16_t battery_voltage = uint16_t(data[11]) | (uint16_t(data[10]) << 8);
108 ESP_LOGVV(TAG,
"report_results(): no results available.");
112 ESP_LOGD(TAG,
"Got ATC MiThermometer (%s):", address.c_str());
115 ESP_LOGD(TAG,
" Temperature: %.1f °C", *result->temperature);
118 ESP_LOGD(TAG,
" Humidity: %.0f %%", *result->humidity);
121 ESP_LOGD(TAG,
" Battery Level: %.0f %%", *result->battery_level);
123 if (result->battery_voltage.
has_value()) {
124 ESP_LOGD(TAG,
" Battery Voltage: %.3f V", *result->battery_voltage);
optional< float > battery_voltage
sensor::Sensor * signal_strength_
sensor::Sensor * temperature_
optional< ParseResult > parse_header_(const esp32_ble_tracker::ServiceData &service_data)
std::string address_str() const
bool report_results_(const optional< ParseResult > &result, const std::string &address)
sensor::Sensor * battery_voltage_
optional< float > temperature
sensor::Sensor * battery_level_
bool parse_message_(const std::vector< uint8_t > &message, ParseResult &result)
void publish_state(float state)
Publish a new state to the front-end.
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
const std::vector< ServiceData > & get_service_datas() const
sensor::Sensor * humidity_
uint64_t address_uint64() const
optional< float > humidity
void dump_config() override
bool contains(uint8_t data1, uint8_t data2) const
Implementation of SPI Controller mode.
optional< float > battery_level