mirror of
https://github.com/esphome/esphome.git
synced 2025-11-18 07:45:56 +00:00
tidy
This commit is contained in:
@@ -124,9 +124,7 @@ void BH1750Sensor::loop() {
|
|||||||
case READING_COARSE_RESULT: {
|
case READING_COARSE_RESULT: {
|
||||||
float lx;
|
float lx;
|
||||||
if (!this->read_measurement_(lx)) {
|
if (!this->read_measurement_(lx)) {
|
||||||
this->status_set_warning();
|
this->fail_and_reset_();
|
||||||
this->publish_state(NAN);
|
|
||||||
this->state_ = IDLE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,9 +132,7 @@ void BH1750Sensor::loop() {
|
|||||||
|
|
||||||
// Start fine measurement with optimal settings
|
// Start fine measurement with optimal settings
|
||||||
if (!this->start_measurement_(this->fine_mode_, this->fine_mtreg_, now)) {
|
if (!this->start_measurement_(this->fine_mode_, this->fine_mtreg_, now)) {
|
||||||
this->status_set_warning();
|
this->fail_and_reset_();
|
||||||
this->publish_state(NAN);
|
|
||||||
this->state_ = IDLE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,9 +149,7 @@ void BH1750Sensor::loop() {
|
|||||||
case READING_FINE_RESULT: {
|
case READING_FINE_RESULT: {
|
||||||
float lx;
|
float lx;
|
||||||
if (!this->read_measurement_(lx)) {
|
if (!this->read_measurement_(lx)) {
|
||||||
this->status_set_warning();
|
this->fail_and_reset_();
|
||||||
this->publish_state(NAN);
|
|
||||||
this->state_ = IDLE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,6 +258,12 @@ void BH1750Sensor::process_coarse_result_(float lx) {
|
|||||||
ESP_LOGV(TAG, "L result: %.1f -> Calculated mode=%d, mtreg=%d", lx, (int) this->fine_mode_, this->fine_mtreg_);
|
ESP_LOGV(TAG, "L result: %.1f -> Calculated mode=%d, mtreg=%d", lx, (int) this->fine_mode_, this->fine_mtreg_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BH1750Sensor::fail_and_reset_() {
|
||||||
|
this->status_set_warning();
|
||||||
|
this->publish_state(NAN);
|
||||||
|
this->state_ = IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
float BH1750Sensor::get_setup_priority() const { return setup_priority::DATA; }
|
float BH1750Sensor::get_setup_priority() const { return setup_priority::DATA; }
|
||||||
|
|
||||||
} // namespace esphome::bh1750
|
} // namespace esphome::bh1750
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class BH1750Sensor : public sensor::Sensor, public PollingComponent, public i2c:
|
|||||||
bool start_measurement_(BH1750Mode mode, uint8_t mtreg, uint32_t now);
|
bool start_measurement_(BH1750Mode mode, uint8_t mtreg, uint32_t now);
|
||||||
bool read_measurement_(float &lx_out);
|
bool read_measurement_(float &lx_out);
|
||||||
void process_coarse_result_(float lx);
|
void process_coarse_result_(float lx);
|
||||||
|
void fail_and_reset_();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace esphome::bh1750
|
} // namespace esphome::bh1750
|
||||||
|
|||||||
Reference in New Issue
Block a user