7 namespace mopeka_pro_check {
9 static const char *
const TAG =
"mopeka_pro_check";
10 static const uint8_t MANUFACTURER_DATA_LENGTH = 10;
11 static const uint16_t MANUFACTURER_ID = 0x0059;
12 static const double MOPEKA_LPG_COEF[] = {0.573045, -0.002822, -0.00000535};
15 ESP_LOGCONFIG(TAG,
"Mopeka Pro Check");
16 LOG_SENSOR(
" ",
"Level", this->
level_);
19 LOG_SENSOR(
" ",
"Reading Distance", this->
distance_);
34 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str().c_str());
38 if (manu_datas.size() != 1) {
39 ESP_LOGE(TAG,
"Unexpected manu_datas size (%d)", manu_datas.size());
43 const auto &manu_data = manu_datas[0];
45 ESP_LOGVV(TAG,
"Manufacturer data:");
46 for (
const uint8_t byte : manu_data.data) {
47 ESP_LOGVV(TAG,
"0x%02x", byte);
50 if (manu_data.data.size() != MANUFACTURER_DATA_LENGTH) {
51 ESP_LOGE(TAG,
"Unexpected manu_data size (%d)", manu_data.data.size());
61 ESP_LOGE(TAG,
"Unsupported Sensor Type (0x%X)", manu_data.data[0]);
80 ESP_LOGW(TAG,
"Read Quality too low to report distance or level");
94 ESP_LOGD(TAG,
"Distance Sensor: Quality (0x%X) Distance (%" PRId32
"mm)", quality_value, distance_value);
105 if (this->
level_ !=
nullptr) {
106 uint8_t tank_level = 0;
107 if (distance_value >= this->
full_mm_) {
109 }
else if (distance_value > this->
empty_mm_) {
127 float v = (float) ((message[1] & 0x7F) / 32.0f);
129 float percent = (v - 2.2f) / 0.65f * 100.0f;
130 if (percent < 0.0f) {
133 if (percent > 100.0f) {
136 return (uint8_t) percent;
140 uint16_t
raw = (message[4] * 256) + message[3];
141 double raw_level = raw & 0x3FFF;
142 double raw_t = (message[2] & 0x7F);
144 return (uint32_t) (raw_level *
145 (MOPEKA_LPG_COEF[0] + MOPEKA_LPG_COEF[1] * raw_t + MOPEKA_LPG_COEF[2] * raw_t * raw_t));
void dump_config() override
sensor::Sensor * temperature_
SensorReadQuality parse_read_quality_(const std::vector< uint8_t > &message)
uint32_t parse_distance_(const std::vector< uint8_t > &message)
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
Main parse function that gets called for all ble advertisements.
std::string address_str() const
uint32_t ignored_read_count_
const std::vector< ServiceData > & get_manufacturer_datas() const
uint8_t parse_battery_level_(const std::vector< uint8_t > &message)
sensor::Sensor * read_quality_
SensorReadQuality min_signal_quality_
sensor::Sensor * distance_
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * battery_level_
uint8_t parse_temperature_(const std::vector< uint8_t > &message)
uint64_t address_uint64() const
Implementation of SPI Controller mode.
sensor::Sensor * ignored_reads_