From cfd2c9182c9cf7355cd4c536f64bc81e7073073c Mon Sep 17 00:00:00 2001 From: Didier A Date: Wed, 6 May 2026 18:34:55 +0200 Subject: [PATCH] [bl0942] Remove broken 24-bit overflow tracking (#15650) Co-authored-by: DidierA <1620015+didiera@users.noreply.github.com> Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> --- esphome/components/bl0942/bl0942.cpp | 8 ++------ esphome/components/bl0942/bl0942.h | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/esphome/components/bl0942/bl0942.cpp b/esphome/components/bl0942/bl0942.cpp index 7d38597423..074aff9643 100644 --- a/esphome/components/bl0942/bl0942.cpp +++ b/esphome/components/bl0942/bl0942.cpp @@ -161,13 +161,9 @@ void BL0942::received_package_(DataPacket *data) { return; } - // cf_cnt is only 24 bits, so track overflows + // cf_cnt wraps at 24 bits; total_increasing on the energy sensor handles the + // wrap (and any spurious chip resets) downstream. uint32_t cf_cnt = (uint24_t) data->cf_cnt; - cf_cnt |= this->prev_cf_cnt_ & 0xff000000; - if (cf_cnt < this->prev_cf_cnt_) { - cf_cnt += 0x1000000; - } - this->prev_cf_cnt_ = cf_cnt; float v_rms = (uint24_t) data->v_rms / voltage_reference_; float i_rms = (uint24_t) data->i_rms / current_reference_; diff --git a/esphome/components/bl0942/bl0942.h b/esphome/components/bl0942/bl0942.h index 3c013f86e7..7604399c25 100644 --- a/esphome/components/bl0942/bl0942.h +++ b/esphome/components/bl0942/bl0942.h @@ -141,7 +141,6 @@ class BL0942 : public PollingComponent, public uart::UARTDevice { bool reset_ = false; LineFrequency line_freq_ = LINE_FREQUENCY_50HZ; optional rx_start_{}; - uint32_t prev_cf_cnt_ = 0; bool validate_checksum_(DataPacket *data); int read_reg_(uint8_t reg);