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_);
32 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str().c_str());
36 if (manu_datas.size() != 1) {
37 ESP_LOGE(TAG,
"Unexpected manu_datas size (%d)", manu_datas.size());
41 const auto &manu_data = manu_datas[0];
43 ESP_LOGVV(TAG,
"Manufacturer data:");
44 for (
const uint8_t byte : manu_data.data) {
45 ESP_LOGVV(TAG,
"0x%02x", byte);
48 if (manu_data.data.size() != MANUFACTURER_DATA_LENGTH) {
49 ESP_LOGE(TAG,
"Unexpected manu_data size (%d)", manu_data.data.size());
59 ESP_LOGE(TAG,
"Unsupported Sensor Type (0x%X)", manu_data.data[0]);
73 ESP_LOGD(TAG,
"Distance Sensor: Quality (0x%X) Distance (%" PRId32
"mm)", quality_value, distance_value);
75 ESP_LOGW(TAG,
"Poor read quality.");
79 ESP_LOGW(TAG,
"Setting distance to 0");
89 if (this->
level_ !=
nullptr) {
90 uint8_t tank_level = 0;
91 if (distance_value >= this->
full_mm_) {
93 }
else if (distance_value > this->
empty_mm_) {
110 float v = (float) ((message[1] & 0x7F) / 32.0f);
112 float percent = (v - 2.2f) / 0.65f * 100.0f;
113 if (percent < 0.0f) {
116 if (percent > 100.0f) {
119 return (uint8_t) percent;
123 uint16_t
raw = (message[4] * 256) + message[3];
124 double raw_level = raw & 0x3FFF;
125 double raw_t = (message[2] & 0x7F);
127 return (uint32_t) (raw_level *
128 (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
const std::vector< ServiceData > & get_manufacturer_datas() const
uint8_t parse_battery_level_(const std::vector< uint8_t > &message)
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.