mirror of
https://github.com/esphome/esphome.git
synced 2025-01-21 21:31:55 +01:00
Update logic for elevaton and atmospheric pressure
This commit is contained in:
parent
8b05c8b172
commit
702a212b13
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user