Add support for additional Xiaomi BLE sensors (#1027) (#1027)

This commit is contained in:
Alexander Pohl
2020-05-27 00:33:28 +02:00
committed by GitHub
parent e64246f642
commit 3fba3a5e2e
48 changed files with 1875 additions and 276 deletions
@@ -14,6 +14,46 @@ void XiaomiLYWSD02::dump_config() {
LOG_SENSOR(" ", "Humidity", this->humidity_);
}
bool XiaomiLYWSD02::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
if (device.address_uint64() != this->address_) {
ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
return false;
}
ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", device.address_str().c_str());
bool success = false;
for (auto &service_data : device.get_service_datas()) {
auto res = xiaomi_ble::parse_xiaomi_header(service_data);
if (!res.has_value()) {
continue;
}
if (res->is_duplicate) {
continue;
}
if (res->has_encryption) {
ESP_LOGVV(TAG, "parse_device(): payload decryption is currently not supported on this device.");
continue;
}
if (!(xiaomi_ble::parse_xiaomi_message(service_data.data, *res))) {
continue;
}
if (!(xiaomi_ble::report_xiaomi_results(res, device.address_str()))) {
continue;
}
if (res->temperature.has_value() && this->temperature_ != nullptr)
this->temperature_->publish_state(*res->temperature);
if (res->humidity.has_value() && this->humidity_ != nullptr)
this->humidity_->publish_state(*res->humidity);
success = true;
}
if (!success) {
return false;
}
return true;
}
} // namespace xiaomi_lywsd02
} // namespace esphome