Skip to content

Commit

Permalink
resolve clang-tidy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
whitty committed Jul 26, 2024
1 parent 8e4b3b7 commit c514876
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
28 changes: 8 additions & 20 deletions esphome/components/emerald_ble/emerald_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<uint8_t*>(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);
}
Expand Down
12 changes: 6 additions & 6 deletions esphome/components/emerald_ble/emerald_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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; }

Expand All @@ -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::RealTimeClock *> time_{};
time::RealTimeClock * time_{};
#endif
uint8_t day_of_last_measurement_{0};

Expand Down

0 comments on commit c514876

Please sign in to comment.