[usb_cdc_acm][scd4x][pulse_counter][mopeka_std_check][ruuvi_ble] Fix assorted one-liner bugs (#14495)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-03-05 14:47:55 -05:00
committed by GitHub
parent 9961c8180a
commit 22d90d702d
6 changed files with 16 additions and 11 deletions

View File

@@ -108,7 +108,7 @@ bool MopekaStdCheck::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
}
// Get temperature of sensor
uint8_t temp_in_c = this->parse_temperature_(mopeka_data);
int8_t temp_in_c = this->parse_temperature_(mopeka_data);
if (this->temperature_ != nullptr) {
this->temperature_->publish_state(temp_in_c);
}
@@ -223,12 +223,12 @@ uint8_t MopekaStdCheck::parse_battery_level_(const mopeka_std_package *message)
return (uint8_t) percent;
}
uint8_t MopekaStdCheck::parse_temperature_(const mopeka_std_package *message) {
int8_t MopekaStdCheck::parse_temperature_(const mopeka_std_package *message) {
uint8_t tmp = message->raw_temp;
if (tmp == 0x0) {
return -40;
} else {
return (uint8_t) ((tmp - 25.0f) * 1.776964f);
return static_cast<int8_t>((tmp - 25.0f) * 1.776964f);
}
}

View File

@@ -71,7 +71,7 @@ class MopekaStdCheck : public Component, public esp32_ble_tracker::ESPBTDeviceLi
float get_lpg_speed_of_sound_(float temperature);
uint8_t parse_battery_level_(const mopeka_std_package *message);
uint8_t parse_temperature_(const mopeka_std_package *message);
int8_t parse_temperature_(const mopeka_std_package *message);
};
} // namespace mopeka_std_check

View File

@@ -175,7 +175,8 @@ void PulseCounterSensor::setup() {
void PulseCounterSensor::set_total_pulses(uint32_t pulses) {
this->current_total_ = pulses;
this->total_sensor_->publish_state(pulses);
if (this->total_sensor_ != nullptr)
this->total_sensor_->publish_state(pulses);
}
void PulseCounterSensor::dump_config() {

View File

@@ -63,10 +63,13 @@ bool parse_ruuvi_data_byte(const esp32_ble_tracker::adv_data_t &adv_data, RuuviP
result.acceleration_x = data[6] == 0xFF && data[7] == 0xFF ? NAN : acceleration_x;
result.acceleration_y = data[8] == 0xFF && data[9] == 0xFF ? NAN : acceleration_y;
result.acceleration_z = data[10] == 0xFF && data[11] == 0xFF ? NAN : acceleration_z;
result.acceleration = result.acceleration_x == NAN || result.acceleration_y == NAN || result.acceleration_z == NAN
? NAN
: sqrtf(acceleration_x * acceleration_x + acceleration_y * acceleration_y +
acceleration_z * acceleration_z);
if ((data[6] != 0xFF || data[7] != 0xFF) && (data[8] != 0xFF || data[9] != 0xFF) &&
(data[10] != 0xFF || data[11] != 0xFF)) {
result.acceleration =
sqrtf(acceleration_x * acceleration_x + acceleration_y * acceleration_y + acceleration_z * acceleration_z);
} else {
result.acceleration = NAN;
}
result.battery_voltage = (power_info >> 5) == 0x7FF ? NAN : battery_voltage;
result.tx_power = (power_info & 0x1F) == 0x1F ? NAN : tx_power;
result.movement_counter = movement_counter;

View File

@@ -307,7 +307,7 @@ bool SCD4XComponent::start_measurement_() {
break;
}
static uint8_t remaining_retries = 3;
uint8_t remaining_retries = 3;
while (remaining_retries) {
if (!this->write_command(measurement_command)) {
ESP_LOGE(TAG, "Error starting measurements");
@@ -316,6 +316,7 @@ bool SCD4XComponent::start_measurement_() {
if (--remaining_retries == 0)
return false;
delay(50); // NOLINT wait 50 ms and try again
continue;
}
this->status_clear_warning();
return true;

View File

@@ -161,7 +161,7 @@ void USBCDCACMInstance::setup() {
// Create a simple, unique task name per interface
char task_name[] = "usb_tx_0";
task_name[sizeof(task_name) - 1] = format_hex_char(static_cast<char>(this->itf_));
task_name[sizeof(task_name) - 2] = format_hex_char(static_cast<char>(this->itf_));
xTaskCreate(usb_tx_task_fn, task_name, stack_size, this, 4, &this->usb_tx_task_handle_);
if (this->usb_tx_task_handle_ == nullptr) {