mirror of
https://github.com/esphome/esphome.git
synced 2024-12-05 13:54:09 +01:00
fixed clang-tidy issues
This commit is contained in:
parent
b4feed3669
commit
6ea0f00dfb
@ -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); };
|
||||
|
@ -12,7 +12,7 @@ namespace optolink {
|
||||
static const char *const TAG = "optolink.datapoint_component";
|
||||
static std::vector<HassSubscription> hass_subscriptions_;
|
||||
|
||||
void DatapointComponent::setup_datapoint() {
|
||||
void DatapointComponent::setup_datapoint_() {
|
||||
switch (div_ratio_) {
|
||||
case 0:
|
||||
datapoint_ = new Datapoint<convRaw>(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<void(std::string)> f) {
|
||||
void DatapointComponent::subscribe_hass_(std::string entity_id, std::function<void(std::string)> f) {
|
||||
for (auto &subscription : hass_subscriptions_) {
|
||||
if (subscription.entity_id == entity_id) {
|
||||
subscription.callbacks.push_back(f);
|
||||
|
@ -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<void(std::string)> f);
|
||||
void subscribe_hass_(std::string entity_id, std::function<void(std::string)> 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
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
@ -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(); }
|
||||
|
@ -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);
|
||||
|
@ -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(); }
|
||||
|
@ -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
|
||||
|
@ -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); };
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
@ -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(); }
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user