mirror of
https://github.com/esphome/esphome.git
synced 2026-09-04 03:56:04 +00:00
[multiple] Fix wrong behavior in sensor calculations and drivers (#14644)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
308e8e78cd
commit
b3fc43c13c
@@ -147,8 +147,11 @@ void BME280Component::setup() {
|
||||
this->calibration_.h1 = read_u8_(BME280_REGISTER_DIG_H1);
|
||||
this->calibration_.h2 = read_s16_le_(BME280_REGISTER_DIG_H2);
|
||||
this->calibration_.h3 = read_u8_(BME280_REGISTER_DIG_H3);
|
||||
this->calibration_.h4 = read_u8_(BME280_REGISTER_DIG_H4) << 4 | (read_u8_(BME280_REGISTER_DIG_H4 + 1) & 0x0F);
|
||||
this->calibration_.h5 = read_u8_(BME280_REGISTER_DIG_H5 + 1) << 4 | (read_u8_(BME280_REGISTER_DIG_H5) >> 4);
|
||||
// h4 and h5 are signed 12-bit values; shift left then arithmetic right shift to sign-extend
|
||||
int16_t h4_raw = read_u8_(BME280_REGISTER_DIG_H4) << 4 | (read_u8_(BME280_REGISTER_DIG_H4 + 1) & 0x0F);
|
||||
this->calibration_.h4 = static_cast<int16_t>(h4_raw << 4) >> 4;
|
||||
int16_t h5_raw = read_u8_(BME280_REGISTER_DIG_H5 + 1) << 4 | (read_u8_(BME280_REGISTER_DIG_H5) >> 4);
|
||||
this->calibration_.h5 = static_cast<int16_t>(h5_raw << 4) >> 4;
|
||||
this->calibration_.h6 = read_u8_(BME280_REGISTER_DIG_H6);
|
||||
|
||||
uint8_t humid_control_val = 0;
|
||||
|
||||
@@ -32,8 +32,8 @@ enum BME680Oversampling {
|
||||
/// Struct for storing calibration data for the BME680.
|
||||
struct BME680CalibrationData {
|
||||
uint16_t t1;
|
||||
uint16_t t2;
|
||||
uint8_t t3;
|
||||
int16_t t2;
|
||||
int8_t t3;
|
||||
|
||||
uint16_t p1;
|
||||
int16_t p2;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace esphome::cse7766 {
|
||||
|
||||
@@ -192,12 +193,12 @@ void CSE7766Component::parse_data_() {
|
||||
this->apparent_power_sensor_->publish_state(apparent_power);
|
||||
}
|
||||
if (have_power && this->reactive_power_sensor_ != nullptr) {
|
||||
const float reactive_power = apparent_power - power;
|
||||
if (reactive_power < 0.0f) {
|
||||
ESP_LOGD(TAG, "Impossible reactive power: %.4f is negative", reactive_power);
|
||||
const float q_squared = apparent_power * apparent_power - power * power;
|
||||
if (q_squared < 0.0f) {
|
||||
ESP_LOGD(TAG, "Impossible reactive power: S^2-P^2 is negative (%.4f)", q_squared);
|
||||
this->reactive_power_sensor_->publish_state(0.0f);
|
||||
} else {
|
||||
this->reactive_power_sensor_->publish_state(reactive_power);
|
||||
this->reactive_power_sensor_->publish_state(std::sqrt(q_squared));
|
||||
}
|
||||
}
|
||||
if (this->power_factor_sensor_ != nullptr && (have_power || power_cycle_exceeds_range)) {
|
||||
|
||||
@@ -96,7 +96,7 @@ class HitachiClimate : public climate_ir::ClimateIR {
|
||||
void set_power_(bool on);
|
||||
uint8_t get_mode_();
|
||||
void set_mode_(uint8_t mode);
|
||||
void set_temp_(uint8_t celsius, bool set_previous = false);
|
||||
void set_temp_(uint8_t celsius, bool set_previous = true);
|
||||
uint8_t get_fan_();
|
||||
void set_fan_(uint8_t speed);
|
||||
void set_swing_v_toggle_(bool on);
|
||||
|
||||
@@ -75,7 +75,7 @@ void RX8130Component::read_time() {
|
||||
.second = bcd2dec(date[0] & 0x7f),
|
||||
.minute = bcd2dec(date[1] & 0x7f),
|
||||
.hour = bcd2dec(date[2] & 0x3f),
|
||||
.day_of_week = bcd2dec(date[3] & 0x7f),
|
||||
.day_of_week = static_cast<uint8_t>((date[3] & 0x7f) ? __builtin_ctz(date[3] & 0x7f) + 1 : 1),
|
||||
.day_of_month = bcd2dec(date[4] & 0x3f),
|
||||
.day_of_year = 1, // ignored by recalc_timestamp_utc(false)
|
||||
.month = bcd2dec(date[5] & 0x1f),
|
||||
@@ -103,7 +103,7 @@ void RX8130Component::write_time() {
|
||||
buff[0] = dec2bcd(now.second);
|
||||
buff[1] = dec2bcd(now.minute);
|
||||
buff[2] = dec2bcd(now.hour);
|
||||
buff[3] = dec2bcd(now.day_of_week);
|
||||
buff[3] = 1 << (now.day_of_week - 1);
|
||||
buff[4] = dec2bcd(now.day_of_month);
|
||||
buff[5] = dec2bcd(now.month);
|
||||
buff[6] = dec2bcd(now.year % 100);
|
||||
|
||||
@@ -65,7 +65,7 @@ std::vector<CdcEps> USBUartTypeCP210X::parse_descriptors(usb_device_handle_t dev
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i != config_desc->bNumInterfaces; i++) {
|
||||
auto data_desc = usb_parse_interface_descriptor(config_desc, 0, 0, &conf_offset);
|
||||
auto data_desc = usb_parse_interface_descriptor(config_desc, i, 0, &conf_offset);
|
||||
if (!data_desc) {
|
||||
ESP_LOGE(TAG, "data_desc: usb_parse_interface_descriptor failed");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user