From 6ea0f00dfb96a817948795368751814927fd386c Mon Sep 17 00:00:00 2001 From: j0ta29 Date: Sun, 18 Feb 2024 17:05:04 +0000 Subject: [PATCH] fixed clang-tidy issues --- .../binary_sensor/optolink_binary_sensor.h | 4 +- .../optolink/datapoint_component.cpp | 74 +++++++++---------- .../components/optolink/datapoint_component.h | 43 ++++++----- .../optolink/number/optolink_number.cpp | 4 +- .../optolink/number/optolink_number.h | 4 +- .../optolink/select/optolink_select.cpp | 6 +- .../optolink/select/optolink_select.h | 4 +- .../optolink/sensor/optolink_sensor.cpp | 2 + .../optolink/sensor/optolink_sensor.h | 4 +- .../optolink/switch/optolink_switch.cpp | 4 +- .../optolink/switch/optolink_switch.h | 4 +- .../text_sensor/optolink_text_sensor.cpp | 18 ++--- 12 files changed, 86 insertions(+), 85 deletions(-) diff --git a/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h b/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h index 67f8e99307..2e1b5158b4 100644 --- a/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h +++ b/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h @@ -19,8 +19,8 @@ class OptolinkBinarySensor : public DatapointComponent, } protected: - void setup() override { setup_datapoint(); } - void update() override { datapoint_read_request(); } + void setup() override { setup_datapoint_(); } + void update() override { datapoint_read_request_(); } const StringRef &get_component_name() override { return get_name(); } void datapoint_value_changed(uint8_t state) override { publish_state(state); }; diff --git a/esphome/components/optolink/datapoint_component.cpp b/esphome/components/optolink/datapoint_component.cpp index 6f00e3abe0..7c13c6cd95 100644 --- a/esphome/components/optolink/datapoint_component.cpp +++ b/esphome/components/optolink/datapoint_component.cpp @@ -12,7 +12,7 @@ namespace optolink { static const char *const TAG = "optolink.datapoint_component"; static std::vector hass_subscriptions_; -void DatapointComponent::setup_datapoint() { +void DatapointComponent::setup_datapoint_() { switch (div_ratio_) { case 0: datapoint_ = new Datapoint(get_component_name().c_str(), "optolink", address_, writeable_); @@ -56,7 +56,7 @@ void DatapointComponent::setup_datapoint() { }); break; default: - unfitting_value_type(); + unfitting_value_type_(); } break; case 10: @@ -78,7 +78,7 @@ void DatapointComponent::setup_datapoint() { }); break; default: - unfitting_value_type(); + unfitting_value_type_(); } break; case 100: @@ -92,7 +92,7 @@ void DatapointComponent::setup_datapoint() { }); break; default: - unfitting_value_type(); + unfitting_value_type_(); } break; case 1000: @@ -120,16 +120,16 @@ void DatapointComponent::setup_datapoint() { } break; default: - unfitting_value_type(); + unfitting_value_type_(); } } -void DatapointComponent::datapoint_read_request() { - if (is_dp_value_writing_outstanding) { +void DatapointComponent::datapoint_read_request_() { + if (is_dp_value_writing_outstanding_) { ESP_LOGI(TAG, "read request for %s deferred due to outstanding write request", get_component_name().c_str()); - datapoint_write_request(dp_value_outstanding); + datapoint_write_request_(dp_value_outstanding_); } else { - if (read_retries_ == 0 || read_retries_ >= MAX_RETRIES_UNTIL_RESET) { + if (read_retries_ == 0 || read_retries_ >= max_retries_until_reset_) { if (optolink_->read_value(datapoint_)) { read_retries_ = 1; } @@ -165,7 +165,7 @@ void DatapointComponent::datapoint_value_changed(uint8_t *value, size_t length) ESP_LOGW(TAG, "unused value update by sensor %s", get_component_name().c_str()); } -void DatapointComponent::datapoint_write_request(DPValue dp_value) { +void DatapointComponent::datapoint_write_request_(DPValue dp_value) { if (!writeable_) { optolink_->set_state("trying to control not writable datapoint %s", get_component_name().c_str()); ESP_LOGE(TAG, "trying to control not writable datapoint %s", get_component_name().c_str()); @@ -176,78 +176,78 @@ void DatapointComponent::datapoint_write_request(DPValue dp_value) { ESP_LOGI(TAG, "trying to update datapoint %s value: %s", get_component_name().c_str(), buffer); #endif - dp_value_outstanding = dp_value; - if (optolink_->write_value(datapoint_, dp_value_outstanding)) { - is_dp_value_writing_outstanding = false; + dp_value_outstanding_ = dp_value; + if (optolink_->write_value(datapoint_, dp_value_outstanding_)) { + is_dp_value_writing_outstanding_ = false; } else { ESP_LOGW(TAG, "write request for %s rejected due to outstanding running request - increase update_interval!", get_component_name().c_str()); - is_dp_value_writing_outstanding = true; + is_dp_value_writing_outstanding_ = true; } } } -void DatapointComponent::write_datapoint_value(float value) { +void DatapointComponent::write_datapoint_value_(float value) { if (div_ratio_ > 1) { - datapoint_write_request(DPValue(value)); + datapoint_write_request_(DPValue(value)); } else if (div_ratio_ == 1) { switch (bytes_) { case 1: - datapoint_write_request(DPValue((uint8_t) value)); + datapoint_write_request_(DPValue((uint8_t) value)); break; case 2: - datapoint_write_request(DPValue((uint16_t) value)); + datapoint_write_request_(DPValue((uint16_t) value)); break; case 4: - datapoint_write_request(DPValue((uint32_t) value)); + datapoint_write_request_(DPValue((uint32_t) value)); break; default: - unfitting_value_type(); + unfitting_value_type_(); break; } } else { - unfitting_value_type(); + unfitting_value_type_(); } } -void DatapointComponent::write_datapoint_value(uint8_t value) { +void DatapointComponent::write_datapoint_value_(uint8_t value) { if (bytes_ == 1 && div_ratio_ == 1) { - datapoint_write_request(DPValue(value)); + datapoint_write_request_(DPValue(value)); } else { - unfitting_value_type(); + unfitting_value_type_(); } } -void DatapointComponent::write_datapoint_value(uint16_t value) { +void DatapointComponent::write_datapoint_value_(uint16_t value) { if (bytes_ == 2 && div_ratio_ == 1) { - datapoint_write_request(DPValue(value)); + datapoint_write_request_(DPValue(value)); } else { - unfitting_value_type(); + unfitting_value_type_(); } } -void DatapointComponent::write_datapoint_value(uint32_t value) { +void DatapointComponent::write_datapoint_value_(uint32_t value) { if (bytes_ == 4 && div_ratio_ == 1) { - datapoint_write_request(DPValue(value)); + datapoint_write_request_(DPValue(value)); } else { - unfitting_value_type(); + unfitting_value_type_(); } } -void DatapointComponent::write_datapoint_value(uint8_t *value, size_t length) { +void DatapointComponent::write_datapoint_value_(uint8_t *value, size_t length) { if (bytes_ == length && div_ratio_ == 0) { - datapoint_write_request(DPValue(value, length)); + datapoint_write_request_(DPValue(value, length)); } else { - unfitting_value_type(); + unfitting_value_type_(); } } -void DatapointComponent::unfitting_value_type() { +void DatapointComponent::unfitting_value_type_() { optolink_->set_state("Unfitting byte/div_ratio combination for sensor/component %s", get_component_name().c_str()); ESP_LOGE(TAG, "Unfitting byte/div_ratio combination for sensor/component %s", get_component_name().c_str()); } -void DatapointComponent::set_optolink_state(const char *format, ...) { +void DatapointComponent::set_optolink_state_(const char *format, ...) { va_list args; va_start(args, format); char buffer[128]; @@ -257,9 +257,9 @@ void DatapointComponent::set_optolink_state(const char *format, ...) { optolink_->set_state(buffer); } -std::string DatapointComponent::get_optolink_state() { return optolink_->get_state(); } +std::string DatapointComponent::get_optolink_state_() { return optolink_->get_state(); } -void DatapointComponent::subscribe_hass(std::string entity_id, std::function f) { +void DatapointComponent::subscribe_hass_(std::string entity_id, std::function f) { for (auto &subscription : hass_subscriptions_) { if (subscription.entity_id == entity_id) { subscription.callbacks.push_back(f); diff --git a/esphome/components/optolink/datapoint_component.h b/esphome/components/optolink/datapoint_component.h index a0548bcefa..970f6abe06 100644 --- a/esphome/components/optolink/datapoint_component.h +++ b/esphome/components/optolink/datapoint_component.h @@ -19,7 +19,7 @@ struct HassSubscription { class DatapointComponent { public: - DatapointComponent(Optolink *optolink, bool writeable = false) : dp_value_outstanding((uint8_t) 0) { + DatapointComponent(Optolink *optolink, bool writeable = false) : dp_value_outstanding_((uint8_t) 0) { optolink_ = optolink; writeable_ = writeable; } @@ -32,11 +32,11 @@ class DatapointComponent { protected: virtual const StringRef &get_component_name() = 0; - uint32_t get_address() { return address_; } + uint32_t get_address_() { return address_; } - void setup_datapoint(); + void setup_datapoint_(); - void datapoint_read_request(); + void datapoint_read_request_(); virtual void datapoint_value_changed(float value); virtual void datapoint_value_changed(uint8_t value); @@ -45,20 +45,20 @@ class DatapointComponent { virtual void datapoint_value_changed(std::string value); virtual void datapoint_value_changed(uint8_t *value, size_t length); - void write_datapoint_value(float value); - void write_datapoint_value(uint8_t value); - void write_datapoint_value(uint16_t value); - void write_datapoint_value(uint32_t value); - void write_datapoint_value(uint8_t *value, size_t length); + void write_datapoint_value_(float value); + void write_datapoint_value_(uint8_t value); + void write_datapoint_value_(uint16_t value); + void write_datapoint_value_(uint32_t value); + void write_datapoint_value_(uint8_t *value, size_t length); - void unfitting_value_type(); - void set_optolink_state(const char *format, ...); - std::string get_optolink_state(); + void unfitting_value_type_(); + void set_optolink_state_(const char *format, ...); + std::string get_optolink_state_(); - void subscribe_hass(std::string entity_id, std::function f); + void subscribe_hass_(std::string entity_id, std::function f); private: - const size_t MAX_RETRIES_UNTIL_RESET = 10; + const size_t max_retries_until_reset_ = 10; Optolink *optolink_; IDatapoint *datapoint_ = nullptr; size_t read_retries_ = 0; @@ -66,28 +66,27 @@ class DatapointComponent { size_t bytes_; uint32_t address_; bool writeable_; + bool is_dp_value_writing_outstanding_ = false; + DPValue dp_value_outstanding_; - bool is_dp_value_writing_outstanding = false; - DPValue dp_value_outstanding; - - void datapoint_write_request(DPValue dp_value); + void datapoint_write_request_(DPValue dp_value); }; -// NOLINTNEXTLINE +// NOLINTBEGIN class conv2_100_F : public DPType { public: void encode(uint8_t *out, DPValue in); DPValue decode(const uint8_t *in); - size_t get_length() const { return 2; } + virtual const size_t get_length() const { return 2; } }; -// NOLINTNEXTLINE class conv4_1000_F : public DPType { public: void encode(uint8_t *out, DPValue in); DPValue decode(const uint8_t *in); - const size_t getLength() const { return 4; } + virtual const size_t getLength() const { return 4; } }; +// NOLINTEND } // namespace optolink } // namespace esphome diff --git a/esphome/components/optolink/number/optolink_number.cpp b/esphome/components/optolink/number/optolink_number.cpp index 5c3fc87fff..31450c02b5 100644 --- a/esphome/components/optolink/number/optolink_number.cpp +++ b/esphome/components/optolink/number/optolink_number.cpp @@ -10,11 +10,11 @@ static const char *const TAG = "optolink.number"; void OptolinkNumber::control(float value) { if (value > traits.get_max_value() || value < traits.get_min_value()) { - set_optolink_state("datapoint value of number %s not in allowed range", get_component_name().c_str()); + set_optolink_state_("datapoint value of number %s not in allowed range", get_component_name().c_str()); ESP_LOGE(TAG, "datapoint value of number %s not in allowed range", get_component_name().c_str()); } else { ESP_LOGI(TAG, "control of number %s to value %f", get_component_name().c_str(), value); - write_datapoint_value(value); + write_datapoint_value_(value); publish_state(value); } }; diff --git a/esphome/components/optolink/number/optolink_number.h b/esphome/components/optolink/number/optolink_number.h index d7d3062a31..b202a9b770 100644 --- a/esphome/components/optolink/number/optolink_number.h +++ b/esphome/components/optolink/number/optolink_number.h @@ -14,8 +14,8 @@ class OptolinkNumber : public DatapointComponent, public esphome::number::Number OptolinkNumber(Optolink *optolink) : DatapointComponent(optolink, true) {} protected: - void setup() override { setup_datapoint(); } - void update() override { datapoint_read_request(); } + void setup() override { setup_datapoint_(); } + void update() override { datapoint_read_request_(); } void control(float value) override; const StringRef &get_component_name() override { return get_name(); } diff --git a/esphome/components/optolink/select/optolink_select.cpp b/esphome/components/optolink/select/optolink_select.cpp index 0f21c6d0c6..a40378580f 100644 --- a/esphome/components/optolink/select/optolink_select.cpp +++ b/esphome/components/optolink/select/optolink_select.cpp @@ -12,12 +12,12 @@ void OptolinkSelect::control(const std::string &value) { for (auto it = mapping_->begin(); it != mapping_->end(); ++it) { if (it->second == value) { ESP_LOGI(TAG, "control of select %s to value %s", get_component_name().c_str(), it->first.c_str()); - write_datapoint_value(std::stof(it->first)); + write_datapoint_value_(std::stof(it->first)); publish_state(it->second); break; } if (it == mapping_->end()) { - set_optolink_state("unknown value %s of select %s", value.c_str(), get_component_name().c_str()); + set_optolink_state_("unknown value %s of select %s", value.c_str(), get_component_name().c_str()); ESP_LOGE(TAG, "unknown value %s of select %s", value.c_str(), get_component_name().c_str()); } } @@ -26,7 +26,7 @@ void OptolinkSelect::control(const std::string &value) { void OptolinkSelect::datapoint_value_changed(std::string key) { auto pos = mapping_->find(key); if (pos == mapping_->end()) { - set_optolink_state("value %s not found in select %s", key.c_str(), get_component_name().c_str()); + set_optolink_state_("value %s not found in select %s", key.c_str(), get_component_name().c_str()); ESP_LOGE(TAG, "value %s not found in select %s", key.c_str(), get_component_name().c_str()); } else { publish_state(pos->second); diff --git a/esphome/components/optolink/select/optolink_select.h b/esphome/components/optolink/select/optolink_select.h index e578a858b1..a712715e16 100644 --- a/esphome/components/optolink/select/optolink_select.h +++ b/esphome/components/optolink/select/optolink_select.h @@ -24,8 +24,8 @@ class OptolinkSelect : public DatapointComponent, public esphome::select::Select }; protected: - void setup() override { setup_datapoint(); } - void update() override { datapoint_read_request(); } + void setup() override { setup_datapoint_(); } + void update() override { datapoint_read_request_(); } void control(const std::string &value) override; const StringRef &get_component_name() override { return get_name(); } diff --git a/esphome/components/optolink/sensor/optolink_sensor.cpp b/esphome/components/optolink/sensor/optolink_sensor.cpp index a1c2df7815..dab0d6ccb4 100644 --- a/esphome/components/optolink/sensor/optolink_sensor.cpp +++ b/esphome/components/optolink/sensor/optolink_sensor.cpp @@ -10,6 +10,7 @@ static const char *const TAG = "optolink.sensor"; void OptolinkSensor::set_min_value(float min_value) { min_value_ = -29.3; } +// NOLINTBEGIN void OptolinkSensor::datapoint_value_changed(uint8_t state) { if (min_value_ >= 0.0) { publish_state(state); @@ -33,6 +34,7 @@ void OptolinkSensor::datapoint_value_changed(uint32_t state) { publish_state((int32_t) state); } }; +// NOLINTEND } // namespace optolink } // namespace esphome diff --git a/esphome/components/optolink/sensor/optolink_sensor.h b/esphome/components/optolink/sensor/optolink_sensor.h index 59e9d4bdb7..3bfb0e8ddd 100644 --- a/esphome/components/optolink/sensor/optolink_sensor.h +++ b/esphome/components/optolink/sensor/optolink_sensor.h @@ -19,8 +19,8 @@ class OptolinkSensor : public DatapointComponent, public esphome::sensor::Sensor void set_min_value(float min_value); protected: - void setup() { setup_datapoint(); } - void update() override { datapoint_read_request(); } + void setup() override { setup_datapoint_(); } + void update() override { datapoint_read_request_(); } const StringRef &get_component_name() override { return get_name(); } void datapoint_value_changed(float state) override { publish_state(state); }; diff --git a/esphome/components/optolink/switch/optolink_switch.cpp b/esphome/components/optolink/switch/optolink_switch.cpp index cfd14e287f..43182287c3 100644 --- a/esphome/components/optolink/switch/optolink_switch.cpp +++ b/esphome/components/optolink/switch/optolink_switch.cpp @@ -10,11 +10,11 @@ static const char *const TAG = "optolink.switch"; void OptolinkSwitch::write_state(bool value) { if (value != 0 && value != 1) { - set_optolink_state("datapoint value of switch %s not 0 or 1", get_component_name().c_str()); + set_optolink_state_("datapoint value of switch %s not 0 or 1", get_component_name().c_str()); ESP_LOGE(TAG, "datapoint value of switch %s not 0 or 1", get_component_name().c_str()); } else { ESP_LOGI(TAG, "control of switch %s to value %d", get_component_name().c_str(), value); - write_datapoint_value((uint8_t) value); + write_datapoint_value_((uint8_t) value); publish_state(value); } }; diff --git a/esphome/components/optolink/switch/optolink_switch.h b/esphome/components/optolink/switch/optolink_switch.h index 75cbe85c36..880e66618a 100644 --- a/esphome/components/optolink/switch/optolink_switch.h +++ b/esphome/components/optolink/switch/optolink_switch.h @@ -17,8 +17,8 @@ class OptolinkSwitch : public DatapointComponent, public esphome::switch_::Switc } protected: - void setup() override { setup_datapoint(); } - void update() override { datapoint_read_request(); } + void setup() override { setup_datapoint_(); } + void update() override { datapoint_read_request_(); } void write_state(bool value) override; const StringRef &get_component_name() override { return get_name(); } diff --git a/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp b/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp index 9d1d8d1e32..d10f1af6c1 100644 --- a/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp +++ b/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp @@ -84,20 +84,20 @@ void OptolinkTextSensor::setup() { case DAY_SCHEDULE: set_div_ratio(0); set_bytes(8); - set_address(get_address() + 8 * dow_); + set_address(get_address_() + 8 * dow_); break; case DAY_SCHEDULE_SYNCHRONIZED: set_writeable(true); set_div_ratio(0); set_bytes(8); - set_address(get_address() + 8 * dow_); + set_address(get_address_() + 8 * dow_); ESP_LOGI(TAG, "subscribing to schedule plan from HASS entity '%s' for component %s", this->entity_id_.c_str(), get_component_name().c_str()); - subscribe_hass(entity_id_, [this](const std::string &state) { + subscribe_hass_(entity_id_, [this](const std::string &state) { ESP_LOGD(TAG, "update for schedule plan for component %s: %s", get_component_name().c_str(), state.c_str()); uint8_t *data = encode_time_string(state); if (data) { - write_datapoint_value(data, 8); + write_datapoint_value_(data, 8); } else { ESP_LOGW(TAG, "not changing any value of datapoint %s", get_component_name().c_str()); } @@ -112,14 +112,14 @@ void OptolinkTextSensor::setup() { set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC); return; // no datapoint setup! } - setup_datapoint(); + setup_datapoint_(); }; void OptolinkTextSensor::update() { if (mode_ == STATE_INFO) { - publish_state(get_optolink_state()); + publish_state(get_optolink_state_()); } else { - datapoint_read_request(); + datapoint_read_request_(); } } @@ -143,13 +143,13 @@ void OptolinkTextSensor::datapoint_value_changed(uint8_t *value, size_t length) } publish_state(buffer); } else { - unfitting_value_type(); + unfitting_value_type_(); } break; case DEVICE_INFO: case STATE_INFO: case MAP: - unfitting_value_type(); + unfitting_value_type_(); break; } };