From 1546ba10ac5b5dd4b768d000a38aef281283a731 Mon Sep 17 00:00:00 2001 From: Greg Whiteley Date: Thu, 25 Jul 2024 22:52:06 +1000 Subject: [PATCH] resolve clang-tidy issues --- .../components/emerald_ble/emerald_ble.cpp | 28 ++++++------------- esphome/components/emerald_ble/emerald_ble.h | 12 ++++---- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/esphome/components/emerald_ble/emerald_ble.cpp b/esphome/components/emerald_ble/emerald_ble.cpp index 7b40f7cb25ce..f59c904525a0 100644 --- a/esphome/components/emerald_ble/emerald_ble.cpp +++ b/esphome/components/emerald_ble/emerald_ble.cpp @@ -103,9 +103,7 @@ void Emerald::decode_emerald_packet_(const uint8_t *data, uint16_t length) { // if esphome device has a valid time component set up, use that (preferred) // else, use the emerald measurement timestamps #ifdef USE_TIME - auto *time_ = *this->time_; - ESPTime date_of_measurement = time_->now(); - // ESPTime date_of_measurement = this->time_->now(); + ESPTime date_of_measurement = (this->time_) ? this->time_->now() : ESPTime{}; if (date_of_measurement.is_valid()) { if (this->day_of_last_measurement_ == 0) { this->day_of_last_measurement_ = date_of_measurement.day_of_year; } else if (this->day_of_last_measurement_ != date_of_measurement.day_of_year) { @@ -131,18 +129,10 @@ void Emerald::decode_emerald_packet_(const uint8_t *data, uint16_t length) { break; } - case RETURN_UPDATED_POWER_CMD: { - break; - } - case RETURN_EVERY30S_POWER_CONSUMPTION_CMD: { - break; - } - case RETURN_IMPULSE_CMD: { - break; - } - case RETURN_PAIRING_CODE_CMD: { - break; - } + case RETURN_UPDATED_POWER_CMD: + case RETURN_EVERY30S_POWER_CONSUMPTION_CMD: + case RETURN_IMPULSE_CMD: + case RETURN_PAIRING_CODE_CMD: case RETURN_DEVICE_TIME_CMD: { break; } @@ -155,9 +145,7 @@ void Emerald::decode_emerald_packet_(const uint8_t *data, uint16_t length) { void Emerald::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) { switch (event) { - case ESP_GATTC_DISCONNECT_EVT: { - break; - } + case ESP_GATTC_DISCONNECT_EVT: case ESP_GATTC_SEARCH_CMPL_EVT: { break; } @@ -243,8 +231,8 @@ void Emerald::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_par // uint8_t set_auto_upload[] = {0x00, 0x01, 0x02, 0x0b, 0x01, 0x01}; ESP_LOGI(TAG, "[%s] Writing auto upload code to Emerald", this->parent()->address_str().c_str()); auto write_status = esp_ble_gattc_write_char(this->parent()->get_gattc_if(), this->parent()->get_conn_id(), - this->time_write_size_char_handle_, sizeof(setAutoUploadStatusCmd), - setAutoUploadStatusCmd, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); + this->time_write_size_char_handle_, sizeof(SET_AUTO_UPLOAD_STATUS_CMD), + const_cast(SET_AUTO_UPLOAD_STATUS_CMD), ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); if (write_status) { ESP_LOGW(TAG, "Error sending write request for pairing_code, status=%d", write_status); } diff --git a/esphome/components/emerald_ble/emerald_ble.h b/esphome/components/emerald_ble/emerald_ble.h index 1c5f9451972b..539f985fe54a 100644 --- a/esphome/components/emerald_ble/emerald_ble.h +++ b/esphome/components/emerald_ble/emerald_ble.h @@ -44,7 +44,7 @@ static const espbt::ESPBTUUID EMERALD_BATTERY_CHARACTERISTIC_UUID = espbt::ESPBT // static std::string setAutoUploadStatusCmd = "0001020b01"; // static const uint8_t setAutoUploadStatusCmd = "0001020b01"; //enabled -static uint8_t setAutoUploadStatusCmd[] = {0x00,0x01,0x02,0x0b,0x01,0x01}; +static const uint8_t SET_AUTO_UPLOAD_STATUS_CMD[] = {0x00,0x01,0x02,0x0b,0x01,0x01}; static const uint32_t RETURN30S_POWER_CONSUMPTION_CMD = 0x0001020a06; static const uint32_t RETURN_UPDATED_POWER_CMD = 0x0001020204; @@ -53,9 +53,9 @@ static const uint32_t RETURN_IMPULSE_CMD = 0x0001010602; static const uint32_t RETURN_PAIRING_CODE_CMD = 0x0001030206; static const uint32_t RETURN_DEVICE_TIME_CMD = 0x0001010304; -static const uint8_t standard_update_interval = 30; // seconds -static const float kw_to_w_conversion = 1000.0; // conversion ratio -static const int hr_to_s_conversion = 3600; +static const uint8_t STANDARD_UPDATE_INTERVAL = 30; // seconds +static const float KW_TO_W_CONVERSION = 1000.0; // conversion ratio +static const int HR_TO_S_CONVERSION = 3600; class Emerald : public esphome::ble_client::BLEClientNode, public Component { @@ -76,7 +76,7 @@ class Emerald : public esphome::ble_client::BLEClientNode, public Component { #endif void set_pulses_per_kwh(uint16_t pulses_per_kwh) { pulses_per_kwh_ = pulses_per_kwh; - pulse_multiplier_ = ((hr_to_s_conversion * kw_to_w_conversion) / (standard_update_interval * pulses_per_kwh)); + pulse_multiplier_ = ((HR_TO_S_CONVERSION * KW_TO_W_CONVERSION) / (STANDARD_UPDATE_INTERVAL * pulses_per_kwh)); } void set_pairing_code(uint32_t pairing_code) { pairing_code_ = pairing_code; } @@ -94,7 +94,7 @@ class Emerald : public esphome::ble_client::BLEClientNode, public Component { sensor::Sensor *energy_sensor_{nullptr}; sensor::Sensor *daily_energy_sensor_{nullptr}; #ifdef USE_TIME - optional time_{}; + time::RealTimeClock * time_{}; #endif uint8_t day_of_last_measurement_{0};