From 053fd535ada011543574064f87a0bedf280d289c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 Oct 2026 14:58:00 -1000 Subject: [PATCH] Log the old and new register value at VERBOSE in update_register --- esphome/components/i2c/i2c.cpp | 4 +++- esphome/components/i2c/i2c.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/esphome/components/i2c/i2c.cpp b/esphome/components/i2c/i2c.cpp index 6fda6644bf2..c2bc9c6b1a3 100644 --- a/esphome/components/i2c/i2c.cpp +++ b/esphome/components/i2c/i2c.cpp @@ -62,7 +62,9 @@ bool I2CDevice::update_register(uint8_t a_register, uint8_t mask, uint8_t value) uint8_t data; if (!this->read_byte(a_register, &data)) return false; - return this->write_byte(a_register, (data & ~mask) | (value & mask)); + const uint8_t updated = (data & ~mask) | (value & mask); + ESP_LOGV(TAG, "Register 0x%02X: 0x%02X -> 0x%02X", a_register, data, updated); + return this->write_byte(a_register, updated); } bool I2CDevice::write_bytes_16(uint8_t a_register, const uint16_t *data, uint8_t len) const { diff --git a/esphome/components/i2c/i2c.h b/esphome/components/i2c/i2c.h index 1565abef56e..0a3af593e49 100644 --- a/esphome/components/i2c/i2c.h +++ b/esphome/components/i2c/i2c.h @@ -267,7 +267,7 @@ class I2CDevice { bool write_byte_16(uint8_t a_register, uint16_t data) const { return write_bytes_16(a_register, &data, 1); } /// Read a register, replace the bits in @p mask with those of @p value and write it back. - /// The write always happens; bits of @p value outside @p mask are ignored. + /// The write always happens; bits of @p value outside @p mask are ignored. Logs both values at VERBOSE. /// @return false if the read or the write failed (nothing is written after a failed read) bool update_register(uint8_t a_register, uint8_t mask, uint8_t value);