fixed more clang-tidy issues

This commit is contained in:
j0ta29 2024-02-19 20:44:40 +00:00
parent 6ea0f00dfb
commit c296453639
12 changed files with 59 additions and 64 deletions

View file

@ -23,7 +23,7 @@ class OptolinkBinarySensor : public DatapointComponent,
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); };
void datapoint_value_changed(uint8_t value) override { publish_state(value); };
};
} // namespace optolink
} // namespace esphome

View file

@ -259,7 +259,7 @@ void DatapointComponent::set_optolink_state_(const char *format, ...) {
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_(const 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);
@ -273,13 +273,13 @@ void DatapointComponent::subscribe_hass_(std::string entity_id, std::function<vo
#ifdef USE_API
if (api::global_api_server != nullptr) {
api::global_api_server->subscribe_home_assistant_state(
entity_id, optional<std::string>(), [this, entity_id](const std::string &state) {
entity_id, optional<std::string>(), [entity_id](const std::string &state) {
ESP_LOGD(TAG, "received schedule plan from HASS entity '%s': %s", entity_id.c_str(), state.c_str());
for (auto &subscription : hass_subscriptions_) {
if (subscription.last_state != state) {
if (subscription.entity_id == entity_id) {
subscription.last_state = state;
for (auto callback : subscription.callbacks) {
for (const auto &callback : subscription.callbacks) {
callback(state);
}
}

View file

@ -55,7 +55,7 @@ class DatapointComponent {
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_(const std::string entity_id, std::function<void(std::string)> f);
private:
const size_t max_retries_until_reset_ = 10;

View file

@ -19,27 +19,27 @@ void OptolinkNumber::control(float value) {
}
};
void OptolinkNumber::datapoint_value_changed(uint8_t state) {
void OptolinkNumber::datapoint_value_changed(uint8_t value) {
if (traits.get_min_value() >= 0) {
publish_state(state);
publish_state(value);
} else {
publish_state((int8_t) state);
publish_state((int8_t) value);
}
};
void OptolinkNumber::datapoint_value_changed(uint16_t state) {
void OptolinkNumber::datapoint_value_changed(uint16_t value) {
if (traits.get_min_value() >= 0) {
publish_state(state);
publish_state(value);
} else {
publish_state((int16_t) state);
publish_state((int16_t) value);
}
};
void OptolinkNumber::datapoint_value_changed(uint32_t state) {
void OptolinkNumber::datapoint_value_changed(uint32_t value) {
if (traits.get_min_value() >= 0) {
publish_state(state);
publish_state(value);
} else {
publish_state((int32_t) state);
publish_state((int32_t) value);
}
};

View file

@ -19,10 +19,10 @@ class OptolinkNumber : public DatapointComponent, public esphome::number::Number
void control(float value) override;
const StringRef &get_component_name() override { return get_name(); }
void datapoint_value_changed(float state) override { publish_state(state); };
void datapoint_value_changed(uint8_t state) override;
void datapoint_value_changed(uint16_t state) override;
void datapoint_value_changed(uint32_t state) override;
void datapoint_value_changed(float value) override { publish_state(value); };
void datapoint_value_changed(uint8_t value) override;
void datapoint_value_changed(uint16_t value) override;
void datapoint_value_changed(uint32_t value) override;
};
} // namespace optolink

View file

@ -23,33 +23,33 @@ void OptolinkSelect::control(const std::string &value) {
}
};
void OptolinkSelect::datapoint_value_changed(std::string key) {
auto pos = mapping_->find(key);
void OptolinkSelect::datapoint_value_changed(std::string value) {
auto pos = mapping_->find(value);
if (pos == mapping_->end()) {
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());
set_optolink_state_("value %s not found in select %s", value.c_str(), get_component_name().c_str());
ESP_LOGE(TAG, "value %s not found in select %s", value.c_str(), get_component_name().c_str());
} else {
publish_state(pos->second);
}
}
void OptolinkSelect::datapoint_value_changed(uint8_t state) {
std::string key = std::to_string(state);
void OptolinkSelect::datapoint_value_changed(uint8_t value) {
std::string key = std::to_string(value);
datapoint_value_changed(key);
}
void OptolinkSelect::datapoint_value_changed(uint16_t state) {
std::string key = std::to_string(state);
void OptolinkSelect::datapoint_value_changed(uint16_t value) {
std::string key = std::to_string(value);
datapoint_value_changed(key);
}
void OptolinkSelect::datapoint_value_changed(uint32_t state) {
std::string key = std::to_string(state);
void OptolinkSelect::datapoint_value_changed(uint32_t value) {
std::string key = std::to_string(value);
datapoint_value_changed(key);
}
void OptolinkSelect::datapoint_value_changed(float state) {
std::string key = std::to_string(state);
void OptolinkSelect::datapoint_value_changed(float value) {
std::string key = std::to_string(value);
datapoint_value_changed(key);
}

View file

@ -29,11 +29,11 @@ class OptolinkSelect : public DatapointComponent, public esphome::select::Select
void control(const std::string &value) override;
const StringRef &get_component_name() override { return get_name(); }
void datapoint_value_changed(std::string state) override;
void datapoint_value_changed(uint8_t state) override;
void datapoint_value_changed(uint16_t state) override;
void datapoint_value_changed(uint32_t state) override;
void datapoint_value_changed(float state) override;
void datapoint_value_changed(std::string value) override;
void datapoint_value_changed(uint8_t value) override;
void datapoint_value_changed(uint16_t value) override;
void datapoint_value_changed(uint32_t value) override;
void datapoint_value_changed(float value) override;
private:
std::map<std::string, std::string> *mapping_ = nullptr;

View file

@ -11,27 +11,27 @@ 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) {
void OptolinkSensor::datapoint_value_changed(uint8_t value) {
if (min_value_ >= 0.0) {
publish_state(state);
publish_state(value);
} else {
publish_state((int8_t) state);
publish_state((int8_t) value);
}
};
void OptolinkSensor::datapoint_value_changed(uint16_t state) {
void OptolinkSensor::datapoint_value_changed(uint16_t value) {
if (min_value_ >= 0.0) {
publish_state(state);
publish_state(value);
} else {
publish_state((int16_t) state);
publish_state((int16_t) value);
}
}
void OptolinkSensor::datapoint_value_changed(uint32_t state) {
void OptolinkSensor::datapoint_value_changed(uint32_t value) {
if (min_value_ >= 0.0) {
publish_state(state);
publish_state(value);
} else {
publish_state((int32_t) state);
publish_state((int32_t) value);
}
};
// NOLINTEND

View file

@ -23,10 +23,10 @@ class OptolinkSensor : public DatapointComponent, public esphome::sensor::Sensor
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); };
void datapoint_value_changed(uint8_t state) override;
void datapoint_value_changed(uint16_t state) override;
void datapoint_value_changed(uint32_t state) override;
void datapoint_value_changed(float value) override { publish_state(value); };
void datapoint_value_changed(uint8_t value) override;
void datapoint_value_changed(uint16_t value) override;
void datapoint_value_changed(uint32_t value) override;
private:
float min_value_ = -FLT_MAX;

View file

@ -22,7 +22,7 @@ class OptolinkSwitch : public DatapointComponent, public esphome::switch_::Switc
void write_state(bool value) override;
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 value) override { publish_state(state); };
};
} // namespace optolink

View file

@ -16,17 +16,14 @@ struct Time {
};
bool check_time_sequence(const Time &t1, const Time &t2) {
if (t2.hours > t1.hours || (t2.hours == t1.hours && t2.minutes >= t1.minutes)) {
return true;
}
return false;
return t2.hours > t1.hours || (t2.hours == t1.hours && t2.minutes >= t1.minutes);
}
bool check_time_values(const Time &time) {
return (time.hours >= 0 && time.hours <= 23) && (time.minutes >= 0 && time.minutes <= 59);
}
uint8_t *encode_time_string(std::string input) {
uint8_t *encode_time_string(const std::string input) {
char buffer[49];
strncpy(buffer, input.c_str(), sizeof(buffer));
buffer[sizeof(buffer) - 1] = 0x00;
@ -45,18 +42,18 @@ uint8_t *encode_time_string(std::string input) {
ESP_LOGE(
TAG,
"Time values should be in the format hh:mm and in increasing order within the range of 00:00 to 23:59");
return 0;
return nullptr;
}
} else {
ESP_LOGE(TAG, "Invalid time format");
return 0;
return nullptr;
}
token = strtok(nullptr, " ");
}
if (time_count % 2) {
ESP_LOGE(TAG, "Number of time values must be even");
return 0;
return nullptr;
}
while (time_count < 8) {
@ -64,11 +61,9 @@ uint8_t *encode_time_string(std::string input) {
}
static uint8_t data[8];
// ESP_LOGD(TAG, "Parsed time values:");
for (int i = 0; i < 8; i++) {
Time time = time_values[i];
data[i] = (time.hours << 3) + (time.minutes / 10);
// ESP_LOGD(TAG, " %02d:%02d => %d", time.hours, time.minutes, data[i]);
}
return data;

View file

@ -26,11 +26,11 @@ class OptolinkTextSensor : public DatapointComponent,
void update() override;
const StringRef &get_component_name() override { return get_name(); }
void datapoint_value_changed(float state) override { publish_state(std::to_string(state)); };
void datapoint_value_changed(uint8_t state) override { publish_state(std::to_string(state)); };
void datapoint_value_changed(uint16_t state) override { publish_state(std::to_string(state)); };
void datapoint_value_changed(uint32_t state) override;
void datapoint_value_changed(uint8_t *state, size_t length) override;
void datapoint_value_changed(float value) override { publish_state(std::to_string(value)); };
void datapoint_value_changed(uint8_t value) override { publish_state(std::to_string(value)); };
void datapoint_value_changed(uint16_t value) override { publish_state(std::to_string(value)); };
void datapoint_value_changed(uint32_t value) override;
void datapoint_value_changed(uint8_t *value, size_t length) override;
private:
TextSensorMode mode_ = MAP;