mirror of
https://github.com/esphome/esphome.git
synced 2024-12-11 07:54:54 +01:00
fixed more clang-tidy issues
This commit is contained in:
parent
6ea0f00dfb
commit
c296453639
12 changed files with 59 additions and 64 deletions
|
@ -23,7 +23,7 @@ class OptolinkBinarySensor : public DatapointComponent,
|
||||||
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 value) override { publish_state(value); };
|
||||||
};
|
};
|
||||||
} // namespace optolink
|
} // namespace optolink
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -259,7 +259,7 @@ void DatapointComponent::set_optolink_state_(const char *format, ...) {
|
||||||
|
|
||||||
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_(const 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);
|
||||||
|
@ -273,13 +273,13 @@ void DatapointComponent::subscribe_hass_(std::string entity_id, std::function<vo
|
||||||
#ifdef USE_API
|
#ifdef USE_API
|
||||||
if (api::global_api_server != nullptr) {
|
if (api::global_api_server != nullptr) {
|
||||||
api::global_api_server->subscribe_home_assistant_state(
|
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());
|
ESP_LOGD(TAG, "received schedule plan from HASS entity '%s': %s", entity_id.c_str(), state.c_str());
|
||||||
for (auto &subscription : hass_subscriptions_) {
|
for (auto &subscription : hass_subscriptions_) {
|
||||||
if (subscription.last_state != state) {
|
if (subscription.last_state != state) {
|
||||||
if (subscription.entity_id == entity_id) {
|
if (subscription.entity_id == entity_id) {
|
||||||
subscription.last_state = state;
|
subscription.last_state = state;
|
||||||
for (auto callback : subscription.callbacks) {
|
for (const auto &callback : subscription.callbacks) {
|
||||||
callback(state);
|
callback(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class DatapointComponent {
|
||||||
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_(const 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;
|
||||||
|
|
|
@ -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) {
|
if (traits.get_min_value() >= 0) {
|
||||||
publish_state(state);
|
publish_state(value);
|
||||||
} else {
|
} 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) {
|
if (traits.get_min_value() >= 0) {
|
||||||
publish_state(state);
|
publish_state(value);
|
||||||
} else {
|
} 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) {
|
if (traits.get_min_value() >= 0) {
|
||||||
publish_state(state);
|
publish_state(value);
|
||||||
} else {
|
} else {
|
||||||
publish_state((int32_t) state);
|
publish_state((int32_t) value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ class OptolinkNumber : public DatapointComponent, public esphome::number::Number
|
||||||
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(); }
|
||||||
void datapoint_value_changed(float state) override { publish_state(state); };
|
void datapoint_value_changed(float value) override { publish_state(value); };
|
||||||
void datapoint_value_changed(uint8_t state) override;
|
void datapoint_value_changed(uint8_t value) override;
|
||||||
void datapoint_value_changed(uint16_t state) override;
|
void datapoint_value_changed(uint16_t value) override;
|
||||||
void datapoint_value_changed(uint32_t state) override;
|
void datapoint_value_changed(uint32_t value) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace optolink
|
} // namespace optolink
|
||||||
|
|
|
@ -23,33 +23,33 @@ void OptolinkSelect::control(const std::string &value) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void OptolinkSelect::datapoint_value_changed(std::string key) {
|
void OptolinkSelect::datapoint_value_changed(std::string value) {
|
||||||
auto pos = mapping_->find(key);
|
auto pos = mapping_->find(value);
|
||||||
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", value.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", value.c_str(), get_component_name().c_str());
|
||||||
} else {
|
} else {
|
||||||
publish_state(pos->second);
|
publish_state(pos->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptolinkSelect::datapoint_value_changed(uint8_t state) {
|
void OptolinkSelect::datapoint_value_changed(uint8_t value) {
|
||||||
std::string key = std::to_string(state);
|
std::string key = std::to_string(value);
|
||||||
datapoint_value_changed(key);
|
datapoint_value_changed(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptolinkSelect::datapoint_value_changed(uint16_t state) {
|
void OptolinkSelect::datapoint_value_changed(uint16_t value) {
|
||||||
std::string key = std::to_string(state);
|
std::string key = std::to_string(value);
|
||||||
datapoint_value_changed(key);
|
datapoint_value_changed(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptolinkSelect::datapoint_value_changed(uint32_t state) {
|
void OptolinkSelect::datapoint_value_changed(uint32_t value) {
|
||||||
std::string key = std::to_string(state);
|
std::string key = std::to_string(value);
|
||||||
datapoint_value_changed(key);
|
datapoint_value_changed(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptolinkSelect::datapoint_value_changed(float state) {
|
void OptolinkSelect::datapoint_value_changed(float value) {
|
||||||
std::string key = std::to_string(state);
|
std::string key = std::to_string(value);
|
||||||
datapoint_value_changed(key);
|
datapoint_value_changed(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ class OptolinkSelect : public DatapointComponent, public esphome::select::Select
|
||||||
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(); }
|
||||||
void datapoint_value_changed(std::string state) override;
|
void datapoint_value_changed(std::string value) override;
|
||||||
void datapoint_value_changed(uint8_t state) override;
|
void datapoint_value_changed(uint8_t value) override;
|
||||||
void datapoint_value_changed(uint16_t state) override;
|
void datapoint_value_changed(uint16_t value) override;
|
||||||
void datapoint_value_changed(uint32_t state) override;
|
void datapoint_value_changed(uint32_t value) override;
|
||||||
void datapoint_value_changed(float state) override;
|
void datapoint_value_changed(float value) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> *mapping_ = nullptr;
|
std::map<std::string, std::string> *mapping_ = nullptr;
|
||||||
|
|
|
@ -11,27 +11,27 @@ 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
|
// NOLINTBEGIN
|
||||||
void OptolinkSensor::datapoint_value_changed(uint8_t state) {
|
void OptolinkSensor::datapoint_value_changed(uint8_t value) {
|
||||||
if (min_value_ >= 0.0) {
|
if (min_value_ >= 0.0) {
|
||||||
publish_state(state);
|
publish_state(value);
|
||||||
} else {
|
} 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) {
|
if (min_value_ >= 0.0) {
|
||||||
publish_state(state);
|
publish_state(value);
|
||||||
} else {
|
} 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) {
|
if (min_value_ >= 0.0) {
|
||||||
publish_state(state);
|
publish_state(value);
|
||||||
} else {
|
} else {
|
||||||
publish_state((int32_t) state);
|
publish_state((int32_t) value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// NOLINTEND
|
// NOLINTEND
|
||||||
|
|
|
@ -23,10 +23,10 @@ class OptolinkSensor : public DatapointComponent, public esphome::sensor::Sensor
|
||||||
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 value) override { publish_state(value); };
|
||||||
void datapoint_value_changed(uint8_t state) override;
|
void datapoint_value_changed(uint8_t value) override;
|
||||||
void datapoint_value_changed(uint16_t state) override;
|
void datapoint_value_changed(uint16_t value) override;
|
||||||
void datapoint_value_changed(uint32_t state) override;
|
void datapoint_value_changed(uint32_t value) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float min_value_ = -FLT_MAX;
|
float min_value_ = -FLT_MAX;
|
||||||
|
|
|
@ -22,7 +22,7 @@ class OptolinkSwitch : public DatapointComponent, public esphome::switch_::Switc
|
||||||
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(); }
|
||||||
void datapoint_value_changed(uint8_t state) override { publish_state(state); };
|
void datapoint_value_changed(uint8_t value) override { publish_state(state); };
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace optolink
|
} // namespace optolink
|
||||||
|
|
|
@ -16,17 +16,14 @@ struct Time {
|
||||||
};
|
};
|
||||||
|
|
||||||
bool check_time_sequence(const Time &t1, const Time &t2) {
|
bool check_time_sequence(const Time &t1, const Time &t2) {
|
||||||
if (t2.hours > t1.hours || (t2.hours == t1.hours && t2.minutes >= t1.minutes)) {
|
return t2.hours > t1.hours || (t2.hours == t1.hours && t2.minutes >= t1.minutes);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_time_values(const Time &time) {
|
bool check_time_values(const Time &time) {
|
||||||
return (time.hours >= 0 && time.hours <= 23) && (time.minutes >= 0 && time.minutes <= 59);
|
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];
|
char buffer[49];
|
||||||
strncpy(buffer, input.c_str(), sizeof(buffer));
|
strncpy(buffer, input.c_str(), sizeof(buffer));
|
||||||
buffer[sizeof(buffer) - 1] = 0x00;
|
buffer[sizeof(buffer) - 1] = 0x00;
|
||||||
|
@ -45,18 +42,18 @@ uint8_t *encode_time_string(std::string input) {
|
||||||
ESP_LOGE(
|
ESP_LOGE(
|
||||||
TAG,
|
TAG,
|
||||||
"Time values should be in the format hh:mm and in increasing order within the range of 00:00 to 23:59");
|
"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 {
|
} else {
|
||||||
ESP_LOGE(TAG, "Invalid time format");
|
ESP_LOGE(TAG, "Invalid time format");
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
token = strtok(nullptr, " ");
|
token = strtok(nullptr, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time_count % 2) {
|
if (time_count % 2) {
|
||||||
ESP_LOGE(TAG, "Number of time values must be even");
|
ESP_LOGE(TAG, "Number of time values must be even");
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (time_count < 8) {
|
while (time_count < 8) {
|
||||||
|
@ -64,11 +61,9 @@ uint8_t *encode_time_string(std::string input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t data[8];
|
static uint8_t data[8];
|
||||||
// ESP_LOGD(TAG, "Parsed time values:");
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
Time time = time_values[i];
|
Time time = time_values[i];
|
||||||
data[i] = (time.hours << 3) + (time.minutes / 10);
|
data[i] = (time.hours << 3) + (time.minutes / 10);
|
||||||
// ESP_LOGD(TAG, " %02d:%02d => %d", time.hours, time.minutes, data[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -26,11 +26,11 @@ class OptolinkTextSensor : public DatapointComponent,
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
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(std::to_string(state)); };
|
void datapoint_value_changed(float value) override { publish_state(std::to_string(value)); };
|
||||||
void datapoint_value_changed(uint8_t state) override { publish_state(std::to_string(state)); };
|
void datapoint_value_changed(uint8_t value) override { publish_state(std::to_string(value)); };
|
||||||
void datapoint_value_changed(uint16_t state) override { publish_state(std::to_string(state)); };
|
void datapoint_value_changed(uint16_t value) override { publish_state(std::to_string(value)); };
|
||||||
void datapoint_value_changed(uint32_t state) override;
|
void datapoint_value_changed(uint32_t value) override;
|
||||||
void datapoint_value_changed(uint8_t *state, size_t length) override;
|
void datapoint_value_changed(uint8_t *value, size_t length) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextSensorMode mode_ = MAP;
|
TextSensorMode mode_ = MAP;
|
||||||
|
|
Loading…
Reference in a new issue