1
0
mirror of https://github.com/esphome/esphome.git synced 2025-01-13 10:07:09 +01:00

Activate some clang-tidy checks (#1884)

This commit is contained in:
Otto Winter 2021-06-10 13:04:40 +02:00 committed by GitHub
parent eb9bd69405
commit 360effcb72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
109 changed files with 458 additions and 422 deletions

View File

@ -5,30 +5,20 @@ Checks: >-
-android-*,
-boost-*,
-bugprone-branch-clone,
-bugprone-macro-parentheses,
-bugprone-narrowing-conversions,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-suspicious-include,
-bugprone-too-small-loop-variable,
-bugprone-unhandled-self-assignment,
-cert-dcl37-c,
-cert-dcl50-cpp,
-cert-dcl51-cpp,
-cert-err58-cpp,
-cert-oop54-cpp,
-cert-oop57-cpp,
-cert-str34-c,
-clang-analyzer-core.CallAndMessage,
-clang-analyzer-optin.*,
-clang-analyzer-optin.cplusplus.UninitializedObject,
-clang-analyzer-osx.*,
-clang-analyzer-security.*,
-clang-diagnostic-shadow-field,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-c-copy-assignment-signature,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions,
@ -45,17 +35,17 @@ Checks: >-
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-special-member-functions,
-fuchsia-*,
-fuchsia-default-arguments,
-fuchsia-multiple-inheritance,
-fuchsia-overloaded-operator,
-fuchsia-statically-constructed-objects,
-fuchsia-default-arguments-declarations,
-fuchsia-default-arguments-calls,
-google-build-using-namespace,
-google-explicit-constructor,
-google-readability-braces-around-statements,
-google-readability-casting,
-google-readability-todo,
-google-runtime-int,
-google-runtime-references,
-hicpp-*,
-llvm-else-after-return,
@ -65,12 +55,8 @@ Checks: >-
-llvmlibc-*,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
-misc-unconventional-assign-operator,
-misc-unused-parameters,
-modernize-avoid-c-arrays,
-modernize-deprecated-headers,
-modernize-pass-by-value,
-modernize-pass-by-value,
-modernize-return-braced-init-list,
-modernize-use-auto,
-modernize-use-default-member-init,
@ -78,7 +64,6 @@ Checks: >-
-modernize-use-trailing-return-type,
-mpi-*,
-objc-*,
-performance-unnecessary-value-param,
-readability-braces-around-statements,
-readability-const-return-type,
-readability-convert-member-functions-to-static,
@ -94,8 +79,7 @@ Checks: >-
-readability-redundant-string-init,
-readability-uppercase-literal-suffix,
-readability-use-anyofallof,
-warnings-as-errors,
-zircon-*
-warnings-as-errors
WarningsAsErrors: '*'
HeaderFilterRegex: '^.*/src/esphome/.*'
AnalyzeTemporaryDtors: false

View File

@ -21,8 +21,8 @@ void ADE7953::dump_config() {
}
#define ADE_PUBLISH_(name, factor) \
if (name && this->name##_sensor_) { \
float value = *name / factor; \
if ((name) && this->name##_sensor_) { \
float value = *(name) / (factor); \
this->name##_sensor_->publish_state(value); \
}
#define ADE_PUBLISH(name, factor) ADE_PUBLISH_(name, factor)

View File

@ -7,7 +7,7 @@ namespace apds9960 {
static const char *TAG = "apds9960";
#define APDS9960_ERROR_CHECK(func) \
if (!func) { \
if (!(func)) { \
this->mark_failed(); \
return; \
}

View File

@ -180,7 +180,7 @@ void APIServer::on_switch_update(switch_::Switch *obj, bool state) {
#endif
#ifdef USE_TEXT_SENSOR
void APIServer::on_text_sensor_update(text_sensor::TextSensor *obj, std::string state) {
void APIServer::on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state) {
if (obj->is_internal())
return;
for (auto *c : this->clients_)

View File

@ -56,7 +56,7 @@ class APIServer : public Component, public Controller {
void on_switch_update(switch_::Switch *obj, bool state) override;
#endif
#ifdef USE_TEXT_SENSOR
void on_text_sensor_update(text_sensor::TextSensor *obj, std::string state) override;
void on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state) override;
#endif
#ifdef USE_CLIMATE
void on_climate_update(climate::Climate *obj) override;

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "api_pb2.h"
@ -20,8 +22,8 @@ template<typename T> enums::ServiceArgType to_service_arg_type();
template<typename... Ts> class UserServiceBase : public UserServiceDescriptor {
public:
UserServiceBase(const std::string &name, const std::array<std::string, sizeof...(Ts)> &arg_names)
: name_(name), arg_names_(arg_names) {
UserServiceBase(std::string name, const std::array<std::string, sizeof...(Ts)> &arg_names)
: name_(std::move(name)), arg_names_(arg_names) {
this->key_ = fnv1_hash(this->name_);
}

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
@ -87,8 +89,8 @@ class DoubleClickTrigger : public Trigger<> {
class MultiClickTrigger : public Trigger<>, public Component {
public:
explicit MultiClickTrigger(BinarySensor *parent, const std::vector<MultiClickTriggerEvent> &timing)
: parent_(parent), timing_(timing) {}
explicit MultiClickTrigger(BinarySensor *parent, std::vector<MultiClickTriggerEvent> timing)
: parent_(parent), timing_(std::move(timing)) {}
void setup() override {
this->last_state_ = this->parent_->state;

View File

@ -61,7 +61,7 @@ void BinarySensor::add_filter(Filter *filter) {
last_filter->next_ = filter;
}
}
void BinarySensor::add_filters(std::vector<Filter *> filters) {
void BinarySensor::add_filters(const std::vector<Filter *> &filters) {
for (Filter *filter : filters) {
this->add_filter(filter);
}

View File

@ -9,10 +9,10 @@ namespace esphome {
namespace binary_sensor {
#define LOG_BINARY_SENSOR(prefix, type, obj) \
if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
if (!obj->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str()); \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, (obj)->get_name().c_str()); \
if (!(obj)->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \
} \
}
@ -60,7 +60,7 @@ class BinarySensor : public Nameable {
std::string get_device_class();
void add_filter(Filter *filter);
void add_filters(std::vector<Filter *> filters);
void add_filters(const std::vector<Filter *> &filters);
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)

View File

@ -1,5 +1,7 @@
#include "filter.h"
#include "binary_sensor.h"
#include <utility>
namespace esphome {
@ -64,7 +66,7 @@ float DelayedOffFilter::get_setup_priority() const { return setup_priority::HARD
optional<bool> InvertFilter::new_value(bool value, bool is_initial) { return !value; }
AutorepeatFilter::AutorepeatFilter(const std::vector<AutorepeatFilterTiming> &timings) : timings_(timings) {}
AutorepeatFilter::AutorepeatFilter(std::vector<AutorepeatFilterTiming> timings) : timings_(std::move(timings)) {}
optional<bool> AutorepeatFilter::new_value(bool value, bool is_initial) {
if (value) {
@ -108,7 +110,7 @@ void AutorepeatFilter::next_value_(bool val) {
float AutorepeatFilter::get_setup_priority() const { return setup_priority::HARDWARE; }
LambdaFilter::LambdaFilter(const std::function<optional<bool>(bool)> &f) : f_(f) {}
LambdaFilter::LambdaFilter(std::function<optional<bool>(bool)> f) : f_(std::move(f)) {}
optional<bool> LambdaFilter::new_value(bool value, bool is_initial) { return this->f_(value); }

View File

@ -79,7 +79,7 @@ struct AutorepeatFilterTiming {
class AutorepeatFilter : public Filter, public Component {
public:
explicit AutorepeatFilter(const std::vector<AutorepeatFilterTiming> &timings);
explicit AutorepeatFilter(std::vector<AutorepeatFilterTiming> timings);
optional<bool> new_value(bool value, bool is_initial) override;
@ -95,7 +95,7 @@ class AutorepeatFilter : public Filter, public Component {
class LambdaFilter : public Filter {
public:
explicit LambdaFilter(const std::function<optional<bool>(bool)> &f);
explicit LambdaFilter(std::function<optional<bool>(bool)> f);
optional<bool> new_value(bool value, bool is_initial) override;

View File

@ -11,8 +11,8 @@ namespace esphome {
namespace climate {
#define LOG_CLIMATE(prefix, type, obj) \
if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, (obj)->get_name().c_str()); \
}
class Climate;

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "esphome/components/climate/climate.h"
#include "esphome/components/remote_base/remote_base.h"
#include "esphome/components/remote_transmitter/remote_transmitter.h"
@ -27,8 +29,8 @@ class ClimateIR : public climate::Climate, public Component, public remote_base:
this->temperature_step_ = temperature_step;
this->supports_dry_ = supports_dry;
this->supports_fan_only_ = supports_fan_only;
this->fan_modes_ = fan_modes;
this->swing_modes_ = swing_modes;
this->fan_modes_ = std::move(fan_modes);
this->swing_modes_ = std::move(swing_modes);
}
void setup() override;

View File

@ -12,14 +12,14 @@ const extern float COVER_OPEN;
const extern float COVER_CLOSED;
#define LOG_COVER(prefix, type, obj) \
if (obj != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \
auto traits_ = obj->get_traits(); \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, (obj)->get_name().c_str()); \
auto traits_ = (obj)->get_traits(); \
if (traits_.get_is_assumed_state()) { \
ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
} \
if (!obj->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str()); \
if (!(obj)->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \
} \
}

View File

@ -9,7 +9,9 @@ namespace custom {
class CustomBinaryOutputConstructor {
public:
CustomBinaryOutputConstructor(std::function<std::vector<output::BinaryOutput *>()> init) { this->outputs_ = init(); }
CustomBinaryOutputConstructor(const std::function<std::vector<output::BinaryOutput *>()> &init) {
this->outputs_ = init();
}
output::BinaryOutput *get_output(int i) { return this->outputs_[i]; }
@ -19,7 +21,9 @@ class CustomBinaryOutputConstructor {
class CustomFloatOutputConstructor {
public:
CustomFloatOutputConstructor(std::function<std::vector<output::FloatOutput *>()> init) { this->outputs_ = init(); }
CustomFloatOutputConstructor(const std::function<std::vector<output::FloatOutput *>()> &init) {
this->outputs_ = init();
}
output::FloatOutput *get_output(int i) { return this->outputs_[i]; }

View File

@ -8,7 +8,7 @@ namespace custom {
class CustomSwitchConstructor : public Component {
public:
CustomSwitchConstructor(std::function<std::vector<switch_::Switch *>()> init) { this->switches_ = init(); }
CustomSwitchConstructor(const std::function<std::vector<switch_::Switch *>()> &init) { this->switches_ = init(); }
switch_::Switch *get_switch(int i) { return this->switches_[i]; }

View File

@ -8,7 +8,7 @@ namespace custom {
class CustomTextSensorConstructor : public Component {
public:
CustomTextSensorConstructor(std::function<std::vector<text_sensor::TextSensor *>()> init) {
CustomTextSensorConstructor(const std::function<std::vector<text_sensor::TextSensor *>()> &init) {
this->text_sensors_ = init();
}

View File

@ -103,7 +103,10 @@ class DFPlayer : public uart::UARTDevice, public Component {
};
#define DFPLAYER_SIMPLE_ACTION(ACTION_CLASS, ACTION_METHOD) \
template<typename... Ts> class ACTION_CLASS : public Action<Ts...>, public Parented<DFPlayer> { \
template<typename... Ts> \
class ACTION_CLASS : /* NOLINT */ \
public Action<Ts...>, \
public Parented<DFPlayer> { \
void play(Ts... x) override { this->parent_->ACTION_METHOD(); } \
};

View File

@ -1,7 +1,9 @@
#include "display_buffer.h"
#include "esphome/core/application.h"
#include "esphome/core/color.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
#include <utility>
namespace esphome {
namespace display {
@ -524,7 +526,7 @@ void Animation::next_frame() {
}
}
DisplayPage::DisplayPage(const display_writer_t &writer) : writer_(writer) {}
DisplayPage::DisplayPage(display_writer_t writer) : writer_(std::move(writer)) {}
void DisplayPage::show() { this->parent_->show_page(this); }
void DisplayPage::show_next() { this->next_->show(); }
void DisplayPage::show_prev() { this->prev_->show(); }

View File

@ -86,10 +86,10 @@ class DisplayOnPageChangeTrigger;
using display_writer_t = std::function<void(DisplayBuffer &)>;
#define LOG_DISPLAY(prefix, type, obj) \
if (obj != nullptr) { \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, prefix type); \
ESP_LOGCONFIG(TAG, "%s Rotations: %d °", prefix, obj->rotation_); \
ESP_LOGCONFIG(TAG, "%s Dimensions: %dpx x %dpx", prefix, obj->get_width(), obj->get_height()); \
ESP_LOGCONFIG(TAG, "%s Rotations: %d °", prefix, (obj)->rotation_); \
ESP_LOGCONFIG(TAG, "%s Dimensions: %dpx x %dpx", prefix, (obj)->get_width(), (obj)->get_height()); \
}
class DisplayBuffer {
@ -327,7 +327,7 @@ class DisplayBuffer {
class DisplayPage {
public:
DisplayPage(const display_writer_t &writer);
DisplayPage(display_writer_t writer);
void show();
void show_next();
void show_prev();

View File

@ -51,7 +51,7 @@ union E131RawPacket {
// We need to have at least one `1` value
// Get the offset of `property_values[1]`
const long E131_MIN_PACKET_SIZE = reinterpret_cast<long>(&((E131RawPacket *) nullptr)->property_values[1]);
const size_t E131_MIN_PACKET_SIZE = reinterpret_cast<size_t>(&((E131RawPacket *) nullptr)->property_values[1]);
bool E131Component::join_igmp_groups_() {
if (listen_method_ != E131_MULTICAST)

View File

@ -9,6 +9,11 @@
#include <eth_phy/phy_tlk110.h>
#include <lwip/dns.h>
/// Macro for IDF version comparision
#ifndef ESP_IDF_VERSION_VAL
#define ESP_IDF_VERSION_VAL(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
#endif
// Defined in WiFiGeneric.cpp, sets global initialized flag, starts network event task queue and calls
// tcpip_adapter_init()
extern void tcpipInit();

View File

@ -18,8 +18,8 @@ class EZOSensor : public sensor::Sensor, public PollingComponent, public i2c::I2
void set_tempcomp_value(float temp);
protected:
unsigned long start_time_ = 0;
unsigned long wait_time_ = 0;
uint32_t start_time_ = 0;
uint32_t wait_time_ = 0;
uint16_t state_ = 0;
float tempcomp_;
};

View File

@ -5,8 +5,9 @@ namespace fujitsu_general {
// bytes' bits are reversed for fujitsu, so nibbles are ordered 1, 0, 3, 2, 5, 4, etc...
#define SET_NIBBLE(message, nibble, value) (message[nibble / 2] |= (value & 0b00001111) << ((nibble % 2) ? 0 : 4))
#define GET_NIBBLE(message, nibble) ((message[nibble / 2] >> ((nibble % 2) ? 0 : 4)) & 0b00001111)
#define SET_NIBBLE(message, nibble, value) \
((message)[(nibble) / 2] |= ((value) &0b00001111) << (((nibble) % 2) ? 0 : 4))
#define GET_NIBBLE(message, nibble) (((message)[(nibble) / 2] >> (((nibble) % 2) ? 0 : 4)) & 0b00001111)
static const char *TAG = "fujitsu_general.climate";

View File

@ -73,7 +73,7 @@ const uint8_t HITACHI_AC344_MILDEWPROOF_OFFSET = 2; // Mask 0b00000x00
const uint16_t HITACHI_AC344_STATE_LENGTH = 43;
const uint16_t HITACHI_AC344_BITS = HITACHI_AC344_STATE_LENGTH * 8;
#define GETBIT8(a, b) (a & ((uint8_t) 1 << b))
#define GETBIT8(a, b) ((a) & ((uint8_t) 1 << (b)))
#define GETBITS8(data, offset, size) (((data) & (((uint8_t) UINT8_MAX >> (8 - (size))) << (offset))) >> (offset))
class HitachiClimate : public climate_ir::ClimateIR {

View File

@ -1,7 +1,5 @@
#pragma once
#include "Arduino.h"
namespace esphome {
namespace hm3301 {

View File

@ -1,3 +1,5 @@
#pragma once
#include "abstract_aqi_calculator.h"
namespace esphome {

View File

@ -1,8 +1,7 @@
#pragma once
#include "Arduino.h"
#include "caqi_calculator.cpp"
#include "aqi_calculator.cpp"
#include "caqi_calculator.h"
#include "aqi_calculator.h"
namespace esphome {
namespace hm3301 {

View File

@ -1,3 +1,5 @@
#pragma once
#include "esphome/core/log.h"
#include "abstract_aqi_calculator.h"

View File

@ -8,30 +8,31 @@ namespace homeassistant {
static const char *TAG = "homeassistant.binary_sensor";
void HomeassistantBinarySensor::setup() {
api::global_api_server->subscribe_home_assistant_state(this->entity_id_, this->attribute_, [this](std::string state) {
auto val = parse_on_off(state.c_str());
switch (val) {
case PARSE_NONE:
case PARSE_TOGGLE:
ESP_LOGW(TAG, "Can't convert '%s' to binary state!", state.c_str());
break;
case PARSE_ON:
case PARSE_OFF:
bool new_state = val == PARSE_ON;
if (this->attribute_.has_value()) {
ESP_LOGD(TAG, "'%s::%s': Got attribute state %s", this->entity_id_.c_str(), this->attribute_.value().c_str(),
ONOFF(new_state));
} else {
ESP_LOGD(TAG, "'%s': Got state %s", this->entity_id_.c_str(), ONOFF(new_state));
api::global_api_server->subscribe_home_assistant_state(
this->entity_id_, this->attribute_, [this](const std::string &state) {
auto val = parse_on_off(state.c_str());
switch (val) {
case PARSE_NONE:
case PARSE_TOGGLE:
ESP_LOGW(TAG, "Can't convert '%s' to binary state!", state.c_str());
break;
case PARSE_ON:
case PARSE_OFF:
bool new_state = val == PARSE_ON;
if (this->attribute_.has_value()) {
ESP_LOGD(TAG, "'%s::%s': Got attribute state %s", this->entity_id_.c_str(),
this->attribute_.value().c_str(), ONOFF(new_state));
} else {
ESP_LOGD(TAG, "'%s': Got state %s", this->entity_id_.c_str(), ONOFF(new_state));
}
if (this->initial_)
this->publish_initial_state(new_state);
else
this->publish_state(new_state);
break;
}
if (this->initial_)
this->publish_initial_state(new_state);
else
this->publish_state(new_state);
break;
}
this->initial_ = false;
});
this->initial_ = false;
});
}
void HomeassistantBinarySensor::dump_config() {
LOG_BINARY_SENSOR("", "Homeassistant Binary Sensor", this);

View File

@ -8,22 +8,23 @@ namespace homeassistant {
static const char *TAG = "homeassistant.sensor";
void HomeassistantSensor::setup() {
api::global_api_server->subscribe_home_assistant_state(this->entity_id_, this->attribute_, [this](std::string state) {
auto val = parse_float(state);
if (!val.has_value()) {
ESP_LOGW(TAG, "Can't convert '%s' to number!", state.c_str());
this->publish_state(NAN);
return;
}
api::global_api_server->subscribe_home_assistant_state(
this->entity_id_, this->attribute_, [this](const std::string &state) {
auto val = parse_float(state);
if (!val.has_value()) {
ESP_LOGW(TAG, "Can't convert '%s' to number!", state.c_str());
this->publish_state(NAN);
return;
}
if (this->attribute_.has_value()) {
ESP_LOGD(TAG, "'%s::%s': Got attribute state %.2f", this->entity_id_.c_str(), this->attribute_.value().c_str(),
*val);
} else {
ESP_LOGD(TAG, "'%s': Got state %.2f", this->entity_id_.c_str(), *val);
}
this->publish_state(*val);
});
if (this->attribute_.has_value()) {
ESP_LOGD(TAG, "'%s::%s': Got attribute state %.2f", this->entity_id_.c_str(),
this->attribute_.value().c_str(), *val);
} else {
ESP_LOGD(TAG, "'%s': Got state %.2f", this->entity_id_.c_str(), *val);
}
this->publish_state(*val);
});
}
void HomeassistantSensor::dump_config() {
LOG_SENSOR("", "Homeassistant Sensor", this);

View File

@ -8,15 +8,16 @@ namespace homeassistant {
static const char *TAG = "homeassistant.text_sensor";
void HomeassistantTextSensor::setup() {
api::global_api_server->subscribe_home_assistant_state(this->entity_id_, this->attribute_, [this](std::string state) {
if (this->attribute_.has_value()) {
ESP_LOGD(TAG, "'%s::%s': Got attribute state '%s'", this->entity_id_.c_str(), this->attribute_.value().c_str(),
state.c_str());
} else {
ESP_LOGD(TAG, "'%s': Got state '%s'", this->entity_id_.c_str(), state.c_str());
}
this->publish_state(state);
});
api::global_api_server->subscribe_home_assistant_state(
this->entity_id_, this->attribute_, [this](const std::string &state) {
if (this->attribute_.has_value()) {
ESP_LOGD(TAG, "'%s::%s': Got attribute state '%s'", this->entity_id_.c_str(),
this->attribute_.value().c_str(), state.c_str());
} else {
ESP_LOGD(TAG, "'%s': Got state '%s'", this->entity_id_.c_str(), state.c_str());
}
this->publish_state(state);
});
}
void HomeassistantTextSensor::dump_config() {
LOG_TEXT_SENSOR("", "Homeassistant Text Sensor", this);

View File

@ -13,8 +13,8 @@ void HttpRequestComponent::dump_config() {
}
void HttpRequestComponent::set_url(std::string url) {
this->url_ = url;
this->secure_ = url.compare(0, 6, "https:") == 0;
this->url_ = std::move(url);
this->secure_ = this->url_.compare(0, 6, "https:") == 0;
if (!this->last_url_.empty() && this->url_ != this->last_url_) {
// Close connection if url has been changed

View File

@ -1,10 +1,11 @@
#pragma once
#include "esphome/components/json/json_util.h"
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include <list>
#include <map>
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/json/json_util.h"
#include <utility>
#ifdef ARDUINO_ARCH_ESP32
#include <HTTPClient.h>
@ -33,8 +34,8 @@ class HttpRequestComponent : public Component {
void set_method(const char *method) { this->method_ = method; }
void set_useragent(const char *useragent) { this->useragent_ = useragent; }
void set_timeout(uint16_t timeout) { this->timeout_ = timeout; }
void set_body(std::string body) { this->body_ = body; }
void set_headers(std::list<Header> headers) { this->headers_ = headers; }
void set_body(std::string body) { this->body_ = std::move(body); }
void set_headers(std::list<Header> headers) { this->headers_ = std::move(headers); }
void send(const std::vector<HttpRequestResponseTrigger *> &response_triggers);
void close();
const char *get_string();

View File

@ -1,8 +1,8 @@
#pragma once
#include <stdint.h>
#include <string>
#include "WString.h"
#include <cstdint>
#include <string>
#include <vector>
namespace improv {

View File

@ -120,7 +120,7 @@ void ESPRangeView::darken(uint8_t delta) {
for (auto c : *this)
c.darken(delta);
}
ESPRangeView &ESPRangeView::operator=(const ESPRangeView &rhs) {
ESPRangeView &ESPRangeView::operator=(const ESPRangeView &rhs) { // NOLINT
// If size doesn't match, error (todo warning)
if (rhs.size() != this->size())
return *this;

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "esphome/core/component.h"
#include "esphome/components/light/light_state.h"
#include "esphome/components/light/addressable_light.h"
@ -51,9 +53,9 @@ class AddressableLightEffect : public LightEffect {
class AddressableLambdaLightEffect : public AddressableLightEffect {
public:
AddressableLambdaLightEffect(const std::string &name,
const std::function<void(AddressableLight &, Color, bool initial_run)> &f,
std::function<void(AddressableLight &, Color, bool initial_run)> f,
uint32_t update_interval)
: AddressableLightEffect(name), f_(f), update_interval_(update_interval) {}
: AddressableLightEffect(name), f_(std::move(f)), update_interval_(update_interval) {}
void start() override { this->initial_run_ = true; }
void apply(AddressableLight &it, const Color &current_color) override {
const uint32_t now = millis();

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "light_effect.h"
#include "esphome/core/automation.h"
@ -85,8 +87,8 @@ class RandomLightEffect : public LightEffect {
class LambdaLightEffect : public LightEffect {
public:
LambdaLightEffect(const std::string &name, const std::function<void()> &f, uint32_t update_interval)
: LightEffect(name), f_(f), update_interval_(update_interval) {}
LambdaLightEffect(const std::string &name, std::function<void()> f, uint32_t update_interval)
: LightEffect(name), f_(std::move(f)), update_interval_(update_interval) {}
void apply() override {
const uint32_t now = millis();

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "esphome/core/component.h"
#include "light_color_values.h"
#include "light_state.h"
@ -11,7 +13,7 @@ class LightState;
class LightEffect {
public:
explicit LightEffect(const std::string &name) : name_(name) {}
explicit LightEffect(std::string name) : name_(std::move(name)) {}
/// Initialize this LightEffect. Will be called once after creation.
virtual void start() {}

View File

@ -173,7 +173,7 @@ void LightState::loop() {
}
LightTraits LightState::get_traits() { return this->output_->get_traits(); }
const std::vector<LightEffect *> &LightState::get_effects() const { return this->effects_; }
void LightState::add_effects(const std::vector<LightEffect *> effects) {
void LightState::add_effects(const std::vector<LightEffect *> &effects) {
this->effects_.reserve(this->effects_.size() + effects.size());
for (auto *effect : effects) {
this->effects_.push_back(effect);

View File

@ -269,7 +269,7 @@ class LightState : public Nameable, public Component {
const std::vector<LightEffect *> &get_effects() const;
void add_effects(std::vector<LightEffect *> effects);
void add_effects(const std::vector<LightEffect *> &effects);
void current_values_as_binary(bool *binary);

View File

@ -55,7 +55,7 @@ void MAX7219Component::dump_config() {
}
void MAX7219Component::loop() {
unsigned long now = millis();
uint32_t now = millis();
// check if the buffer has shrunk past the current position since last update
if ((this->max_displaybuffer_.size() >= this->old_buffer_size_ + 3) ||

View File

@ -99,7 +99,7 @@ class MAX7219Component : public PollingComponent,
uint8_t orientation_;
uint8_t bckgrnd_ = 0x0;
std::vector<uint8_t> max_displaybuffer_;
unsigned long last_scroll_ = 0;
uint32_t last_scroll_ = 0;
uint16_t stepsleft_;
size_t get_buffer_length_();
optional<max7219_writer_t> writer_local_{};

View File

@ -113,7 +113,7 @@ uint8_t MCP2515::get_status_() {
canbus::Error MCP2515::set_mode_(const CanctrlReqopMode mode) {
modify_register_(MCP_CANCTRL, CANCTRL_REQOP, mode);
unsigned long end_time = millis() + 10;
uint32_t end_time = millis() + 10;
bool mode_match = false;
while (millis() < end_time) {
uint8_t new_mode = read_register_(MCP_CANSTAT);
@ -600,9 +600,9 @@ canbus::Error MCP2515::set_bitrate_(canbus::CanSpeed can_speed, CanClock can_clo
}
if (set) {
set_register_(MCP_CNF1, cfg1);
set_register_(MCP_CNF2, cfg2);
set_register_(MCP_CNF3, cfg3);
set_register_(MCP_CNF1, cfg1); // NOLINT
set_register_(MCP_CNF2, cfg2); // NOLINT
set_register_(MCP_CNF3, cfg3); // NOLINT
return canbus::ERROR_OK;
} else {
return canbus::ERROR_FAIL;

View File

@ -37,7 +37,7 @@ float MCP3008::read_data(uint8_t pin) {
return data / 1023.0f;
}
MCP3008Sensor::MCP3008Sensor(MCP3008 *parent, std::string name, uint8_t pin, float reference_voltage)
MCP3008Sensor::MCP3008Sensor(MCP3008 *parent, const std::string &name, uint8_t pin, float reference_voltage)
: PollingComponent(1000), parent_(parent), pin_(pin) {
this->set_name(name);
this->reference_voltage_ = reference_voltage;

View File

@ -26,7 +26,7 @@ class MCP3008 : public Component,
class MCP3008Sensor : public PollingComponent, public sensor::Sensor, public voltage_sampler::VoltageSampler {
public:
MCP3008Sensor(MCP3008 *parent, std::string name, uint8_t pin, float reference_voltage);
MCP3008Sensor(MCP3008 *parent, const std::string &name, uint8_t pin, float reference_voltage);
void set_reference_voltage(float reference_voltage) { reference_voltage_ = reference_voltage; }
void setup() override;

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/midea_dongle/midea_dongle.h"
@ -27,9 +29,11 @@ class MideaAC : public midea_dongle::MideaAppliance, public climate::Climate, pu
void set_preset_boost(bool state) { this->traits_preset_boost_ = state; }
bool allow_preset(climate::ClimatePreset preset) const;
void set_custom_fan_modes(std::vector<std::string> custom_fan_modes) {
this->traits_custom_fan_modes_ = custom_fan_modes;
this->traits_custom_fan_modes_ = std::move(custom_fan_modes);
}
void set_custom_presets(std::vector<std::string> custom_presets) {
this->traits_custom_presets_ = std::move(custom_presets);
}
void set_custom_presets(std::vector<std::string> custom_presets) { this->traits_custom_presets_ = custom_presets; }
bool allow_custom_preset(const std::string &custom_preset) const;
protected:

View File

@ -52,7 +52,7 @@ void MideaDongle::update() {
wifi_strength = this->notify_.get_signal_strength();
} else {
this->rssi_timer_ = 60;
const long dbm = WiFi.RSSI();
const int32_t dbm = WiFi.RSSI();
if (dbm > -63)
wifi_strength = 4;
else if (dbm > -75)

View File

@ -1,8 +1,10 @@
#include "mqtt_client.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include "esphome/core/util.h"
#include <utility>
#ifdef USE_LOGGER
#include "esphome/components/logger/logger.h"
#endif
@ -340,7 +342,7 @@ void MQTTClientComponent::subscribe(const std::string &topic, mqtt_callback_t ca
this->subscriptions_.push_back(subscription);
}
void MQTTClientComponent::subscribe_json(const std::string &topic, mqtt_json_callback_t callback, uint8_t qos) {
void MQTTClientComponent::subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos) {
auto f = [callback](const std::string &topic, const std::string &payload) {
json::parse_json(payload, [topic, callback](JsonObject &root) { callback(topic, root); });
};
@ -561,7 +563,7 @@ void MQTTClientComponent::add_ssl_fingerprint(const std::array<uint8_t, SHA1_SIZ
MQTTClientComponent *global_mqtt_client = nullptr;
// MQTTMessageTrigger
MQTTMessageTrigger::MQTTMessageTrigger(const std::string &topic) : topic_(topic) {}
MQTTMessageTrigger::MQTTMessageTrigger(std::string topic) : topic_(std::move(topic)) {}
void MQTTMessageTrigger::set_qos(uint8_t qos) { this->qos_ = qos; }
void MQTTMessageTrigger::set_payload(const std::string &payload) { this->payload_ = payload; }
void MQTTMessageTrigger::setup() {

View File

@ -157,7 +157,7 @@ class MQTTClientComponent : public Component {
* received.
* @param qos The QoS of this subscription.
*/
void subscribe_json(const std::string &topic, mqtt_json_callback_t callback, uint8_t qos = 0);
void subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos = 0);
/** Unsubscribe from an MQTT topic.
*
@ -279,7 +279,7 @@ extern MQTTClientComponent *global_mqtt_client;
class MQTTMessageTrigger : public Trigger<std::string>, public Component {
public:
explicit MQTTMessageTrigger(const std::string &topic);
explicit MQTTMessageTrigger(std::string topic);
void set_qos(uint8_t qos);
void set_payload(const std::string &payload);

View File

@ -124,8 +124,8 @@ void MQTTComponent::subscribe(const std::string &topic, mqtt_callback_t callback
global_mqtt_client->subscribe(topic, std::move(callback), qos);
}
void MQTTComponent::subscribe_json(const std::string &topic, mqtt_json_callback_t callback, uint8_t qos) {
global_mqtt_client->subscribe_json(topic, std::move(callback), qos);
void MQTTComponent::subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos) {
global_mqtt_client->subscribe_json(topic, callback, qos);
}
MQTTComponent::MQTTComponent() = default;

View File

@ -127,7 +127,7 @@ class MQTTComponent : public Component {
* received.
* @param qos The MQTT quality of service. Defaults to 0.
*/
void subscribe_json(const std::string &topic, mqtt_json_callback_t callback, uint8_t qos = 0);
void subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos = 0);
protected:
/// Helper method to get the discovery topic for this component.

View File

@ -9,7 +9,7 @@ static const char *TAG = "mqtt_subscribe.sensor";
void MQTTSubscribeSensor::setup() {
mqtt::global_mqtt_client->subscribe(
this->topic_,
[this](const std::string &topic, std::string payload) {
[this](const std::string &topic, const std::string &payload) {
auto val = parse_float(payload);
if (!val.has_value()) {
ESP_LOGW(TAG, "Can't convert '%s' to number!", payload.c_str());

View File

@ -1,5 +1,7 @@
#include "mqtt_subscribe_text_sensor.h"
#include "esphome/core/log.h"
#include <utility>
namespace esphome {
namespace mqtt_subscribe {
@ -8,7 +10,7 @@ static const char *TAG = "mqtt_subscribe.text_sensor";
void MQTTSubscribeTextSensor::setup() {
this->parent_->subscribe(
this->topic_, [this](const std::string &topic, std::string payload) { this->publish_state(payload); },
this->topic_, [this](const std::string &topic, const std::string &payload) { this->publish_state(payload); },
this->qos_);
}
float MQTTSubscribeTextSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; }

View File

@ -1,5 +1,7 @@
#pragma once
#include <utility>
#include "esphome/core/component.h"
#include "esphome/components/light/addressable_light.h"
@ -31,7 +33,7 @@ class AddressableSegment {
class PartitionLightOutput : public light::AddressableLight {
public:
explicit PartitionLightOutput(std::vector<AddressableSegment> segments) : segments_(segments) {
explicit PartitionLightOutput(std::vector<AddressableSegment> segments) : segments_(std::move(segments)) {
int32_t off = 0;
for (auto &seg : this->segments_) {
seg.set_dst_offset(off);