Update logic for elevaton and atmospheric pressure

This commit is contained in:
thetestspecimen 2024-10-08 01:03:17 +03:00
parent 8b05c8b172
commit 702a212b13
No known key found for this signature in database
GPG Key ID: C88001C355A25170

View File

@ -153,14 +153,14 @@ void Sen0501Component::read_luminous_intensity_() {
}
void Sen0501Component::read_atmospheric_pressure_() {
if (this->atmospheric_pressure_ == nullptr)
if (this->atmospheric_pressure_ == nullptr && this->elevation_ == nullptr)
return;
uint8_t buffer[2];
this->read_bytes(REG_ATMOSPHERIC_PRESSURE, buffer, 2);
uint16_t atmosphere = encode_uint16(buffer[0], buffer[1]);
if (this->atmospheric_pressure_ != nullptr)
this->atmospheric_pressure_->publish_state(atmosphere);
if (this->elevation_ == nullptr)
return;
if (this->elevation_ != nullptr)
float elevation = 44330 * (1.0 - pow(atmosphere / 1015.0f, 0.1903));
this->elevation_->publish_state(elevation);
}