fixed clang-tidy issues

This commit is contained in:
j0ta29 2024-02-18 17:05:04 +00:00
parent b4feed3669
commit 6ea0f00dfb
12 changed files with 86 additions and 85 deletions

View file

@ -19,8 +19,8 @@ class OptolinkBinarySensor : public DatapointComponent,
} }
protected: protected:
void setup() override { setup_datapoint(); } void setup() override { setup_datapoint_(); }
void update() override { datapoint_read_request(); } void update() override { datapoint_read_request_(); }
const StringRef &get_component_name() override { return get_name(); } const StringRef &get_component_name() override { return get_name(); }
void datapoint_value_changed(uint8_t state) override { publish_state(state); }; void datapoint_value_changed(uint8_t state) override { publish_state(state); };

View file

@ -12,7 +12,7 @@ namespace optolink {
static const char *const TAG = "optolink.datapoint_component"; static const char *const TAG = "optolink.datapoint_component";
static std::vector<HassSubscription> hass_subscriptions_; static std::vector<HassSubscription> hass_subscriptions_;
void DatapointComponent::setup_datapoint() { void DatapointComponent::setup_datapoint_() {
switch (div_ratio_) { switch (div_ratio_) {
case 0: case 0:
datapoint_ = new Datapoint<convRaw>(get_component_name().c_str(), "optolink", address_, writeable_); datapoint_ = new Datapoint<convRaw>(get_component_name().c_str(), "optolink", address_, writeable_);
@ -56,7 +56,7 @@ void DatapointComponent::setup_datapoint() {
}); });
break; break;
default: default:
unfitting_value_type(); unfitting_value_type_();
} }
break; break;
case 10: case 10:
@ -78,7 +78,7 @@ void DatapointComponent::setup_datapoint() {
}); });
break; break;
default: default:
unfitting_value_type(); unfitting_value_type_();
} }
break; break;
case 100: case 100:
@ -92,7 +92,7 @@ void DatapointComponent::setup_datapoint() {
}); });
break; break;
default: default:
unfitting_value_type(); unfitting_value_type_();
} }
break; break;
case 1000: case 1000:
@ -120,16 +120,16 @@ void DatapointComponent::setup_datapoint() {
} }
break; break;
default: default:
unfitting_value_type(); unfitting_value_type_();
} }
} }
void DatapointComponent::datapoint_read_request() { void DatapointComponent::datapoint_read_request_() {
if (is_dp_value_writing_outstanding) { if (is_dp_value_writing_outstanding_) {
ESP_LOGI(TAG, "read request for %s deferred due to outstanding write request", get_component_name().c_str()); 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 { } 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_)) { if (optolink_->read_value(datapoint_)) {
read_retries_ = 1; 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()); 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_) { if (!writeable_) {
optolink_->set_state("trying to control not writable datapoint %s", get_component_name().c_str()); 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()); 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); ESP_LOGI(TAG, "trying to update datapoint %s value: %s", get_component_name().c_str(), buffer);
#endif #endif
dp_value_outstanding = dp_value; dp_value_outstanding_ = dp_value;
if (optolink_->write_value(datapoint_, dp_value_outstanding)) { if (optolink_->write_value(datapoint_, dp_value_outstanding_)) {
is_dp_value_writing_outstanding = false; is_dp_value_writing_outstanding_ = false;
} else { } else {
ESP_LOGW(TAG, "write request for %s rejected due to outstanding running request - increase update_interval!", ESP_LOGW(TAG, "write request for %s rejected due to outstanding running request - increase update_interval!",
get_component_name().c_str()); 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) { if (div_ratio_ > 1) {
datapoint_write_request(DPValue(value)); datapoint_write_request_(DPValue(value));
} else if (div_ratio_ == 1) { } else if (div_ratio_ == 1) {
switch (bytes_) { switch (bytes_) {
case 1: case 1:
datapoint_write_request(DPValue((uint8_t) value)); datapoint_write_request_(DPValue((uint8_t) value));
break; break;
case 2: case 2:
datapoint_write_request(DPValue((uint16_t) value)); datapoint_write_request_(DPValue((uint16_t) value));
break; break;
case 4: case 4:
datapoint_write_request(DPValue((uint32_t) value)); datapoint_write_request_(DPValue((uint32_t) value));
break; break;
default: default:
unfitting_value_type(); unfitting_value_type_();
break; break;
} }
} else { } 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) { if (bytes_ == 1 && div_ratio_ == 1) {
datapoint_write_request(DPValue(value)); datapoint_write_request_(DPValue(value));
} else { } 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) { if (bytes_ == 2 && div_ratio_ == 1) {
datapoint_write_request(DPValue(value)); datapoint_write_request_(DPValue(value));
} else { } 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) { if (bytes_ == 4 && div_ratio_ == 1) {
datapoint_write_request(DPValue(value)); datapoint_write_request_(DPValue(value));
} else { } 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) { if (bytes_ == length && div_ratio_ == 0) {
datapoint_write_request(DPValue(value, length)); datapoint_write_request_(DPValue(value, length));
} else { } 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()); 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()); 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_list args;
va_start(args, format); va_start(args, format);
char buffer[128]; char buffer[128];
@ -257,9 +257,9 @@ void DatapointComponent::set_optolink_state(const char *format, ...) {
optolink_->set_state(buffer); 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<void(std::string)> f) { void DatapointComponent::subscribe_hass_(std::string entity_id, std::function<void(std::string)> f) {
for (auto &subscription : hass_subscriptions_) { for (auto &subscription : hass_subscriptions_) {
if (subscription.entity_id == entity_id) { if (subscription.entity_id == entity_id) {
subscription.callbacks.push_back(f); subscription.callbacks.push_back(f);

View file

@ -19,7 +19,7 @@ struct HassSubscription {
class DatapointComponent { class DatapointComponent {
public: 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; optolink_ = optolink;
writeable_ = writeable; writeable_ = writeable;
} }
@ -32,11 +32,11 @@ class DatapointComponent {
protected: protected:
virtual const StringRef &get_component_name() = 0; 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(float value);
virtual void datapoint_value_changed(uint8_t 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(std::string value);
virtual void datapoint_value_changed(uint8_t *value, size_t length); virtual void datapoint_value_changed(uint8_t *value, size_t length);
void write_datapoint_value(float value); void write_datapoint_value_(float value);
void write_datapoint_value(uint8_t value); void write_datapoint_value_(uint8_t value);
void write_datapoint_value(uint16_t value); void write_datapoint_value_(uint16_t value);
void write_datapoint_value(uint32_t value); void write_datapoint_value_(uint32_t value);
void write_datapoint_value(uint8_t *value, size_t length); void write_datapoint_value_(uint8_t *value, size_t length);
void unfitting_value_type(); void unfitting_value_type_();
void set_optolink_state(const char *format, ...); void set_optolink_state_(const char *format, ...);
std::string get_optolink_state(); std::string get_optolink_state_();
void subscribe_hass(std::string entity_id, std::function<void(std::string)> f); void subscribe_hass_(std::string entity_id, std::function<void(std::string)> f);
private: private:
const size_t MAX_RETRIES_UNTIL_RESET = 10; const size_t max_retries_until_reset_ = 10;
Optolink *optolink_; Optolink *optolink_;
IDatapoint *datapoint_ = nullptr; IDatapoint *datapoint_ = nullptr;
size_t read_retries_ = 0; size_t read_retries_ = 0;
@ -66,28 +66,27 @@ class DatapointComponent {
size_t bytes_; size_t bytes_;
uint32_t address_; uint32_t address_;
bool writeable_; bool writeable_;
bool is_dp_value_writing_outstanding_ = false;
DPValue dp_value_outstanding_;
bool is_dp_value_writing_outstanding = false; void datapoint_write_request_(DPValue dp_value);
DPValue dp_value_outstanding;
void datapoint_write_request(DPValue dp_value);
}; };
// NOLINTNEXTLINE // NOLINTBEGIN
class conv2_100_F : public DPType { class conv2_100_F : public DPType {
public: public:
void encode(uint8_t *out, DPValue in); void encode(uint8_t *out, DPValue in);
DPValue decode(const uint8_t *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 { class conv4_1000_F : public DPType {
public: public:
void encode(uint8_t *out, DPValue in); void encode(uint8_t *out, DPValue in);
DPValue decode(const uint8_t *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 optolink
} // namespace esphome } // namespace esphome

View file

@ -10,11 +10,11 @@ static const char *const TAG = "optolink.number";
void OptolinkNumber::control(float value) { void OptolinkNumber::control(float value) {
if (value > traits.get_max_value() || value < traits.get_min_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()); ESP_LOGE(TAG, "datapoint value of number %s not in allowed range", get_component_name().c_str());
} else { } else {
ESP_LOGI(TAG, "control of number %s to value %f", get_component_name().c_str(), value); 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); publish_state(value);
} }
}; };

View file

@ -14,8 +14,8 @@ class OptolinkNumber : public DatapointComponent, public esphome::number::Number
OptolinkNumber(Optolink *optolink) : DatapointComponent(optolink, true) {} OptolinkNumber(Optolink *optolink) : DatapointComponent(optolink, true) {}
protected: protected:
void setup() override { setup_datapoint(); } void setup() override { setup_datapoint_(); }
void update() override { datapoint_read_request(); } void update() override { datapoint_read_request_(); }
void control(float value) override; void control(float value) override;
const StringRef &get_component_name() override { return get_name(); } const StringRef &get_component_name() override { return get_name(); }

View file

@ -12,12 +12,12 @@ void OptolinkSelect::control(const std::string &value) {
for (auto it = mapping_->begin(); it != mapping_->end(); ++it) { for (auto it = mapping_->begin(); it != mapping_->end(); ++it) {
if (it->second == value) { if (it->second == value) {
ESP_LOGI(TAG, "control of select %s to value %s", get_component_name().c_str(), it->first.c_str()); 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); publish_state(it->second);
break; break;
} }
if (it == mapping_->end()) { 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()); 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) { void OptolinkSelect::datapoint_value_changed(std::string key) {
auto pos = mapping_->find(key); auto pos = mapping_->find(key);
if (pos == mapping_->end()) { 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()); ESP_LOGE(TAG, "value %s not found in select %s", key.c_str(), get_component_name().c_str());
} else { } else {
publish_state(pos->second); publish_state(pos->second);

View file

@ -24,8 +24,8 @@ class OptolinkSelect : public DatapointComponent, public esphome::select::Select
}; };
protected: protected:
void setup() override { setup_datapoint(); } void setup() override { setup_datapoint_(); }
void update() override { datapoint_read_request(); } void update() override { datapoint_read_request_(); }
void control(const std::string &value) override; void control(const std::string &value) override;
const StringRef &get_component_name() override { return get_name(); } const StringRef &get_component_name() override { return get_name(); }

View file

@ -10,6 +10,7 @@ static const char *const TAG = "optolink.sensor";
void OptolinkSensor::set_min_value(float min_value) { min_value_ = -29.3; } void OptolinkSensor::set_min_value(float min_value) { min_value_ = -29.3; }
// NOLINTBEGIN
void OptolinkSensor::datapoint_value_changed(uint8_t state) { void OptolinkSensor::datapoint_value_changed(uint8_t state) {
if (min_value_ >= 0.0) { if (min_value_ >= 0.0) {
publish_state(state); publish_state(state);
@ -33,6 +34,7 @@ void OptolinkSensor::datapoint_value_changed(uint32_t state) {
publish_state((int32_t) state); publish_state((int32_t) state);
} }
}; };
// NOLINTEND
} // namespace optolink } // namespace optolink
} // namespace esphome } // namespace esphome

View file

@ -19,8 +19,8 @@ class OptolinkSensor : public DatapointComponent, public esphome::sensor::Sensor
void set_min_value(float min_value); void set_min_value(float min_value);
protected: protected:
void setup() { setup_datapoint(); } void setup() override { setup_datapoint_(); }
void update() override { datapoint_read_request(); } void update() override { datapoint_read_request_(); }
const StringRef &get_component_name() override { return get_name(); } const StringRef &get_component_name() override { return get_name(); }
void datapoint_value_changed(float state) override { publish_state(state); }; void datapoint_value_changed(float state) override { publish_state(state); };

View file

@ -10,11 +10,11 @@ static const char *const TAG = "optolink.switch";
void OptolinkSwitch::write_state(bool value) { void OptolinkSwitch::write_state(bool value) {
if (value != 0 && value != 1) { 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()); ESP_LOGE(TAG, "datapoint value of switch %s not 0 or 1", get_component_name().c_str());
} else { } else {
ESP_LOGI(TAG, "control of switch %s to value %d", get_component_name().c_str(), value); 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); publish_state(value);
} }
}; };

View file

@ -17,8 +17,8 @@ class OptolinkSwitch : public DatapointComponent, public esphome::switch_::Switc
} }
protected: protected:
void setup() override { setup_datapoint(); } void setup() override { setup_datapoint_(); }
void update() override { datapoint_read_request(); } void update() override { datapoint_read_request_(); }
void write_state(bool value) override; void write_state(bool value) override;
const StringRef &get_component_name() override { return get_name(); } const StringRef &get_component_name() override { return get_name(); }

View file

@ -84,20 +84,20 @@ void OptolinkTextSensor::setup() {
case DAY_SCHEDULE: case DAY_SCHEDULE:
set_div_ratio(0); set_div_ratio(0);
set_bytes(8); set_bytes(8);
set_address(get_address() + 8 * dow_); set_address(get_address_() + 8 * dow_);
break; break;
case DAY_SCHEDULE_SYNCHRONIZED: case DAY_SCHEDULE_SYNCHRONIZED:
set_writeable(true); set_writeable(true);
set_div_ratio(0); set_div_ratio(0);
set_bytes(8); 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(), ESP_LOGI(TAG, "subscribing to schedule plan from HASS entity '%s' for component %s", this->entity_id_.c_str(),
get_component_name().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()); 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); uint8_t *data = encode_time_string(state);
if (data) { if (data) {
write_datapoint_value(data, 8); write_datapoint_value_(data, 8);
} else { } else {
ESP_LOGW(TAG, "not changing any value of datapoint %s", get_component_name().c_str()); 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); set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC);
return; // no datapoint setup! return; // no datapoint setup!
} }
setup_datapoint(); setup_datapoint_();
}; };
void OptolinkTextSensor::update() { void OptolinkTextSensor::update() {
if (mode_ == STATE_INFO) { if (mode_ == STATE_INFO) {
publish_state(get_optolink_state()); publish_state(get_optolink_state_());
} else { } 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); publish_state(buffer);
} else { } else {
unfitting_value_type(); unfitting_value_type_();
} }
break; break;
case DEVICE_INFO: case DEVICE_INFO:
case STATE_INFO: case STATE_INFO:
case MAP: case MAP:
unfitting_value_type(); unfitting_value_type_();
break; break;
} }
}; };