mirror of
https://github.com/esphome/esphome.git
synced 2026-10-19 04:32:50 +00:00
[components] Report communication failures with status_comm_result in the remaining components (#21079)
This commit is contained in:
@@ -117,12 +117,9 @@ void ATM90E32Component::loop() {
|
||||
}
|
||||
|
||||
void ATM90E32Component::update() {
|
||||
if (this->read16_(ATM90E32_REGISTER_METEREN) != 1) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read16_(ATM90E32_REGISTER_METEREN) == 1, nullptr))
|
||||
return;
|
||||
}
|
||||
this->set_publish_interval_flag_(true);
|
||||
this->status_clear_warning();
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
this->check_phase_status();
|
||||
|
||||
@@ -284,7 +284,7 @@ uint8_t BME680Component::calc_heater_duration_(uint16_t duration) {
|
||||
}
|
||||
void BME680Component::read_data_() {
|
||||
uint8_t data[15];
|
||||
if (!this->read_bytes(BME680_REGISTER_FIELD0, data, 15)) {
|
||||
if (!this->status_comm_result(this->read_bytes(BME680_REGISTER_FIELD0, data, 15))) {
|
||||
if (this->temperature_sensor_ != nullptr)
|
||||
this->temperature_sensor_->publish_state(NAN);
|
||||
if (this->pressure_sensor_ != nullptr)
|
||||
@@ -294,10 +294,8 @@ void BME680Component::read_data_() {
|
||||
if (this->gas_resistance_sensor_ != nullptr)
|
||||
this->gas_resistance_sensor_->publish_state(NAN);
|
||||
ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
uint32_t raw_temperature = (uint32_t(data[5]) << 12) | (uint32_t(data[6]) << 4) | (uint32_t(data[7]) >> 4);
|
||||
uint32_t raw_pressure = (uint32_t(data[2]) << 12) | (uint32_t(data[3]) << 4) | (uint32_t(data[4]) >> 4);
|
||||
|
||||
@@ -191,11 +191,7 @@ void BME680BSECComponent::loop() {
|
||||
} else {
|
||||
this->status_clear_error();
|
||||
}
|
||||
if (this->bsec_status_ > BSEC_OK || this->bme680_status_ > BME680_OK) {
|
||||
this->status_set_warning();
|
||||
} else {
|
||||
this->status_clear_warning();
|
||||
}
|
||||
this->status_comm_result(this->bsec_status_ <= BSEC_OK && this->bme680_status_ <= BME680_OK, nullptr);
|
||||
|
||||
// Process a single action from the queue. These are primarily sensor state publishes
|
||||
// that in totality take too long to send in a single call.
|
||||
|
||||
@@ -126,11 +126,7 @@ void BME68xBSEC2Component::check_status_() {
|
||||
this->status_clear_error();
|
||||
}
|
||||
const bool has_bme68x_warning = this->bme68x_status_ > BME68X_OK && !is_no_new_data_warning(this->bme68x_status_);
|
||||
if (this->bsec_status_ > BSEC_OK || has_bme68x_warning) {
|
||||
this->status_set_warning();
|
||||
} else {
|
||||
this->status_clear_warning();
|
||||
}
|
||||
this->status_comm_result(this->bsec_status_ <= BSEC_OK && !has_bme68x_warning, nullptr);
|
||||
}
|
||||
|
||||
void BME68xBSEC2Component::loop() {
|
||||
|
||||
@@ -101,15 +101,13 @@ bool CM1106Component::send_command_expect_ack_(const uint8_t *command, size_t co
|
||||
uint8_t response[4] = {0};
|
||||
if (!this->cm1106_write_command_(command, command_len, response, sizeof(response))) {
|
||||
ESP_LOGW(TAG, "Command %02X failed", command[2]);
|
||||
this->status_set_warning();
|
||||
this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
return false;
|
||||
}
|
||||
if (memcmp(response, ack, sizeof(response)) != 0) {
|
||||
if (!this->status_comm_result(memcmp(response, ack, sizeof(response)) == 0)) {
|
||||
ESP_LOGW(TAG, "Unexpected response: %02X %02X %02X %02X", response[0], response[1], response[2], response[3]);
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,10 @@ void CST226Touchscreen::setup() {
|
||||
|
||||
void CST226Touchscreen::update_touches() {
|
||||
uint8_t data[28];
|
||||
if (!this->read_bytes(CST226_REG_STATUS, data, sizeof data)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_bytes(CST226_REG_STATUS, data, sizeof data))) {
|
||||
this->skip_update_ = true;
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
if (data[0] == 0x83 && data[1] == 0x17 && data[5] == 0x80) {
|
||||
this->update_button_state_(true);
|
||||
return;
|
||||
|
||||
@@ -87,12 +87,10 @@ void CST9220Touchscreen::update_touches() {
|
||||
// Only an actual I2C failure should skip the update; a successful read with no
|
||||
// touches is a real "all fingers lifted" state that must flow through so the
|
||||
// base class can generate the release event.
|
||||
if (this->read_register16(REG_TOUCH_DATA, data, sizeof(data)) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_register16(REG_TOUCH_DATA, data, sizeof(data)) == i2c::ERROR_OK)) {
|
||||
this->skip_update_ = true;
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
// Acknowledge the report so the controller can prepare the next one.
|
||||
uint8_t ack = TOUCH_ACK;
|
||||
|
||||
@@ -255,11 +255,7 @@ void DFRobotSEN0465Component::handle_data_(const uint8_t *frame) {
|
||||
|
||||
if (this->concentration_sensor_ != nullptr)
|
||||
this->concentration_sensor_->publish_state(concentration);
|
||||
if (std::isnan(concentration) || std::isnan(temperature) || this->setup_incomplete_) {
|
||||
this->status_set_warning();
|
||||
} else {
|
||||
this->status_clear_warning();
|
||||
}
|
||||
this->status_comm_result(!std::isnan(concentration) && !std::isnan(temperature) && !this->setup_incomplete_, nullptr);
|
||||
}
|
||||
|
||||
#ifdef USE_DFROBOT_SEN0465_TEMPERATURE_COMPENSATION
|
||||
|
||||
@@ -7,11 +7,8 @@ ESPHOME_LOG_TAG(TAG, "ds3231.sensor");
|
||||
|
||||
void DS3231TemperatureSensor::update() {
|
||||
float temperature;
|
||||
if (!this->parent_->read_temperature(temperature)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->parent_->read_temperature(temperature)))
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
this->publish_state(temperature);
|
||||
}
|
||||
|
||||
|
||||
@@ -212,12 +212,9 @@ void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) {
|
||||
#else
|
||||
error = rmt_transmit(this->channel_, this->encoder_, this->rmt_buf_, len * sizeof(rmt_symbol_word_t), &config);
|
||||
#endif
|
||||
if (error != ESP_OK) {
|
||||
if (!this->status_comm_result(error == ESP_OK, nullptr)) {
|
||||
ESP_LOGE(TAG, "RMT TX error");
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
light::ESPColorView ESP32RMTLEDStripLightOutput::get_view_internal(int32_t index) const {
|
||||
|
||||
@@ -55,14 +55,11 @@ void HC8Component::update() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (crc16(response.data(), 12) != encode_uint16(response[13], response[12])) {
|
||||
if (!this->status_comm_result(crc16(response.data(), 12) == encode_uint16(response[13], response[12]))) {
|
||||
ESP_LOGW(TAG, "HC8 Checksum mismatch");
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
const uint16_t ppm = encode_uint16(response[5], response[4]);
|
||||
ESP_LOGD(TAG, "HC8 Received CO₂=%uppm", ppm);
|
||||
if (this->co2_sensor_ != nullptr)
|
||||
|
||||
@@ -133,12 +133,9 @@ void HDC302XComponent::read_data_() {
|
||||
}
|
||||
|
||||
// Check checksums
|
||||
if (crc8(buf, 2, 0xff, 0x31, true) != buf[2] || crc8(buf + 3, 2, 0xff, 0x31, true) != buf[5]) {
|
||||
this->status_set_warning(LOG_STR("Read data: invalid CRC"));
|
||||
const bool crc_ok = crc8(buf, 2, 0xff, 0x31, true) == buf[2] && crc8(buf + 3, 2, 0xff, 0x31, true) == buf[5];
|
||||
if (!this->status_comm_result(crc_ok, LOG_STR("Read data: invalid CRC")))
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
if (this->temp_sensor_ != nullptr) {
|
||||
uint16_t raw_t = encode_uint16(buf[0], buf[1]);
|
||||
|
||||
@@ -39,8 +39,7 @@ void HoermannHcpCover::control(const cover::CoverCall &call) {
|
||||
}
|
||||
|
||||
void HoermannHcpCover::update_from_state_() {
|
||||
if (!this->parent_->is_valid()) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->parent_->is_valid(), LOG_STR("bus controller not responding"))) {
|
||||
// The door can now move unheard, so drop the baseline a direction would be inferred from and stop
|
||||
// reporting motion instead of leaving the cover travelling until the controller returns.
|
||||
this->previous_position_ = NAN;
|
||||
@@ -50,7 +49,6 @@ void HoermannHcpCover::update_from_state_() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
const auto previous_operation = this->current_operation;
|
||||
const float current_position = this->parent_->get_current_position();
|
||||
|
||||
@@ -53,12 +53,9 @@ void HoermannHcpLight::update_from_state_() {
|
||||
this->status_set_warning(LOG_STR("bus controller not responding"));
|
||||
return;
|
||||
}
|
||||
if (!this->parent_->is_light_known()) {
|
||||
// Commands are refused until the door says, so say so rather than looking healthy and doing nothing.
|
||||
this->status_set_warning(LOG_STR("door has not reported the lamp"));
|
||||
// Commands are refused until the door says, so say so rather than looking healthy and doing nothing.
|
||||
if (!this->status_comm_result(this->parent_->is_light_known(), LOG_STR("door has not reported the lamp")))
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
const bool heading_on = this->parent_->is_light_heading_on();
|
||||
if (this->light_state_->remote_values.is_on() != heading_on)
|
||||
this->publish_lamp_state_(heading_on);
|
||||
|
||||
@@ -14,11 +14,8 @@ void Husb238Component::setup() {
|
||||
|
||||
void Husb238Component::update() {
|
||||
uint8_t status;
|
||||
if (!this->read_byte(REG_PD_STATUS1, &status)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_byte(REG_PD_STATUS1, &status)))
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
if (this->attached_binary_sensor_ != nullptr) {
|
||||
|
||||
@@ -59,14 +59,11 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
|
||||
final_dout = this->dout_pin_->digital_read();
|
||||
}
|
||||
|
||||
if (!final_dout) {
|
||||
if (!this->status_comm_result(final_dout)) {
|
||||
ESP_LOGW(TAG, "HX711 DOUT pin not high after reading (data 0x%" PRIx32 ")!", data);
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
data = static_cast<uint32_t>(sign_extend<24>(data));
|
||||
|
||||
if (result != nullptr)
|
||||
|
||||
@@ -172,11 +172,7 @@ void INA2XX::loop() {
|
||||
break;
|
||||
|
||||
case State::DATA_COLLECTION_8:
|
||||
if (this->full_loop_is_okay_) {
|
||||
this->status_clear_warning();
|
||||
} else {
|
||||
this->status_set_warning();
|
||||
}
|
||||
this->status_comm_result(this->full_loop_is_okay_);
|
||||
this->state_ = State::IDLE;
|
||||
break;
|
||||
|
||||
|
||||
@@ -291,11 +291,8 @@ void LIS2DW12Component::loop() {
|
||||
|
||||
// SIXD_SRC and ALL_INT_SRC are adjacent, so one read captures both before any latch clears
|
||||
uint8_t regs[2];
|
||||
if (!this->read_bytes(static_cast<uint8_t>(RegisterMap::SIXD_SRC), regs, sizeof(regs))) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_bytes(static_cast<uint8_t>(RegisterMap::SIXD_SRC), regs, sizeof(regs))))
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
RegSixdSrc sixd;
|
||||
sixd.raw = regs[0];
|
||||
RegAllIntSrc src;
|
||||
@@ -315,11 +312,9 @@ void LIS2DW12Component::loop() {
|
||||
}
|
||||
|
||||
void LIS2DW12Component::update() {
|
||||
float x, y, z;
|
||||
if (!this->read_acceleration_data_(x, y, z)) {
|
||||
this->status_set_warning();
|
||||
float x{}, y{}, z{};
|
||||
if (!this->status_comm_result(this->read_acceleration_data_(x, y, z)))
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Acceleration: {x = %+1.3f m/s², y = %+1.3f m/s², z = %+1.3f m/s²}", x, y, z);
|
||||
|
||||
@@ -331,8 +326,6 @@ void LIS2DW12Component::update() {
|
||||
if (this->acceleration_z_sensor_ != nullptr)
|
||||
this->acceleration_z_sensor_->publish_state(z);
|
||||
#endif
|
||||
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
void LIS2DW12Component::set_offset(float offset_x, float offset_y, float offset_z) {
|
||||
|
||||
@@ -73,11 +73,7 @@ void LP5562Output::dump_config() {
|
||||
void LP5562Output::set_channel_value_(uint8_t channel, uint8_t value) {
|
||||
if (this->is_failed())
|
||||
return;
|
||||
if (!this->write_byte(progmem_read_byte(&LP5562_REG_PWM[channel]), value)) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
this->status_comm_result(this->write_byte(progmem_read_byte(&LP5562_REG_PWM[channel]), value));
|
||||
}
|
||||
|
||||
void LP5562Channel::write_state(float state) {
|
||||
|
||||
@@ -4,12 +4,9 @@ namespace esphome::m5stack_8angle {
|
||||
|
||||
void M5Stack8AngleSwitchBinarySensor::update() {
|
||||
int8_t out = this->parent_->read_switch();
|
||||
if (out == -1) {
|
||||
this->status_set_warning(LOG_STR("Could not read binary sensor state from M5Stack 8Angle."));
|
||||
if (!this->status_comm_result(out != -1, LOG_STR("Could not read binary sensor state from M5Stack 8Angle.")))
|
||||
return;
|
||||
}
|
||||
this->publish_state(out != 0);
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
} // namespace esphome::m5stack_8angle
|
||||
|
||||
@@ -5,17 +5,14 @@ namespace esphome::m5stack_8angle {
|
||||
void M5Stack8AngleKnobSensor::update() {
|
||||
if (this->parent_ != nullptr) {
|
||||
int32_t raw_pos = this->parent_->read_knob_pos_raw(this->channel_, this->bits_);
|
||||
if (raw_pos == -1) {
|
||||
this->status_set_warning(LOG_STR("Could not read knob position from M5Stack 8Angle."));
|
||||
if (!this->status_comm_result(raw_pos != -1, LOG_STR("Could not read knob position from M5Stack 8Angle.")))
|
||||
return;
|
||||
}
|
||||
if (this->raw_) {
|
||||
this->publish_state(raw_pos);
|
||||
} else {
|
||||
float knob_pos = (float) raw_pos / ((1 << this->bits_) - 1);
|
||||
this->publish_state(knob_pos);
|
||||
}
|
||||
this->status_clear_warning();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -31,17 +31,15 @@ void MAX6675Sensor::read_data_() {
|
||||
uint16_t val = data[1] | (uint16_t(data[0]) << 8);
|
||||
this->disable();
|
||||
|
||||
if ((val & 0x04) != 0) {
|
||||
// Thermocouple open
|
||||
// Bit 2 set means the thermocouple is open
|
||||
if (!this->status_comm_result((val & 0x04) == 0, nullptr)) {
|
||||
ESP_LOGW(TAG, "Got invalid value from MAX6675Sensor (0x%04X)", val);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
float temperature = float(val >> 3) / 4.0f;
|
||||
ESP_LOGD(TAG, "'%s': Got temperature=%.1f°C", this->name_.c_str(), temperature);
|
||||
this->publish_state(temperature);
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
} // namespace esphome::max6675
|
||||
|
||||
@@ -8,12 +8,10 @@ ESPHOME_LOG_TAG(TAG, "mcp3221");
|
||||
|
||||
float MCP3221Sensor::sample() {
|
||||
uint8_t data[2];
|
||||
if (this->read(data, 2) != i2c::ERROR_OK) {
|
||||
if (!this->status_comm_result(this->read(data, 2) == i2c::ERROR_OK)) {
|
||||
ESP_LOGW(TAG, "Read failed");
|
||||
this->status_set_warning();
|
||||
return NAN;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
uint16_t value = encode_uint16(data[0], data[1]);
|
||||
float voltage = value * this->reference_voltage_ / 4096.0f;
|
||||
|
||||
@@ -68,14 +68,11 @@ void MCP9808Sensor::update() {
|
||||
temp = (uint16_t) (msb) *16 + lsb / 16.0f;
|
||||
}
|
||||
|
||||
if (std::isnan(temp)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(!std::isnan(temp), nullptr))
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "%s: Got temperature=%.4f°C", this->name_.c_str(), temp);
|
||||
this->publish_state(temp);
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
} // namespace esphome::mcp9808
|
||||
|
||||
@@ -66,13 +66,11 @@ void MHZ19Component::update() {
|
||||
}
|
||||
|
||||
uint8_t checksum = mhz19_checksum(response);
|
||||
if (response[8] != checksum) {
|
||||
if (!this->status_comm_result(response[8] == checksum)) {
|
||||
ESP_LOGW(TAG, "MHZ19 Checksum doesn't match: 0x%02X!=0x%02X", response[8], checksum);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
const uint16_t ppm = (uint16_t(response[2]) << 8) | response[3];
|
||||
const int temp = int(response[4]) - 40;
|
||||
const uint8_t status = response[5];
|
||||
|
||||
@@ -43,11 +43,8 @@ void MICS4514Component::update() {
|
||||
return;
|
||||
}
|
||||
uint8_t data[6];
|
||||
if (this->read_register(SENSOR_REGISTER, data, 6) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_register(SENSOR_REGISTER, data, 6) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
ESP_LOGV(TAG, "Got data: %02X %02X %02X %02X %02X %02X", data[0], data[1], data[2], data[3], data[4], data[5]);
|
||||
uint16_t ox = encode_uint16(data[0], data[1]);
|
||||
uint16_t red = encode_uint16(data[2], data[3]);
|
||||
|
||||
@@ -112,13 +112,7 @@ bool MPR121Component::flush_gpio_() {
|
||||
this->write_byte(MPR121_GPIOEN, this->gpio_enable_);
|
||||
this->write_byte(MPR121_GPIODIR, this->gpio_direction_);
|
||||
|
||||
if (!this->write_byte(MPR121_GPIODATA, this->gpio_output_)) {
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
return this->status_comm_result(this->write_byte(MPR121_GPIODATA, this->gpio_output_));
|
||||
}
|
||||
|
||||
void MPR121GPIOPin::setup() { this->pin_mode(this->flags_); }
|
||||
|
||||
@@ -289,14 +289,11 @@ void NAU7802Sensor::loop() {
|
||||
}
|
||||
|
||||
void NAU7802Sensor::update() {
|
||||
if (!this->is_data_ready_()) {
|
||||
if (!this->status_comm_result(this->is_data_ready_(), nullptr)) {
|
||||
ESP_LOGW(TAG, "No measurements ready!");
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
// Get the most recent sample to publish
|
||||
int32_t result = this->read_value_(ADCO_B2_REG, 3);
|
||||
|
||||
|
||||
@@ -104,13 +104,11 @@ void OPT3001Sensor::update() {
|
||||
this->read_lx_([this](float val) {
|
||||
this->updating_ = false;
|
||||
|
||||
if (std::isnan(val)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(!std::isnan(val))) {
|
||||
this->publish_state(NAN);
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "'%s': Illuminance=%.1flx", this->get_name().c_str(), val);
|
||||
this->status_clear_warning();
|
||||
this->publish_state(val);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -138,13 +138,10 @@ bool PCA6416AComponent::read_register_(uint8_t reg, uint8_t *value) {
|
||||
}
|
||||
|
||||
this->last_error_ = this->read_register(reg, value, 1);
|
||||
if (this->last_error_ != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->last_error_ == i2c::ERROR_OK)) {
|
||||
ESP_LOGE(TAG, "read_register_(): I2C I/O error: %d", (int) this->last_error_);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -155,13 +152,10 @@ bool PCA6416AComponent::write_register_(uint8_t reg, uint8_t value) {
|
||||
}
|
||||
|
||||
this->last_error_ = this->write_register(reg, &value, 1);
|
||||
if (this->last_error_ != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->last_error_ == i2c::ERROR_OK)) {
|
||||
ESP_LOGE(TAG, "write_register_(): I2C I/O error: %d", (int) this->last_error_);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,12 +110,10 @@ bool PCA9554Component::read_inputs_() {
|
||||
}
|
||||
|
||||
this->last_error_ = this->read_register(INPUT_REG * this->reg_width_, inputs, this->reg_width_);
|
||||
if (this->last_error_ != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->last_error_ == i2c::ERROR_OK)) {
|
||||
ESP_LOGE(TAG, "read_register_(): I2C I/O error: %d", (int) this->last_error_);
|
||||
return false;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
this->input_mask_ = inputs[0];
|
||||
if (this->reg_width_ == 2) {
|
||||
this->input_mask_ |= inputs[1] << 8;
|
||||
@@ -128,13 +126,10 @@ bool PCA9554Component::write_register_(uint8_t reg, uint16_t value) {
|
||||
outputs[0] = (uint8_t) value;
|
||||
outputs[1] = (uint8_t) (value >> 8);
|
||||
this->last_error_ = this->write_register(reg * this->reg_width_, outputs, this->reg_width_);
|
||||
if (this->last_error_ != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->last_error_ == i2c::ERROR_OK)) {
|
||||
ESP_LOGE(TAG, "write_register_(): I2C I/O error: %d", (int) this->last_error_);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,12 +87,9 @@ bool PCF8574Component::read_gpio_() {
|
||||
if (this->is_failed())
|
||||
return false;
|
||||
uint8_t data[2]{}; // Keep the bytes zero for the PCF8574's one-byte read.
|
||||
if (!this->read_bytes_raw(data, this->pcf8575_ ? 2 : 1)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_bytes_raw(data, this->pcf8575_ ? 2 : 1)))
|
||||
return false;
|
||||
}
|
||||
this->input_mask_ = encode_value_le<uint16_t>(data);
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
}
|
||||
bool PCF8574Component::write_gpio_() {
|
||||
@@ -108,13 +105,7 @@ bool PCF8574Component::write_gpio_() {
|
||||
uint8_t data[2];
|
||||
data[0] = value;
|
||||
data[1] = value >> 8;
|
||||
if (this->write(data, this->pcf8575_ ? 2 : 1) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
return this->status_comm_result(this->write(data, this->pcf8575_ ? 2 : 1) == i2c::ERROR_OK);
|
||||
}
|
||||
float PCF8574Component::get_setup_priority() const { return setup_priority::IO; }
|
||||
|
||||
|
||||
@@ -105,15 +105,13 @@ bool PI4IOE5V6408Component::read_gpio_modes_() {
|
||||
return false;
|
||||
|
||||
uint8_t data;
|
||||
if (!this->read_byte(PI4IOE5V6408_REGISTER_IO_DIR, &data)) {
|
||||
this->status_set_warning(LOG_STR("Failed to read GPIO modes"));
|
||||
if (!this->status_comm_result(this->read_byte(PI4IOE5V6408_REGISTER_IO_DIR, &data),
|
||||
LOG_STR("Failed to read GPIO modes")))
|
||||
return false;
|
||||
}
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
|
||||
ESP_LOGV(TAG, "Read GPIO modes: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(data));
|
||||
#endif
|
||||
this->mode_mask_ = data;
|
||||
this->status_clear_warning();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -140,14 +138,12 @@ void PI4IOE5V6408Component::digital_write_hw(uint8_t pin, bool value) {
|
||||
} else {
|
||||
this->output_mask_ &= ~(1 << pin);
|
||||
}
|
||||
if (!this->write_byte(PI4IOE5V6408_REGISTER_OUT_SET, this->output_mask_)) {
|
||||
this->status_set_warning(LOG_STR("Failed to write output register"));
|
||||
if (!this->status_comm_result(this->write_byte(PI4IOE5V6408_REGISTER_OUT_SET, this->output_mask_),
|
||||
LOG_STR("Failed to write output register")))
|
||||
return;
|
||||
}
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
|
||||
ESP_LOGV(TAG, "Wrote GPIO output: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(this->output_mask_));
|
||||
#endif
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
bool PI4IOE5V6408Component::write_gpio_modes_() {
|
||||
|
||||
@@ -106,16 +106,15 @@ void PN532::update() {
|
||||
obj->on_scan_end();
|
||||
#endif
|
||||
|
||||
if (!this->write_command_({
|
||||
PN532_COMMAND_INLISTPASSIVETARGET,
|
||||
0x01, // max 1 card
|
||||
0x00, // baud rate ISO14443A (106 kbit/s)
|
||||
})) {
|
||||
const bool ok = this->write_command_({
|
||||
PN532_COMMAND_INLISTPASSIVETARGET,
|
||||
0x01, // max 1 card
|
||||
0x00, // baud rate ISO14443A (106 kbit/s)
|
||||
});
|
||||
if (!this->status_comm_result(ok)) {
|
||||
ESP_LOGW(TAG, "Requesting tag read failed!");
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
this->requested_read_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -288,12 +288,10 @@ bool QMP6988Component::calculate_pressure_() {
|
||||
int32_t t_int, p_int;
|
||||
|
||||
err = this->read_register(QMP6988_PRESSURE_MSB_REG, a_data_uint8_tr, 6);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
if (!this->status_comm_result(err == i2c::ERROR_OK)) {
|
||||
ESP_LOGE(TAG, "Error reading raw pressure/temp values");
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
p_read = encode_uint24(a_data_uint8_tr[0], a_data_uint8_tr[1], a_data_uint8_tr[2]);
|
||||
p_raw = (int32_t) (p_read - SUBTRACTOR);
|
||||
|
||||
@@ -284,14 +284,12 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
||||
this->store_.index = offset;
|
||||
esp_err_t error = rmt_transmit(this->channel_, this->encoder_, this->rmt_temp_.data(),
|
||||
this->rmt_temp_.size() * sizeof(rmt_symbol_half_t), &config);
|
||||
if (error != ESP_OK) {
|
||||
if (!this->status_comm_result(error == ESP_OK, nullptr)) {
|
||||
ESP_LOGW(TAG, "rmt_transmit failed: %s", esp_err_to_name(error));
|
||||
this->status_set_warning();
|
||||
// nothing was queued, so there is no frame to wait for
|
||||
this->fire_complete_(false);
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
if (this->non_blocking_) {
|
||||
this->set_timeout(COMPLETE_TIMEOUT_ID, total_duration / 1000, [this]() { this->wait_for_rmt_(); });
|
||||
|
||||
@@ -52,12 +52,10 @@ void RX8025TComponent::read_time() {
|
||||
}
|
||||
|
||||
uint8_t date[7];
|
||||
if (!this->read_bytes(RX8025T_REG_SEC, date, sizeof(date))) {
|
||||
if (!this->status_comm_result(this->read_bytes(RX8025T_REG_SEC, date, sizeof(date)))) {
|
||||
ESP_LOGE(TAG, "Can't read I2C data.");
|
||||
this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
if (flags & RX8025T_FLAG_VLF) {
|
||||
ESP_LOGW(TAG, "VLF flag is set - time data may be invalid, not syncing to system clock.");
|
||||
|
||||
@@ -81,13 +81,11 @@ void RX8111Component::read_time() {
|
||||
this->status_set_warning(LOG_STR("Invalid RTC time"));
|
||||
return;
|
||||
}
|
||||
if (ESPTime::from_epoch_utc(rtc_time.timestamp).day_of_week != weekday) {
|
||||
if (!this->status_comm_result(ESPTime::from_epoch_utc(rtc_time.timestamp).day_of_week == weekday,
|
||||
LOG_STR("Invalid RTC time"))) {
|
||||
ESP_LOGW(TAG, "RTC weekday does not match calendar date");
|
||||
this->status_set_warning(LOG_STR("Invalid RTC time"));
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
ESP_LOGD(TAG, "Read UTC time: %04d-%02d-%02d %02d:%02d:%02d", rtc_time.year, rtc_time.month, rtc_time.day_of_month,
|
||||
rtc_time.hour, rtc_time.minute, rtc_time.second);
|
||||
time::RealTimeClock::synchronize_epoch_(rtc_time.timestamp);
|
||||
|
||||
@@ -133,11 +133,7 @@ void SelecMeter::on_read_input_registers(uint16_t start_address, std::span<const
|
||||
#else
|
||||
bool ok = this->decode_em2m_(registers);
|
||||
#endif
|
||||
if (ok) {
|
||||
this->status_clear_warning();
|
||||
} else {
|
||||
this->status_set_warning();
|
||||
}
|
||||
this->status_comm_result(ok);
|
||||
break;
|
||||
}
|
||||
#if defined(USE_SELEC_METER_EM4M) && defined(USE_TEXT_SENSOR)
|
||||
|
||||
@@ -15,12 +15,10 @@ void Sen21231Sensor::dump_config() {
|
||||
|
||||
void Sen21231Sensor::read_data_() {
|
||||
person_sensor_results_t results;
|
||||
if (!this->read_bytes(PERSON_SENSOR_I2C_ADDRESS, (uint8_t *) &results, sizeof(results))) {
|
||||
if (!this->status_comm_result(this->read_bytes(PERSON_SENSOR_I2C_ADDRESS, (uint8_t *) &results, sizeof(results)))) {
|
||||
ESP_LOGW(TAG, "Failed to read data from SEN21231");
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
ESP_LOGD(TAG, "SEN21231: %d faces detected", results.num_faces);
|
||||
this->publish_state(results.num_faces);
|
||||
if (results.num_faces == 1) {
|
||||
|
||||
@@ -678,8 +678,7 @@ void SEN6XComponent::parse_and_publish_number_concentration_() {
|
||||
this->pmc_4_0_sensor_, this->pmc_10_0_sensor_};
|
||||
uint16_t measurements[std::size(sensors)];
|
||||
|
||||
if (!this->read_data(measurements, std::size(measurements))) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_data(measurements, std::size(measurements)))) {
|
||||
ESP_LOGD(TAG, "Read data failed (%d)", this->last_error_);
|
||||
return;
|
||||
}
|
||||
@@ -688,7 +687,6 @@ void SEN6XComponent::parse_and_publish_number_concentration_() {
|
||||
if (sensors[i] != nullptr)
|
||||
sensors[i]->publish_state(measurements[i] == 0xFFFF ? NAN : measurements[i] / 10.0f);
|
||||
}
|
||||
this->status_clear_warning();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -44,13 +44,11 @@ void SenseAirComponent::update() {
|
||||
|
||||
uint16_t calc_checksum = crc16(response, 11);
|
||||
uint16_t resp_checksum = encode_value_le<uint16_t>(&response[11]);
|
||||
if (resp_checksum != calc_checksum) {
|
||||
if (!this->status_comm_result(resp_checksum == calc_checksum)) {
|
||||
ESP_LOGW(TAG, "SenseAir checksum doesn't match: 0x%02X!=0x%02X", resp_checksum, calc_checksum);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
const uint8_t length = response[2];
|
||||
const uint16_t status = encode_uint16(response[3], response[4]);
|
||||
const uint16_t ppm = encode_uint16(response[length + 1], response[length + 2]);
|
||||
|
||||
@@ -87,15 +87,12 @@ void SHT4XComponent::update() {
|
||||
uint16_t buffer[2];
|
||||
|
||||
// Read measurement
|
||||
if (!this->read_data(buffer, 2)) {
|
||||
if (!this->status_comm_result(this->read_data(buffer, 2))) {
|
||||
// Using ESP_LOGW to force the warning to be printed
|
||||
ESP_LOGW(TAG, "Sensor read failed");
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
// Evaluate and publish measurements
|
||||
if (this->temp_sensor_ != nullptr) {
|
||||
// Temp is contained in the first result word
|
||||
|
||||
@@ -147,11 +147,9 @@ bool SPD2010Touchscreen::read_data_() {
|
||||
return true;
|
||||
}
|
||||
if (!(status_low & (STATUS_POINT | STATUS_GESTURE))) {
|
||||
if ((status_high & STATUS_RUNNING) && (status_low & STATUS_AUX) && !this->clear_interrupt_()) {
|
||||
this->status_set_warning(LOG_STR("Failed to clear interrupt"));
|
||||
return false;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
const bool needs_clear = (status_high & STATUS_RUNNING) && (status_low & STATUS_AUX);
|
||||
const bool cleared = !needs_clear || this->clear_interrupt_();
|
||||
this->status_comm_result(cleared, LOG_STR("Failed to clear interrupt"));
|
||||
return false;
|
||||
}
|
||||
if (length < REPORT_HEADER_LENGTH || length > MAX_REPORT_LENGTH ||
|
||||
|
||||
@@ -73,12 +73,10 @@ void ST7123Touchscreen::update_touches() {
|
||||
// Reading from this register also clears the INT pin so the controller can report the next frame.
|
||||
uint8_t data[(ST7123_REG_TOUCH_DATA - ST7123_REG_ADV_TOUCH_INFO) + ST7123_MAX_TOUCHES * ST7123_TOUCH_STRIDE];
|
||||
const size_t len = (ST7123_REG_TOUCH_DATA - ST7123_REG_ADV_TOUCH_INFO) + this->max_touches_ * ST7123_TOUCH_STRIDE;
|
||||
if (this->read_register16(ST7123_REG_ADV_TOUCH_INFO, data, len) != i2c::ERROR_OK) {
|
||||
if (!this->status_comm_result(this->read_register16(ST7123_REG_ADV_TOUCH_INFO, data, len) == i2c::ERROR_OK)) {
|
||||
this->skip_update_ = true;
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
const uint8_t *points = data + (ST7123_REG_TOUCH_DATA - ST7123_REG_ADV_TOUCH_INFO);
|
||||
for (uint8_t i = 0; i != this->max_touches_; i++) {
|
||||
|
||||
@@ -50,15 +50,12 @@ void STS3XComponent::update() {
|
||||
|
||||
this->set_timeout(50, [this]() {
|
||||
uint16_t raw_data[1];
|
||||
if (!this->read_data(raw_data, 1)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_data(raw_data, 1)))
|
||||
return;
|
||||
}
|
||||
|
||||
float temperature = 175.0f * float(raw_data[0]) / 65535.0f - 45.0f;
|
||||
ESP_LOGD(TAG, "Got temperature=%.2f°C", temperature);
|
||||
this->publish_state(temperature);
|
||||
this->status_clear_warning();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -123,14 +123,11 @@ void SY6970Component::update() {
|
||||
}
|
||||
|
||||
// Read all registers in one transaction
|
||||
if (!this->read_all_registers_()) {
|
||||
if (!this->status_comm_result(this->read_all_registers_())) {
|
||||
ESP_LOGW(TAG, "Failed to read registers during update");
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
// Notify all listeners with the new data
|
||||
for (auto *listener : this->listeners_) {
|
||||
listener->on_data(this->data_);
|
||||
|
||||
@@ -44,18 +44,15 @@ void T6615Component::loop() {
|
||||
this->read_array(response_buffer, 5);
|
||||
|
||||
// Read header
|
||||
if (response_buffer[0] != T6615_MAGIC || response_buffer[1] != T6615_ADDR_HOST) {
|
||||
if (!this->status_comm_result(response_buffer[0] == T6615_MAGIC && response_buffer[1] == T6615_ADDR_HOST)) {
|
||||
ESP_LOGW(TAG, "Got bad data from T6615! Magic was %02X and address was %02X", response_buffer[0],
|
||||
response_buffer[1]);
|
||||
this->discard_available();
|
||||
/* try again to read the sensor */
|
||||
this->send_ppm_command_();
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
switch (this->command_) {
|
||||
case T6615Command::GET_PPM: {
|
||||
const uint16_t ppm = encode_uint16(response_buffer[3], response_buffer[4]);
|
||||
|
||||
@@ -86,11 +86,8 @@ void TCA8418Component::loop() {
|
||||
return;
|
||||
this->last_poll_ = now;
|
||||
|
||||
if (!this->drain_events_(true)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->drain_events_(true)))
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
// Events that arrive during a read keep INT asserted without a new edge, so only stop once it is clear
|
||||
if (this->interrupt_pin_ != nullptr && this->interrupt_pin_->digital_read())
|
||||
|
||||
@@ -451,12 +451,10 @@ bool TMC22XXStepper::write_register(uint8_t reg, uint32_t value) {
|
||||
this->flush();
|
||||
// On the single wire bus every byte sent is also received, drop that echo
|
||||
uint8_t echo[DATAGRAM_SIZE];
|
||||
if (!this->read_array(echo, DATAGRAM_SIZE) || memcmp(echo, datagram, DATAGRAM_SIZE) != 0) {
|
||||
if (!this->status_comm_result(this->read_array(echo, DATAGRAM_SIZE) && memcmp(echo, datagram, DATAGRAM_SIZE) == 0)) {
|
||||
ESP_LOGV(TAG, "No echo writing register 0x%02X", reg);
|
||||
this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
return false;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
if (uint32_t *shadow = this->shadow_register(reg)) {
|
||||
*shadow = value;
|
||||
@@ -483,12 +481,11 @@ optional<uint32_t> TMC22XXStepper::read_register(uint8_t reg) {
|
||||
this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
return {};
|
||||
}
|
||||
if (reply[0] != SYNC_BYTE || reply[1] != MASTER_ADDRESS || reply[2] != reg || reply[7] != datagram_crc(reply, 7)) {
|
||||
if (!this->status_comm_result(reply[0] == SYNC_BYTE && reply[1] == MASTER_ADDRESS && reply[2] == reg &&
|
||||
reply[7] == datagram_crc(reply, 7))) {
|
||||
ESP_LOGV(TAG, "Invalid reply reading register 0x%02X", reg);
|
||||
this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
|
||||
return {};
|
||||
}
|
||||
this->status_clear_warning();
|
||||
return encode_uint32(reply[3], reply[4], reply[5], reply[6]);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,10 @@ void TMP1075Sensor::setup() {
|
||||
|
||||
void TMP1075Sensor::update() {
|
||||
uint16_t regvalue;
|
||||
if (!read_byte_16(REG_TEMP, ®value)) {
|
||||
if (!this->status_comm_result(this->read_byte_16(REG_TEMP, ®value), LOG_STR("can't read"))) {
|
||||
ESP_LOGW(TAG, "'%s' - unable to read temperature register", this->name_.c_str());
|
||||
this->status_set_warning(LOG_STR("can't read"));
|
||||
return;
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
const float temp = regvalue2temp(regvalue);
|
||||
this->publish_state(temp);
|
||||
|
||||
@@ -119,15 +119,12 @@ void TSL2561Sensor::read_data_() {
|
||||
return;
|
||||
}
|
||||
// Power off
|
||||
if (!this->tsl2561_write_byte(TSL2561_REGISTER_CONTROL, 0b00000000)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->tsl2561_write_byte(TSL2561_REGISTER_CONTROL, 0b00000000)))
|
||||
return;
|
||||
}
|
||||
|
||||
float lx = this->calculate_lx_(data0, data1);
|
||||
ESP_LOGD(TAG, "Got illuminance=%.1flx", lx);
|
||||
this->publish_state(lx);
|
||||
this->status_clear_warning();
|
||||
}
|
||||
float TSL2561Sensor::get_integration_time_ms_() {
|
||||
switch (this->integration_time_) {
|
||||
|
||||
@@ -18,12 +18,9 @@ void TTP229LSFComponent::dump_config() {
|
||||
}
|
||||
void TTP229LSFComponent::loop() {
|
||||
uint16_t touched = 0;
|
||||
if (this->read(reinterpret_cast<uint8_t *>(&touched), 2) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read(reinterpret_cast<uint8_t *>(&touched), 2) == i2c::ERROR_OK))
|
||||
return;
|
||||
}
|
||||
touched = i2c::i2ctohs(touched);
|
||||
this->status_clear_warning();
|
||||
touched = reverse_bits(touched);
|
||||
for (auto *channel : this->channels_) {
|
||||
channel->process(touched);
|
||||
|
||||
@@ -54,15 +54,12 @@ void VEML3235Sensor::update() {
|
||||
|
||||
void VEML3235Sensor::read_and_publish_(uint8_t adjustments_left) {
|
||||
uint8_t als_regs[] = {0, 0};
|
||||
if ((this->read_register(ALS_REG, als_regs, sizeof als_regs) != i2c::ERROR_OK)) {
|
||||
this->status_set_warning();
|
||||
if (!this->status_comm_result(this->read_register(ALS_REG, als_regs, sizeof als_regs) == i2c::ERROR_OK)) {
|
||||
this->publish_state(NAN);
|
||||
this->measurement_in_progress_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this->status_clear_warning();
|
||||
|
||||
uint16_t als_counts = encode_value_le<uint16_t>(als_regs);
|
||||
|
||||
if (this->auto_gain_ && adjustments_left > 0) {
|
||||
|
||||
Reference in New Issue
Block a user