From 360effcb72eefd9eb05060506b84d315125b5138 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Thu, 10 Jun 2021 13:04:40 +0200 Subject: [PATCH] Activate some clang-tidy checks (#1884) --- .clang-tidy | 24 +-- esphome/components/ade7953/ade7953.cpp | 4 +- esphome/components/apds9960/apds9960.cpp | 2 +- esphome/components/api/api_server.cpp | 2 +- esphome/components/api/api_server.h | 2 +- esphome/components/api/user_services.h | 6 +- esphome/components/binary_sensor/automation.h | 6 +- .../binary_sensor/binary_sensor.cpp | 2 +- .../components/binary_sensor/binary_sensor.h | 10 +- esphome/components/binary_sensor/filter.cpp | 6 +- esphome/components/binary_sensor/filter.h | 4 +- esphome/components/climate/climate.h | 4 +- esphome/components/climate_ir/climate_ir.h | 6 +- esphome/components/cover/cover.h | 10 +- .../components/custom/output/custom_output.h | 8 +- .../components/custom/switch/custom_switch.h | 2 +- .../custom/text_sensor/custom_text_sensor.h | 2 +- esphome/components/dfplayer/dfplayer.h | 5 +- esphome/components/display/display_buffer.cpp | 6 +- esphome/components/display/display_buffer.h | 8 +- esphome/components/e131/e131_packet.cpp | 2 +- .../ethernet/ethernet_component.cpp | 5 + esphome/components/ezo/ezo.h | 4 +- .../fujitsu_general/fujitsu_general.cpp | 5 +- .../components/hitachi_ac344/hitachi_ac344.h | 2 +- .../hm3301/abstract_aqi_calculator.h | 2 - .../{aqi_calculator.cpp => aqi_calculator.h} | 2 + .../hm3301/aqi_calculator_factory.h | 5 +- ...{caqi_calculator.cpp => caqi_calculator.h} | 2 + .../homeassistant_binary_sensor.cpp | 47 ++--- .../sensor/homeassistant_sensor.cpp | 31 +-- .../text_sensor/homeassistant_text_sensor.cpp | 19 +- .../components/http_request/http_request.cpp | 4 +- .../components/http_request/http_request.h | 11 +- esphome/components/improv/improv.h | 4 +- .../components/light/addressable_light.cpp | 2 +- .../light/addressable_light_effect.h | 6 +- esphome/components/light/base_light_effects.h | 6 +- esphome/components/light/light_effect.h | 4 +- esphome/components/light/light_state.cpp | 2 +- esphome/components/light/light_state.h | 2 +- .../components/max7219digit/max7219digit.cpp | 2 +- .../components/max7219digit/max7219digit.h | 2 +- esphome/components/mcp2515/mcp2515.cpp | 8 +- esphome/components/mcp3008/mcp3008.cpp | 2 +- esphome/components/mcp3008/mcp3008.h | 2 +- esphome/components/midea_ac/midea_climate.h | 8 +- .../components/midea_dongle/midea_dongle.cpp | 2 +- esphome/components/mqtt/mqtt_client.cpp | 8 +- esphome/components/mqtt/mqtt_client.h | 4 +- esphome/components/mqtt/mqtt_component.cpp | 4 +- esphome/components/mqtt/mqtt_component.h | 2 +- .../sensor/mqtt_subscribe_sensor.cpp | 2 +- .../mqtt_subscribe_text_sensor.cpp | 4 +- .../components/partition/light_partition.h | 4 +- esphome/components/remote_base/remote_base.h | 2 +- esphome/components/rf_bridge/rf_bridge.cpp | 6 +- esphome/components/rf_bridge/rf_bridge.h | 11 +- esphome/components/sensor/filter.h | 5 +- esphome/components/sensor/sensor.h | 24 +-- esphome/components/sgp30/sgp30.cpp | 6 +- esphome/components/sgp30/sgp30.h | 2 +- .../sgp40/sensirion_voc_algorithm.cpp | 191 +++++++++--------- .../sgp40/sensirion_voc_algorithm.h | 52 ++--- esphome/components/sgp40/sgp40.h | 6 +- esphome/components/sim800l/sim800l.cpp | 8 +- esphome/components/sim800l/sim800l.h | 10 +- .../components/slow_pwm/slow_pwm_output.cpp | 2 +- esphome/components/switch/switch.h | 12 +- .../teleinfo/sensor/teleinfo_sensor.cpp | 2 +- .../teleinfo/sensor/teleinfo_sensor.h | 2 +- esphome/components/teleinfo/teleinfo.cpp | 2 +- esphome/components/teleinfo/teleinfo.h | 4 +- .../text_sensor/teleinfo_text_sensor.cpp | 2 +- .../text_sensor/teleinfo_text_sensor.h | 2 +- esphome/components/text_sensor/automation.h | 4 +- .../components/text_sensor/text_sensor.cpp | 2 +- esphome/components/text_sensor/text_sensor.h | 14 +- esphome/components/time/real_time_clock.cpp | 2 +- esphome/components/time/real_time_clock.h | 6 +- .../tuya/binary_sensor/tuya_binary_sensor.cpp | 2 +- .../components/tuya/climate/tuya_climate.cpp | 8 +- esphome/components/tuya/fan/tuya_fan.cpp | 8 +- esphome/components/tuya/light/tuya_light.cpp | 6 +- .../components/tuya/sensor/tuya_sensor.cpp | 2 +- .../components/tuya/switch/tuya_switch.cpp | 2 +- esphome/components/tuya/tuya.cpp | 4 +- esphome/components/tuya/tuya.h | 4 +- esphome/components/web_server/web_server.cpp | 16 +- esphome/components/web_server/web_server.h | 16 +- esphome/components/wifi/wifi_component.cpp | 17 +- esphome/components/wifi/wifi_component.h | 5 +- .../components/wifi/wifi_component_esp32.cpp | 2 +- .../wifi/wifi_component_esp8266.cpp | 10 +- esphome/components/xpt2046/xpt2046.cpp | 2 +- esphome/components/xpt2046/xpt2046.h | 2 +- esphome/components/zyaura/zyaura.cpp | 2 +- esphome/components/zyaura/zyaura.h | 4 +- esphome/core/color.h | 2 +- esphome/core/component.cpp | 10 +- esphome/core/component.h | 2 +- esphome/core/controller.cpp | 2 +- esphome/core/controller.h | 2 +- esphome/core/helpers.cpp | 10 +- esphome/core/helpers.h | 10 +- esphome/core/optional.h | 2 +- esphome/core/preferences.cpp | 2 +- esphome/core/util.cpp | 2 +- esphome/core/util.h | 5 - 109 files changed, 458 insertions(+), 422 deletions(-) rename esphome/components/hm3301/{aqi_calculator.cpp => aqi_calculator.h} (99%) rename esphome/components/hm3301/{caqi_calculator.cpp => caqi_calculator.h} (99%) diff --git a/.clang-tidy b/.clang-tidy index 1202d12c27..dc59dbe1a0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -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 diff --git a/esphome/components/ade7953/ade7953.cpp b/esphome/components/ade7953/ade7953.cpp index d55f585b26..01afdeef36 100644 --- a/esphome/components/ade7953/ade7953.cpp +++ b/esphome/components/ade7953/ade7953.cpp @@ -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) diff --git a/esphome/components/apds9960/apds9960.cpp b/esphome/components/apds9960/apds9960.cpp index 2e09d11182..6612326e5e 100644 --- a/esphome/components/apds9960/apds9960.cpp +++ b/esphome/components/apds9960/apds9960.cpp @@ -7,7 +7,7 @@ namespace apds9960 { static const char *TAG = "apds9960"; #define APDS9960_ERROR_CHECK(func) \ - if (!func) { \ + if (!(func)) { \ this->mark_failed(); \ return; \ } diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index dd77f2004f..1a3aa6e2f4 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -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_) diff --git a/esphome/components/api/api_server.h b/esphome/components/api/api_server.h index 538a385efb..ec89cdf18e 100644 --- a/esphome/components/api/api_server.h +++ b/esphome/components/api/api_server.h @@ -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; diff --git a/esphome/components/api/user_services.h b/esphome/components/api/user_services.h index 3094ba397c..1f9ffc5914 100644 --- a/esphome/components/api/user_services.h +++ b/esphome/components/api/user_services.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "esphome/core/component.h" #include "esphome/core/automation.h" #include "api_pb2.h" @@ -20,8 +22,8 @@ template enums::ServiceArgType to_service_arg_type(); template class UserServiceBase : public UserServiceDescriptor { public: - UserServiceBase(const std::string &name, const std::array &arg_names) - : name_(name), arg_names_(arg_names) { + UserServiceBase(std::string name, const std::array &arg_names) + : name_(std::move(name)), arg_names_(arg_names) { this->key_ = fnv1_hash(this->name_); } diff --git a/esphome/components/binary_sensor/automation.h b/esphome/components/binary_sensor/automation.h index 6b0321628c..0c1e80afba 100644 --- a/esphome/components/binary_sensor/automation.h +++ b/esphome/components/binary_sensor/automation.h @@ -1,5 +1,7 @@ #pragma once +#include + #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 &timing) - : parent_(parent), timing_(timing) {} + explicit MultiClickTrigger(BinarySensor *parent, std::vector timing) + : parent_(parent), timing_(std::move(timing)) {} void setup() override { this->last_state_ = this->parent_->state; diff --git a/esphome/components/binary_sensor/binary_sensor.cpp b/esphome/components/binary_sensor/binary_sensor.cpp index 1cde692dd4..9878f06380 100644 --- a/esphome/components/binary_sensor/binary_sensor.cpp +++ b/esphome/components/binary_sensor/binary_sensor.cpp @@ -61,7 +61,7 @@ void BinarySensor::add_filter(Filter *filter) { last_filter->next_ = filter; } } -void BinarySensor::add_filters(std::vector filters) { +void BinarySensor::add_filters(const std::vector &filters) { for (Filter *filter : filters) { this->add_filter(filter); } diff --git a/esphome/components/binary_sensor/binary_sensor.h b/esphome/components/binary_sensor/binary_sensor.h index f91c93c424..62e8031cb5 100644 --- a/esphome/components/binary_sensor/binary_sensor.h +++ b/esphome/components/binary_sensor/binary_sensor.h @@ -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 filters); + void add_filters(const std::vector &filters); // ========== INTERNAL METHODS ========== // (In most use cases you won't need these) diff --git a/esphome/components/binary_sensor/filter.cpp b/esphome/components/binary_sensor/filter.cpp index c6ca3e2f79..3aef73c893 100644 --- a/esphome/components/binary_sensor/filter.cpp +++ b/esphome/components/binary_sensor/filter.cpp @@ -1,5 +1,7 @@ #include "filter.h" + #include "binary_sensor.h" +#include namespace esphome { @@ -64,7 +66,7 @@ float DelayedOffFilter::get_setup_priority() const { return setup_priority::HARD optional InvertFilter::new_value(bool value, bool is_initial) { return !value; } -AutorepeatFilter::AutorepeatFilter(const std::vector &timings) : timings_(timings) {} +AutorepeatFilter::AutorepeatFilter(std::vector timings) : timings_(std::move(timings)) {} optional 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(bool)> &f) : f_(f) {} +LambdaFilter::LambdaFilter(std::function(bool)> f) : f_(std::move(f)) {} optional LambdaFilter::new_value(bool value, bool is_initial) { return this->f_(value); } diff --git a/esphome/components/binary_sensor/filter.h b/esphome/components/binary_sensor/filter.h index 8528e74a9f..59068634af 100644 --- a/esphome/components/binary_sensor/filter.h +++ b/esphome/components/binary_sensor/filter.h @@ -79,7 +79,7 @@ struct AutorepeatFilterTiming { class AutorepeatFilter : public Filter, public Component { public: - explicit AutorepeatFilter(const std::vector &timings); + explicit AutorepeatFilter(std::vector timings); optional 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(bool)> &f); + explicit LambdaFilter(std::function(bool)> f); optional new_value(bool value, bool is_initial) override; diff --git a/esphome/components/climate/climate.h b/esphome/components/climate/climate.h index cd69469692..3ac9270341 100644 --- a/esphome/components/climate/climate.h +++ b/esphome/components/climate/climate.h @@ -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; diff --git a/esphome/components/climate_ir/climate_ir.h b/esphome/components/climate_ir/climate_ir.h index 7a69b19786..0914f730cf 100644 --- a/esphome/components/climate_ir/climate_ir.h +++ b/esphome/components/climate_ir/climate_ir.h @@ -1,5 +1,7 @@ #pragma once +#include + #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; diff --git a/esphome/components/cover/cover.h b/esphome/components/cover/cover.h index 839cf9207e..1af4f9cbea 100644 --- a/esphome/components/cover/cover.h +++ b/esphome/components/cover/cover.h @@ -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()); \ } \ } diff --git a/esphome/components/custom/output/custom_output.h b/esphome/components/custom/output/custom_output.h index abebe16ee9..1b55d51e29 100644 --- a/esphome/components/custom/output/custom_output.h +++ b/esphome/components/custom/output/custom_output.h @@ -9,7 +9,9 @@ namespace custom { class CustomBinaryOutputConstructor { public: - CustomBinaryOutputConstructor(std::function()> init) { this->outputs_ = init(); } + CustomBinaryOutputConstructor(const std::function()> &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()> init) { this->outputs_ = init(); } + CustomFloatOutputConstructor(const std::function()> &init) { + this->outputs_ = init(); + } output::FloatOutput *get_output(int i) { return this->outputs_[i]; } diff --git a/esphome/components/custom/switch/custom_switch.h b/esphome/components/custom/switch/custom_switch.h index b96074424d..186e7473fe 100644 --- a/esphome/components/custom/switch/custom_switch.h +++ b/esphome/components/custom/switch/custom_switch.h @@ -8,7 +8,7 @@ namespace custom { class CustomSwitchConstructor : public Component { public: - CustomSwitchConstructor(std::function()> init) { this->switches_ = init(); } + CustomSwitchConstructor(const std::function()> &init) { this->switches_ = init(); } switch_::Switch *get_switch(int i) { return this->switches_[i]; } diff --git a/esphome/components/custom/text_sensor/custom_text_sensor.h b/esphome/components/custom/text_sensor/custom_text_sensor.h index aa8c7ddb03..f1e9c7665e 100644 --- a/esphome/components/custom/text_sensor/custom_text_sensor.h +++ b/esphome/components/custom/text_sensor/custom_text_sensor.h @@ -8,7 +8,7 @@ namespace custom { class CustomTextSensorConstructor : public Component { public: - CustomTextSensorConstructor(std::function()> init) { + CustomTextSensorConstructor(const std::function()> &init) { this->text_sensors_ = init(); } diff --git a/esphome/components/dfplayer/dfplayer.h b/esphome/components/dfplayer/dfplayer.h index 6742591926..5cd49c311d 100644 --- a/esphome/components/dfplayer/dfplayer.h +++ b/esphome/components/dfplayer/dfplayer.h @@ -103,7 +103,10 @@ class DFPlayer : public uart::UARTDevice, public Component { }; #define DFPLAYER_SIMPLE_ACTION(ACTION_CLASS, ACTION_METHOD) \ - template class ACTION_CLASS : public Action, public Parented { \ + template \ + class ACTION_CLASS : /* NOLINT */ \ + public Action, \ + public Parented { \ void play(Ts... x) override { this->parent_->ACTION_METHOD(); } \ }; diff --git a/esphome/components/display/display_buffer.cpp b/esphome/components/display/display_buffer.cpp index 23f6faccb1..f88636d7f5 100644 --- a/esphome/components/display/display_buffer.cpp +++ b/esphome/components/display/display_buffer.cpp @@ -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 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(); } diff --git a/esphome/components/display/display_buffer.h b/esphome/components/display/display_buffer.h index 0763262d4c..b89eab0dba 100644 --- a/esphome/components/display/display_buffer.h +++ b/esphome/components/display/display_buffer.h @@ -86,10 +86,10 @@ class DisplayOnPageChangeTrigger; using display_writer_t = std::function; #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(); diff --git a/esphome/components/e131/e131_packet.cpp b/esphome/components/e131/e131_packet.cpp index ca68f5126d..7edc8b129a 100644 --- a/esphome/components/e131/e131_packet.cpp +++ b/esphome/components/e131/e131_packet.cpp @@ -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(&((E131RawPacket *) nullptr)->property_values[1]); +const size_t E131_MIN_PACKET_SIZE = reinterpret_cast(&((E131RawPacket *) nullptr)->property_values[1]); bool E131Component::join_igmp_groups_() { if (listen_method_ != E131_MULTICAST) diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index 8c96cca951..c5dc9bdc93 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -9,6 +9,11 @@ #include #include +/// 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(); diff --git a/esphome/components/ezo/ezo.h b/esphome/components/ezo/ezo.h index b2b59e38d4..d46d193ae7 100644 --- a/esphome/components/ezo/ezo.h +++ b/esphome/components/ezo/ezo.h @@ -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_; }; diff --git a/esphome/components/fujitsu_general/fujitsu_general.cpp b/esphome/components/fujitsu_general/fujitsu_general.cpp index 531c61f0d5..5bf4710e58 100644 --- a/esphome/components/fujitsu_general/fujitsu_general.cpp +++ b/esphome/components/fujitsu_general/fujitsu_general.cpp @@ -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"; diff --git a/esphome/components/hitachi_ac344/hitachi_ac344.h b/esphome/components/hitachi_ac344/hitachi_ac344.h index 9e850d9b53..3126ef0493 100644 --- a/esphome/components/hitachi_ac344/hitachi_ac344.h +++ b/esphome/components/hitachi_ac344/hitachi_ac344.h @@ -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 { diff --git a/esphome/components/hm3301/abstract_aqi_calculator.h b/esphome/components/hm3301/abstract_aqi_calculator.h index f160a91148..f2573ff108 100644 --- a/esphome/components/hm3301/abstract_aqi_calculator.h +++ b/esphome/components/hm3301/abstract_aqi_calculator.h @@ -1,7 +1,5 @@ #pragma once -#include "Arduino.h" - namespace esphome { namespace hm3301 { diff --git a/esphome/components/hm3301/aqi_calculator.cpp b/esphome/components/hm3301/aqi_calculator.h similarity index 99% rename from esphome/components/hm3301/aqi_calculator.cpp rename to esphome/components/hm3301/aqi_calculator.h index 41e538a399..627ee686fc 100644 --- a/esphome/components/hm3301/aqi_calculator.cpp +++ b/esphome/components/hm3301/aqi_calculator.h @@ -1,3 +1,5 @@ +#pragma once + #include "abstract_aqi_calculator.h" namespace esphome { diff --git a/esphome/components/hm3301/aqi_calculator_factory.h b/esphome/components/hm3301/aqi_calculator_factory.h index 483a158822..55608b6e51 100644 --- a/esphome/components/hm3301/aqi_calculator_factory.h +++ b/esphome/components/hm3301/aqi_calculator_factory.h @@ -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 { diff --git a/esphome/components/hm3301/caqi_calculator.cpp b/esphome/components/hm3301/caqi_calculator.h similarity index 99% rename from esphome/components/hm3301/caqi_calculator.cpp rename to esphome/components/hm3301/caqi_calculator.h index 511179cb71..403bac2713 100644 --- a/esphome/components/hm3301/caqi_calculator.cpp +++ b/esphome/components/hm3301/caqi_calculator.h @@ -1,3 +1,5 @@ +#pragma once + #include "esphome/core/log.h" #include "abstract_aqi_calculator.h" diff --git a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp index cf2415d9c0..b4c68615d7 100644 --- a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp +++ b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp @@ -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); diff --git a/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp b/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp index 5f7916403e..da870bd90b 100644 --- a/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp +++ b/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp @@ -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); diff --git a/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp b/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp index 07b06cad3c..962663d8b4 100644 --- a/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp +++ b/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp @@ -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); diff --git a/esphome/components/http_request/http_request.cpp b/esphome/components/http_request/http_request.cpp index 79f698441e..fbe4fa0e54 100644 --- a/esphome/components/http_request/http_request.cpp +++ b/esphome/components/http_request/http_request.cpp @@ -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 diff --git a/esphome/components/http_request/http_request.h b/esphome/components/http_request/http_request.h index f2c688d2f9..27919fe75d 100644 --- a/esphome/components/http_request/http_request.h +++ b/esphome/components/http_request/http_request.h @@ -1,10 +1,11 @@ #pragma once +#include "esphome/components/json/json_util.h" +#include "esphome/core/automation.h" +#include "esphome/core/component.h" #include #include -#include "esphome/core/component.h" -#include "esphome/core/automation.h" -#include "esphome/components/json/json_util.h" +#include #ifdef ARDUINO_ARCH_ESP32 #include @@ -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
headers) { this->headers_ = headers; } + void set_body(std::string body) { this->body_ = std::move(body); } + void set_headers(std::list
headers) { this->headers_ = std::move(headers); } void send(const std::vector &response_triggers); void close(); const char *get_string(); diff --git a/esphome/components/improv/improv.h b/esphome/components/improv/improv.h index 8a44812cec..3d905e70f8 100644 --- a/esphome/components/improv/improv.h +++ b/esphome/components/improv/improv.h @@ -1,8 +1,8 @@ #pragma once -#include -#include #include "WString.h" +#include +#include #include namespace improv { diff --git a/esphome/components/light/addressable_light.cpp b/esphome/components/light/addressable_light.cpp index 236e5cede6..64973549ec 100644 --- a/esphome/components/light/addressable_light.cpp +++ b/esphome/components/light/addressable_light.cpp @@ -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; diff --git a/esphome/components/light/addressable_light_effect.h b/esphome/components/light/addressable_light_effect.h index 8d4d37ec34..d1ea9e3ff0 100644 --- a/esphome/components/light/addressable_light_effect.h +++ b/esphome/components/light/addressable_light_effect.h @@ -1,5 +1,7 @@ #pragma once +#include + #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 &f, + std::function 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 ¤t_color) override { const uint32_t now = millis(); diff --git a/esphome/components/light/base_light_effects.h b/esphome/components/light/base_light_effects.h index 775ee363af..eb92fec642 100644 --- a/esphome/components/light/base_light_effects.h +++ b/esphome/components/light/base_light_effects.h @@ -1,5 +1,7 @@ #pragma once +#include + #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 &f, uint32_t update_interval) - : LightEffect(name), f_(f), update_interval_(update_interval) {} + LambdaLightEffect(const std::string &name, std::function f, uint32_t update_interval) + : LightEffect(name), f_(std::move(f)), update_interval_(update_interval) {} void apply() override { const uint32_t now = millis(); diff --git a/esphome/components/light/light_effect.h b/esphome/components/light/light_effect.h index bef2562f55..f9903397b4 100644 --- a/esphome/components/light/light_effect.h +++ b/esphome/components/light/light_effect.h @@ -1,5 +1,7 @@ #pragma once +#include + #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() {} diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index 749dea5419..e0a850149a 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -173,7 +173,7 @@ void LightState::loop() { } LightTraits LightState::get_traits() { return this->output_->get_traits(); } const std::vector &LightState::get_effects() const { return this->effects_; } -void LightState::add_effects(const std::vector effects) { +void LightState::add_effects(const std::vector &effects) { this->effects_.reserve(this->effects_.size() + effects.size()); for (auto *effect : effects) { this->effects_.push_back(effect); diff --git a/esphome/components/light/light_state.h b/esphome/components/light/light_state.h index aff63bf5db..10bda2d17b 100644 --- a/esphome/components/light/light_state.h +++ b/esphome/components/light/light_state.h @@ -269,7 +269,7 @@ class LightState : public Nameable, public Component { const std::vector &get_effects() const; - void add_effects(std::vector effects); + void add_effects(const std::vector &effects); void current_values_as_binary(bool *binary); diff --git a/esphome/components/max7219digit/max7219digit.cpp b/esphome/components/max7219digit/max7219digit.cpp index 01bc5e0531..a1efb07d51 100644 --- a/esphome/components/max7219digit/max7219digit.cpp +++ b/esphome/components/max7219digit/max7219digit.cpp @@ -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) || diff --git a/esphome/components/max7219digit/max7219digit.h b/esphome/components/max7219digit/max7219digit.h index ddefe976a2..83f45e3a00 100644 --- a/esphome/components/max7219digit/max7219digit.h +++ b/esphome/components/max7219digit/max7219digit.h @@ -99,7 +99,7 @@ class MAX7219Component : public PollingComponent, uint8_t orientation_; uint8_t bckgrnd_ = 0x0; std::vector max_displaybuffer_; - unsigned long last_scroll_ = 0; + uint32_t last_scroll_ = 0; uint16_t stepsleft_; size_t get_buffer_length_(); optional writer_local_{}; diff --git a/esphome/components/mcp2515/mcp2515.cpp b/esphome/components/mcp2515/mcp2515.cpp index 228a951702..ccd8d0ee6c 100644 --- a/esphome/components/mcp2515/mcp2515.cpp +++ b/esphome/components/mcp2515/mcp2515.cpp @@ -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; diff --git a/esphome/components/mcp3008/mcp3008.cpp b/esphome/components/mcp3008/mcp3008.cpp index d09c2e4e92..18eaee89c2 100644 --- a/esphome/components/mcp3008/mcp3008.cpp +++ b/esphome/components/mcp3008/mcp3008.cpp @@ -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; diff --git a/esphome/components/mcp3008/mcp3008.h b/esphome/components/mcp3008/mcp3008.h index 129f299a14..16f1c14fcb 100644 --- a/esphome/components/mcp3008/mcp3008.h +++ b/esphome/components/mcp3008/mcp3008.h @@ -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; diff --git a/esphome/components/midea_ac/midea_climate.h b/esphome/components/midea_ac/midea_climate.h index 0a63312961..1d21c4cab2 100644 --- a/esphome/components/midea_ac/midea_climate.h +++ b/esphome/components/midea_ac/midea_climate.h @@ -1,5 +1,7 @@ #pragma once +#include + #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 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 custom_presets) { + this->traits_custom_presets_ = std::move(custom_presets); } - void set_custom_presets(std::vector custom_presets) { this->traits_custom_presets_ = custom_presets; } bool allow_custom_preset(const std::string &custom_preset) const; protected: diff --git a/esphome/components/midea_dongle/midea_dongle.cpp b/esphome/components/midea_dongle/midea_dongle.cpp index 8ddaba1cb6..c14b1bb3d3 100644 --- a/esphome/components/midea_dongle/midea_dongle.cpp +++ b/esphome/components/midea_dongle/midea_dongle.cpp @@ -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) diff --git a/esphome/components/mqtt/mqtt_client.cpp b/esphome/components/mqtt/mqtt_client.cpp index 3330956b52..6e16af2ea1 100644 --- a/esphome/components/mqtt/mqtt_client.cpp +++ b/esphome/components/mqtt/mqtt_client.cpp @@ -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 #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::arrayqos_ = qos; } void MQTTMessageTrigger::set_payload(const std::string &payload) { this->payload_ = payload; } void MQTTMessageTrigger::setup() { diff --git a/esphome/components/mqtt/mqtt_client.h b/esphome/components/mqtt/mqtt_client.h index e4f7c479b2..12ae32038d 100644 --- a/esphome/components/mqtt/mqtt_client.h +++ b/esphome/components/mqtt/mqtt_client.h @@ -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, 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); diff --git a/esphome/components/mqtt/mqtt_component.cpp b/esphome/components/mqtt/mqtt_component.cpp index 9b4255060f..3efa70e4ed 100644 --- a/esphome/components/mqtt/mqtt_component.cpp +++ b/esphome/components/mqtt/mqtt_component.cpp @@ -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; diff --git a/esphome/components/mqtt/mqtt_component.h b/esphome/components/mqtt/mqtt_component.h index 43465af498..4d7a522d5f 100644 --- a/esphome/components/mqtt/mqtt_component.h +++ b/esphome/components/mqtt/mqtt_component.h @@ -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. diff --git a/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp b/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp index f6ecb0df36..87a190870b 100644 --- a/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp +++ b/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp @@ -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()); diff --git a/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp b/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp index e7373c4b95..3538857e8b 100644 --- a/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp +++ b/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp @@ -1,5 +1,7 @@ #include "mqtt_subscribe_text_sensor.h" + #include "esphome/core/log.h" +#include 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; } diff --git a/esphome/components/partition/light_partition.h b/esphome/components/partition/light_partition.h index 11589ee539..687fe562d1 100644 --- a/esphome/components/partition/light_partition.h +++ b/esphome/components/partition/light_partition.h @@ -1,5 +1,7 @@ #pragma once +#include + #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 segments) : segments_(segments) { + explicit PartitionLightOutput(std::vector segments) : segments_(std::move(segments)) { int32_t off = 0; for (auto &seg : this->segments_) { seg.set_dst_offset(off); diff --git a/esphome/components/remote_base/remote_base.h b/esphome/components/remote_base/remote_base.h index 916fe29c1f..16c732df83 100644 --- a/esphome/components/remote_base/remote_base.h +++ b/esphome/components/remote_base/remote_base.h @@ -33,7 +33,7 @@ class RemoteTransmitData { const std::vector &get_data() const { return this->data_; } - void set_data(std::vector data) { + void set_data(const std::vector &data) { this->data_.clear(); this->data_.reserve(data.size()); for (auto dat : data) diff --git a/esphome/components/rf_bridge/rf_bridge.cpp b/esphome/components/rf_bridge/rf_bridge.cpp index a63523917a..26f2d031ab 100644 --- a/esphome/components/rf_bridge/rf_bridge.cpp +++ b/esphome/components/rf_bridge/rf_bridge.cpp @@ -114,7 +114,7 @@ bool RFBridgeComponent::parse_bridge_byte_(uint8_t byte) { return false; } -void RFBridgeComponent::write_byte_str_(std::string codes) { +void RFBridgeComponent::write_byte_str_(const std::string &codes) { uint8_t code; int size = codes.length(); for (int i = 0; i < size; i += 2) { @@ -160,7 +160,7 @@ void RFBridgeComponent::send_code(RFBridgeData data) { this->flush(); } -void RFBridgeComponent::send_advanced_code(RFBridgeAdvancedData data) { +void RFBridgeComponent::send_advanced_code(const RFBridgeAdvancedData &data) { ESP_LOGD(TAG, "Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.length, data.protocol, data.code.c_str()); this->write(RF_CODE_START); @@ -209,7 +209,7 @@ void RFBridgeComponent::start_bucket_sniffing() { this->flush(); } -void RFBridgeComponent::send_raw(std::string raw_code) { +void RFBridgeComponent::send_raw(const std::string &raw_code) { ESP_LOGD(TAG, "Sending Raw Code: %s", raw_code.c_str()); this->write_byte_str_(raw_code); diff --git a/esphome/components/rf_bridge/rf_bridge.h b/esphome/components/rf_bridge/rf_bridge.h index 573bb2df3f..2fa4eb05c5 100644 --- a/esphome/components/rf_bridge/rf_bridge.h +++ b/esphome/components/rf_bridge/rf_bridge.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "esphome/core/component.h" #include "esphome/components/uart/uart.h" #include "esphome/core/automation.h" @@ -52,19 +54,19 @@ class RFBridgeComponent : public uart::UARTDevice, public Component { this->advanced_data_callback_.add(std::move(callback)); } void send_code(RFBridgeData data); - void send_advanced_code(RFBridgeAdvancedData data); + void send_advanced_code(const RFBridgeAdvancedData &data); void learn(); void start_advanced_sniffing(); void stop_advanced_sniffing(); void start_bucket_sniffing(); - void send_raw(std::string code); + void send_raw(const std::string &code); void beep(uint16_t ms); protected: void ack_(); void decode_(); bool parse_bridge_byte_(uint8_t byte); - void write_byte_str_(std::string codes); + void write_byte_str_(const std::string &codes); std::vector rx_buffer_; uint32_t last_bridge_byte_{0}; @@ -83,7 +85,8 @@ class RFBridgeReceivedCodeTrigger : public Trigger { class RFBridgeReceivedAdvancedCodeTrigger : public Trigger { public: explicit RFBridgeReceivedAdvancedCodeTrigger(RFBridgeComponent *parent) { - parent->add_on_advanced_code_received_callback([this](RFBridgeAdvancedData data) { this->trigger(data); }); + parent->add_on_advanced_code_received_callback( + [this](RFBridgeAdvancedData data) { this->trigger(std::move(data)); }); } }; diff --git a/esphome/components/sensor/filter.h b/esphome/components/sensor/filter.h index 5b06d002fa..270a91ccff 100644 --- a/esphome/components/sensor/filter.h +++ b/esphome/components/sensor/filter.h @@ -1,8 +1,9 @@ #pragma once -#include #include "esphome/core/component.h" #include "esphome/core/helpers.h" +#include +#include namespace esphome { namespace sensor { @@ -335,7 +336,7 @@ class CalibrateLinearFilter : public Filter { class CalibratePolynomialFilter : public Filter { public: - CalibratePolynomialFilter(const std::vector &coefficients) : coefficients_(coefficients) {} + CalibratePolynomialFilter(std::vector coefficients) : coefficients_(std::move(coefficients)) {} optional new_value(float value) override; protected: diff --git a/esphome/components/sensor/sensor.h b/esphome/components/sensor/sensor.h index fe528603c4..9b1f4d7f86 100644 --- a/esphome/components/sensor/sensor.h +++ b/esphome/components/sensor/sensor.h @@ -8,21 +8,21 @@ namespace esphome { namespace sensor { #define LOG_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()); \ } \ - ESP_LOGCONFIG(TAG, "%s State Class: '%s'", prefix, state_class_to_string(obj->state_class)); \ - ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, obj->get_unit_of_measurement().c_str()); \ - ESP_LOGCONFIG(TAG, "%s Accuracy Decimals: %d", prefix, obj->get_accuracy_decimals()); \ - if (!obj->get_icon().empty()) { \ - ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, obj->get_icon().c_str()); \ + ESP_LOGCONFIG(TAG, "%s State Class: '%s'", prefix, state_class_to_string((obj)->state_class)); \ + ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, (obj)->get_unit_of_measurement().c_str()); \ + ESP_LOGCONFIG(TAG, "%s Accuracy Decimals: %d", prefix, (obj)->get_accuracy_decimals()); \ + if (!(obj)->get_icon().empty()) { \ + ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \ } \ - if (!obj->unique_id().empty()) { \ - ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, obj->unique_id().c_str()); \ + if (!(obj)->unique_id().empty()) { \ + ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, (obj)->unique_id().c_str()); \ } \ - if (obj->get_force_update()) { \ + if ((obj)->get_force_update()) { \ ESP_LOGV(TAG, "%s Force Update: YES", prefix); \ } \ } diff --git a/esphome/components/sgp30/sgp30.cpp b/esphome/components/sgp30/sgp30.cpp index 1ef43c1c73..a26f5f8b30 100644 --- a/esphome/components/sgp30/sgp30.cpp +++ b/esphome/components/sgp30/sgp30.cpp @@ -16,11 +16,11 @@ static const uint16_t SGP30_CMD_SET_IAQ_BASELINE = 0x201E; // Sensor baseline should first be relied on after 1H of operation, // if the sensor starts with a baseline value provided -const long IAQ_BASELINE_WARM_UP_SECONDS_WITH_BASELINE_PROVIDED = 3600; +const uint32_t IAQ_BASELINE_WARM_UP_SECONDS_WITH_BASELINE_PROVIDED = 3600; // Sensor baseline could first be relied on after 12H of operation, // if the sensor starts without any prior baseline value provided -const long IAQ_BASELINE_WARM_UP_SECONDS_WITHOUT_BASELINE = 43200; +const uint32_t IAQ_BASELINE_WARM_UP_SECONDS_WITHOUT_BASELINE = 43200; void SGP30Component::setup() { ESP_LOGCONFIG(TAG, "Setting up SGP30..."); @@ -204,7 +204,7 @@ void SGP30Component::dump_config() { } else { ESP_LOGCONFIG(TAG, " Baseline: No baseline configured"); } - ESP_LOGCONFIG(TAG, " Warm up time: %lds", this->required_warm_up_time_); + ESP_LOGCONFIG(TAG, " Warm up time: %us", this->required_warm_up_time_); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "eCO2", this->eco2_sensor_); diff --git a/esphome/components/sgp30/sgp30.h b/esphome/components/sgp30/sgp30.h index 27572e9c46..298a78e8dd 100644 --- a/esphome/components/sgp30/sgp30.h +++ b/esphome/components/sgp30/sgp30.h @@ -33,7 +33,7 @@ class SGP30Component : public PollingComponent, public i2c::I2CDevice { uint8_t sht_crc_(uint8_t data1, uint8_t data2); uint64_t serial_number_; uint16_t featureset_; - long required_warm_up_time_; + uint32_t required_warm_up_time_; enum ErrorCode { COMMUNICATION_FAILED, diff --git a/esphome/components/sgp40/sensirion_voc_algorithm.cpp b/esphome/components/sgp40/sensirion_voc_algorithm.cpp index 1a6b1bd0ef..f3cdeee35b 100644 --- a/esphome/components/sgp40/sensirion_voc_algorithm.cpp +++ b/esphome/components/sgp40/sensirion_voc_algorithm.cpp @@ -364,41 +364,41 @@ static void voc_algorithm_mean_variance_estimator_init_instances(VocAlgorithmPar static void voc_algorithm_mean_variance_estimator_set_parameters(VocAlgorithmParams *params, fix16_t std_initial, fix16_t tau_mean_variance_hours, fix16_t gating_max_duration_minutes) { - params->m_Mean_Variance_Estimator__Gating_Max_Duration_Minutes = gating_max_duration_minutes; - params->m_Mean_Variance_Estimator___Initialized = false; - params->m_Mean_Variance_Estimator___Mean = F16(0.); - params->m_Mean_Variance_Estimator___Sraw_Offset = F16(0.); - params->m_Mean_Variance_Estimator___Std = std_initial; - params->m_Mean_Variance_Estimator___Gamma = + params->m_Mean_Variance_Estimator_Gating_Max_Duration_Minutes = gating_max_duration_minutes; + params->m_Mean_Variance_Estimator_Initialized = false; + params->m_Mean_Variance_Estimator_Mean = F16(0.); + params->m_Mean_Variance_Estimator_Sraw_Offset = F16(0.); + params->m_Mean_Variance_Estimator_Std = std_initial; + params->m_Mean_Variance_Estimator_Gamma = (fix16_div(F16((VOC_ALGORITHM_MEAN_VARIANCE_ESTIMATOR_GAMMA_SCALING * (VOC_ALGORITHM_SAMPLING_INTERVAL / 3600.))), (tau_mean_variance_hours + F16((VOC_ALGORITHM_SAMPLING_INTERVAL / 3600.))))); - params->m_Mean_Variance_Estimator___Gamma_Initial_Mean = + params->m_Mean_Variance_Estimator_Gamma_Initial_Mean = F16(((VOC_ALGORITHM_MEAN_VARIANCE_ESTIMATOR_GAMMA_SCALING * VOC_ALGORITHM_SAMPLING_INTERVAL) / (VOC_ALGORITHM_TAU_INITIAL_MEAN + VOC_ALGORITHM_SAMPLING_INTERVAL))); - params->m_Mean_Variance_Estimator___Gamma_Initial_Variance = + params->m_Mean_Variance_Estimator_Gamma_Initial_Variance = F16(((VOC_ALGORITHM_MEAN_VARIANCE_ESTIMATOR_GAMMA_SCALING * VOC_ALGORITHM_SAMPLING_INTERVAL) / (VOC_ALGORITHM_TAU_INITIAL_VARIANCE + VOC_ALGORITHM_SAMPLING_INTERVAL))); - params->m_Mean_Variance_Estimator__Gamma_Mean = F16(0.); - params->m_Mean_Variance_Estimator__Gamma_Variance = F16(0.); - params->m_Mean_Variance_Estimator___Uptime_Gamma = F16(0.); - params->m_Mean_Variance_Estimator___Uptime_Gating = F16(0.); - params->m_Mean_Variance_Estimator___Gating_Duration_Minutes = F16(0.); + params->m_Mean_Variance_Estimator_Gamma_Mean = F16(0.); + params->m_Mean_Variance_Estimator_Gamma_Variance = F16(0.); + params->m_Mean_Variance_Estimator_Uptime_Gamma = F16(0.); + params->m_Mean_Variance_Estimator_Uptime_Gating = F16(0.); + params->m_Mean_Variance_Estimator_Gating_Duration_Minutes = F16(0.); } static void voc_algorithm_mean_variance_estimator_set_states(VocAlgorithmParams *params, fix16_t mean, fix16_t std, fix16_t uptime_gamma) { - params->m_Mean_Variance_Estimator___Mean = mean; - params->m_Mean_Variance_Estimator___Std = std; - params->m_Mean_Variance_Estimator___Uptime_Gamma = uptime_gamma; - params->m_Mean_Variance_Estimator___Initialized = true; + params->m_Mean_Variance_Estimator_Mean = mean; + params->m_Mean_Variance_Estimator_Std = std; + params->m_Mean_Variance_Estimator_Uptime_Gamma = uptime_gamma; + params->m_Mean_Variance_Estimator_Initialized = true; } static fix16_t voc_algorithm_mean_variance_estimator_get_std(VocAlgorithmParams *params) { - return params->m_Mean_Variance_Estimator___Std; + return params->m_Mean_Variance_Estimator_Std; } static fix16_t voc_algorithm_mean_variance_estimator_get_mean(VocAlgorithmParams *params) { - return (params->m_Mean_Variance_Estimator___Mean + params->m_Mean_Variance_Estimator___Sraw_Offset); + return (params->m_Mean_Variance_Estimator_Mean + params->m_Mean_Variance_Estimator_Sraw_Offset); } static void voc_algorithm_mean_variance_estimator_calculate_gamma(VocAlgorithmParams *params, @@ -414,58 +414,58 @@ static void voc_algorithm_mean_variance_estimator_calculate_gamma(VocAlgorithmPa fix16_t sigmoid_gating_variance; uptime_limit = F16((VOC_ALGORITHM_MEAN_VARIANCE_ESTIMATOR_FI_X16_MAX - VOC_ALGORITHM_SAMPLING_INTERVAL)); - if ((params->m_Mean_Variance_Estimator___Uptime_Gamma < uptime_limit)) { - params->m_Mean_Variance_Estimator___Uptime_Gamma = - (params->m_Mean_Variance_Estimator___Uptime_Gamma + F16(VOC_ALGORITHM_SAMPLING_INTERVAL)); + if ((params->m_Mean_Variance_Estimator_Uptime_Gamma < uptime_limit)) { + params->m_Mean_Variance_Estimator_Uptime_Gamma = + (params->m_Mean_Variance_Estimator_Uptime_Gamma + F16(VOC_ALGORITHM_SAMPLING_INTERVAL)); } - if ((params->m_Mean_Variance_Estimator___Uptime_Gating < uptime_limit)) { - params->m_Mean_Variance_Estimator___Uptime_Gating = - (params->m_Mean_Variance_Estimator___Uptime_Gating + F16(VOC_ALGORITHM_SAMPLING_INTERVAL)); + if ((params->m_Mean_Variance_Estimator_Uptime_Gating < uptime_limit)) { + params->m_Mean_Variance_Estimator_Uptime_Gating = + (params->m_Mean_Variance_Estimator_Uptime_Gating + F16(VOC_ALGORITHM_SAMPLING_INTERVAL)); } voc_algorithm_mean_variance_estimator_sigmoid_set_parameters(params, F16(1.), F16(VOC_ALGORITHM_INIT_DURATION_MEAN), F16(VOC_ALGORITHM_INIT_TRANSITION_MEAN)); sigmoid_gamma_mean = - voc_algorithm_mean_variance_estimator_sigmoid_process(params, params->m_Mean_Variance_Estimator___Uptime_Gamma); + voc_algorithm_mean_variance_estimator_sigmoid_process(params, params->m_Mean_Variance_Estimator_Uptime_Gamma); gamma_mean = - (params->m_Mean_Variance_Estimator___Gamma + - (fix16_mul((params->m_Mean_Variance_Estimator___Gamma_Initial_Mean - params->m_Mean_Variance_Estimator___Gamma), + (params->m_Mean_Variance_Estimator_Gamma + + (fix16_mul((params->m_Mean_Variance_Estimator_Gamma_Initial_Mean - params->m_Mean_Variance_Estimator_Gamma), sigmoid_gamma_mean))); gating_threshold_mean = (F16(VOC_ALGORITHM_GATING_THRESHOLD) + (fix16_mul(F16((VOC_ALGORITHM_GATING_THRESHOLD_INITIAL - VOC_ALGORITHM_GATING_THRESHOLD)), voc_algorithm_mean_variance_estimator_sigmoid_process( - params, params->m_Mean_Variance_Estimator___Uptime_Gating)))); + params, params->m_Mean_Variance_Estimator_Uptime_Gating)))); voc_algorithm_mean_variance_estimator_sigmoid_set_parameters(params, F16(1.), gating_threshold_mean, F16(VOC_ALGORITHM_GATING_THRESHOLD_TRANSITION)); sigmoid_gating_mean = voc_algorithm_mean_variance_estimator_sigmoid_process(params, voc_index_from_prior); - params->m_Mean_Variance_Estimator__Gamma_Mean = (fix16_mul(sigmoid_gating_mean, gamma_mean)); + params->m_Mean_Variance_Estimator_Gamma_Mean = (fix16_mul(sigmoid_gating_mean, gamma_mean)); voc_algorithm_mean_variance_estimator_sigmoid_set_parameters( params, F16(1.), F16(VOC_ALGORITHM_INIT_DURATION_VARIANCE), F16(VOC_ALGORITHM_INIT_TRANSITION_VARIANCE)); sigmoid_gamma_variance = - voc_algorithm_mean_variance_estimator_sigmoid_process(params, params->m_Mean_Variance_Estimator___Uptime_Gamma); - gamma_variance = (params->m_Mean_Variance_Estimator___Gamma + - (fix16_mul((params->m_Mean_Variance_Estimator___Gamma_Initial_Variance - - params->m_Mean_Variance_Estimator___Gamma), - (sigmoid_gamma_variance - sigmoid_gamma_mean)))); + voc_algorithm_mean_variance_estimator_sigmoid_process(params, params->m_Mean_Variance_Estimator_Uptime_Gamma); + gamma_variance = + (params->m_Mean_Variance_Estimator_Gamma + + (fix16_mul((params->m_Mean_Variance_Estimator_Gamma_Initial_Variance - params->m_Mean_Variance_Estimator_Gamma), + (sigmoid_gamma_variance - sigmoid_gamma_mean)))); gating_threshold_variance = (F16(VOC_ALGORITHM_GATING_THRESHOLD) + (fix16_mul(F16((VOC_ALGORITHM_GATING_THRESHOLD_INITIAL - VOC_ALGORITHM_GATING_THRESHOLD)), voc_algorithm_mean_variance_estimator_sigmoid_process( - params, params->m_Mean_Variance_Estimator___Uptime_Gating)))); + params, params->m_Mean_Variance_Estimator_Uptime_Gating)))); voc_algorithm_mean_variance_estimator_sigmoid_set_parameters(params, F16(1.), gating_threshold_variance, F16(VOC_ALGORITHM_GATING_THRESHOLD_TRANSITION)); sigmoid_gating_variance = voc_algorithm_mean_variance_estimator_sigmoid_process(params, voc_index_from_prior); - params->m_Mean_Variance_Estimator__Gamma_Variance = (fix16_mul(sigmoid_gating_variance, gamma_variance)); - params->m_Mean_Variance_Estimator___Gating_Duration_Minutes = - (params->m_Mean_Variance_Estimator___Gating_Duration_Minutes + + params->m_Mean_Variance_Estimator_Gamma_Variance = (fix16_mul(sigmoid_gating_variance, gamma_variance)); + params->m_Mean_Variance_Estimator_Gating_Duration_Minutes = + (params->m_Mean_Variance_Estimator_Gating_Duration_Minutes + (fix16_mul(F16((VOC_ALGORITHM_SAMPLING_INTERVAL / 60.)), ((fix16_mul((F16(1.) - sigmoid_gating_mean), F16((1. + VOC_ALGORITHM_GATING_MAX_RATIO)))) - F16(VOC_ALGORITHM_GATING_MAX_RATIO))))); - if ((params->m_Mean_Variance_Estimator___Gating_Duration_Minutes < F16(0.))) { - params->m_Mean_Variance_Estimator___Gating_Duration_Minutes = F16(0.); + if ((params->m_Mean_Variance_Estimator_Gating_Duration_Minutes < F16(0.))) { + params->m_Mean_Variance_Estimator_Gating_Duration_Minutes = F16(0.); } - if ((params->m_Mean_Variance_Estimator___Gating_Duration_Minutes > - params->m_Mean_Variance_Estimator__Gating_Max_Duration_Minutes)) { - params->m_Mean_Variance_Estimator___Uptime_Gating = F16(0.); + if ((params->m_Mean_Variance_Estimator_Gating_Duration_Minutes > + params->m_Mean_Variance_Estimator_Gating_Max_Duration_Minutes)) { + params->m_Mean_Variance_Estimator_Uptime_Gating = F16(0.); } } @@ -475,42 +475,42 @@ static void voc_algorithm_mean_variance_estimator_process(VocAlgorithmParams *pa fix16_t c; fix16_t additional_scaling; - if ((!params->m_Mean_Variance_Estimator___Initialized)) { - params->m_Mean_Variance_Estimator___Initialized = true; - params->m_Mean_Variance_Estimator___Sraw_Offset = sraw; - params->m_Mean_Variance_Estimator___Mean = F16(0.); + if ((!params->m_Mean_Variance_Estimator_Initialized)) { + params->m_Mean_Variance_Estimator_Initialized = true; + params->m_Mean_Variance_Estimator_Sraw_Offset = sraw; + params->m_Mean_Variance_Estimator_Mean = F16(0.); } else { - if (((params->m_Mean_Variance_Estimator___Mean >= F16(100.)) || - (params->m_Mean_Variance_Estimator___Mean <= F16(-100.)))) { - params->m_Mean_Variance_Estimator___Sraw_Offset = - (params->m_Mean_Variance_Estimator___Sraw_Offset + params->m_Mean_Variance_Estimator___Mean); - params->m_Mean_Variance_Estimator___Mean = F16(0.); + if (((params->m_Mean_Variance_Estimator_Mean >= F16(100.)) || + (params->m_Mean_Variance_Estimator_Mean <= F16(-100.)))) { + params->m_Mean_Variance_Estimator_Sraw_Offset = + (params->m_Mean_Variance_Estimator_Sraw_Offset + params->m_Mean_Variance_Estimator_Mean); + params->m_Mean_Variance_Estimator_Mean = F16(0.); } - sraw = (sraw - params->m_Mean_Variance_Estimator___Sraw_Offset); + sraw = (sraw - params->m_Mean_Variance_Estimator_Sraw_Offset); voc_algorithm_mean_variance_estimator_calculate_gamma(params, voc_index_from_prior); - delta_sgp = (fix16_div((sraw - params->m_Mean_Variance_Estimator___Mean), + delta_sgp = (fix16_div((sraw - params->m_Mean_Variance_Estimator_Mean), F16(VOC_ALGORITHM_MEAN_VARIANCE_ESTIMATOR_GAMMA_SCALING))); if ((delta_sgp < F16(0.))) { - c = (params->m_Mean_Variance_Estimator___Std - delta_sgp); + c = (params->m_Mean_Variance_Estimator_Std - delta_sgp); } else { - c = (params->m_Mean_Variance_Estimator___Std + delta_sgp); + c = (params->m_Mean_Variance_Estimator_Std + delta_sgp); } additional_scaling = F16(1.); if ((c > F16(1440.))) { additional_scaling = F16(4.); } - params->m_Mean_Variance_Estimator___Std = (fix16_mul( + params->m_Mean_Variance_Estimator_Std = (fix16_mul( fix16_sqrt((fix16_mul(additional_scaling, (F16(VOC_ALGORITHM_MEAN_VARIANCE_ESTIMATOR_GAMMA_SCALING) - - params->m_Mean_Variance_Estimator__Gamma_Variance)))), - fix16_sqrt(((fix16_mul(params->m_Mean_Variance_Estimator___Std, - (fix16_div(params->m_Mean_Variance_Estimator___Std, + params->m_Mean_Variance_Estimator_Gamma_Variance)))), + fix16_sqrt(((fix16_mul(params->m_Mean_Variance_Estimator_Std, + (fix16_div(params->m_Mean_Variance_Estimator_Std, (fix16_mul(F16(VOC_ALGORITHM_MEAN_VARIANCE_ESTIMATOR_GAMMA_SCALING), additional_scaling)))))) + - (fix16_mul((fix16_div((fix16_mul(params->m_Mean_Variance_Estimator__Gamma_Variance, delta_sgp)), + (fix16_mul((fix16_div((fix16_mul(params->m_Mean_Variance_Estimator_Gamma_Variance, delta_sgp)), additional_scaling)), delta_sgp)))))); - params->m_Mean_Variance_Estimator___Mean = (params->m_Mean_Variance_Estimator___Mean + - (fix16_mul(params->m_Mean_Variance_Estimator__Gamma_Mean, delta_sgp))); + params->m_Mean_Variance_Estimator_Mean = + (params->m_Mean_Variance_Estimator_Mean + (fix16_mul(params->m_Mean_Variance_Estimator_Gamma_Mean, delta_sgp))); } } @@ -520,22 +520,21 @@ static void voc_algorithm_mean_variance_estimator_sigmoid_init(VocAlgorithmParam static void voc_algorithm_mean_variance_estimator_sigmoid_set_parameters(VocAlgorithmParams *params, fix16_t l, fix16_t x0, fix16_t k) { - params->m_Mean_Variance_Estimator___Sigmoid__L = l; - params->m_Mean_Variance_Estimator___Sigmoid__K = k; - params->m_Mean_Variance_Estimator___Sigmoid__X0 = x0; + params->m_Mean_Variance_Estimator_Sigmoid_L = l; + params->m_Mean_Variance_Estimator_Sigmoid_K = k; + params->m_Mean_Variance_Estimator_Sigmoid_X0 = x0; } static fix16_t voc_algorithm_mean_variance_estimator_sigmoid_process(VocAlgorithmParams *params, fix16_t sample) { fix16_t x; - x = (fix16_mul(params->m_Mean_Variance_Estimator___Sigmoid__K, - (sample - params->m_Mean_Variance_Estimator___Sigmoid__X0))); + x = (fix16_mul(params->m_Mean_Variance_Estimator_Sigmoid_K, (sample - params->m_Mean_Variance_Estimator_Sigmoid_X0))); if ((x < F16(-50.))) { - return params->m_Mean_Variance_Estimator___Sigmoid__L; + return params->m_Mean_Variance_Estimator_Sigmoid_L; } else if ((x > F16(50.))) { return F16(0.); } else { - return (fix16_div(params->m_Mean_Variance_Estimator___Sigmoid__L, (F16(1.) + fix16_exp(x)))); + return (fix16_div(params->m_Mean_Variance_Estimator_Sigmoid_L, (F16(1.) + fix16_exp(x)))); } } @@ -544,13 +543,13 @@ static void voc_algorithm_mox_model_init(VocAlgorithmParams *params) { } static void voc_algorithm_mox_model_set_parameters(VocAlgorithmParams *params, fix16_t sraw_std, fix16_t sraw_mean) { - params->m_Mox_Model__Sraw_Std = sraw_std; - params->m_Mox_Model__Sraw_Mean = sraw_mean; + params->m_Mox_Model_Sraw_Std = sraw_std; + params->m_Mox_Model_Sraw_Mean = sraw_mean; } static fix16_t voc_algorithm_mox_model_process(VocAlgorithmParams *params, fix16_t sraw) { - return (fix16_mul((fix16_div((sraw - params->m_Mox_Model__Sraw_Mean), - (-(params->m_Mox_Model__Sraw_Std + F16(VOC_ALGORITHM_SRAW_STD_BONUS))))), + return (fix16_mul((fix16_div((sraw - params->m_Mox_Model_Sraw_Mean), + (-(params->m_Mox_Model_Sraw_Std + F16(VOC_ALGORITHM_SRAW_STD_BONUS))))), F16(VOC_ALGORITHM_VOC_INDEX_GAIN))); } @@ -559,7 +558,7 @@ static void voc_algorithm_sigmoid_scaled_init(VocAlgorithmParams *params) { } static void voc_algorithm_sigmoid_scaled_set_parameters(VocAlgorithmParams *params, fix16_t offset) { - params->m_Sigmoid_Scaled__Offset = offset; + params->m_Sigmoid_Scaled_Offset = offset; } static fix16_t voc_algorithm_sigmoid_scaled_process(VocAlgorithmParams *params, fix16_t sample) { @@ -574,10 +573,10 @@ static fix16_t voc_algorithm_sigmoid_scaled_process(VocAlgorithmParams *params, } else { if ((sample >= F16(0.))) { shift = - (fix16_div((F16(VOC_ALGORITHM_SIGMOID_L) - (fix16_mul(F16(5.), params->m_Sigmoid_Scaled__Offset))), F16(4.))); + (fix16_div((F16(VOC_ALGORITHM_SIGMOID_L) - (fix16_mul(F16(5.), params->m_Sigmoid_Scaled_Offset))), F16(4.))); return ((fix16_div((F16(VOC_ALGORITHM_SIGMOID_L) + shift), (F16(1.) + fix16_exp(x)))) - shift); } else { - return (fix16_mul((fix16_div(params->m_Sigmoid_Scaled__Offset, F16(VOC_ALGORITHM_VOC_INDEX_OFFSET_DEFAULT))), + return (fix16_mul((fix16_div(params->m_Sigmoid_Scaled_Offset, F16(VOC_ALGORITHM_VOC_INDEX_OFFSET_DEFAULT))), (fix16_div(F16(VOC_ALGORITHM_SIGMOID_L), (F16(1.) + fix16_exp(x)))))); } } @@ -588,11 +587,11 @@ static void voc_algorithm_adaptive_lowpass_init(VocAlgorithmParams *params) { } static void voc_algorithm_adaptive_lowpass_set_parameters(VocAlgorithmParams *params) { - params->m_Adaptive_Lowpass__A1 = + params->m_Adaptive_Lowpass_A1 = F16((VOC_ALGORITHM_SAMPLING_INTERVAL / (VOC_ALGORITHM_LP_TAU_FAST + VOC_ALGORITHM_SAMPLING_INTERVAL))); - params->m_Adaptive_Lowpass__A2 = + params->m_Adaptive_Lowpass_A2 = F16((VOC_ALGORITHM_SAMPLING_INTERVAL / (VOC_ALGORITHM_LP_TAU_SLOW + VOC_ALGORITHM_SAMPLING_INTERVAL))); - params->m_Adaptive_Lowpass___Initialized = false; + params->m_Adaptive_Lowpass_Initialized = false; } static fix16_t voc_algorithm_adaptive_lowpass_process(VocAlgorithmParams *params, fix16_t sample) { @@ -601,19 +600,19 @@ static fix16_t voc_algorithm_adaptive_lowpass_process(VocAlgorithmParams *params fix16_t tau_a; fix16_t a3; - if ((!params->m_Adaptive_Lowpass___Initialized)) { - params->m_Adaptive_Lowpass___X1 = sample; - params->m_Adaptive_Lowpass___X2 = sample; - params->m_Adaptive_Lowpass___X3 = sample; - params->m_Adaptive_Lowpass___Initialized = true; + if ((!params->m_Adaptive_Lowpass_Initialized)) { + params->m_Adaptive_Lowpass_X1 = sample; + params->m_Adaptive_Lowpass_X2 = sample; + params->m_Adaptive_Lowpass_X3 = sample; + params->m_Adaptive_Lowpass_Initialized = true; } - params->m_Adaptive_Lowpass___X1 = - ((fix16_mul((F16(1.) - params->m_Adaptive_Lowpass__A1), params->m_Adaptive_Lowpass___X1)) + - (fix16_mul(params->m_Adaptive_Lowpass__A1, sample))); - params->m_Adaptive_Lowpass___X2 = - ((fix16_mul((F16(1.) - params->m_Adaptive_Lowpass__A2), params->m_Adaptive_Lowpass___X2)) + - (fix16_mul(params->m_Adaptive_Lowpass__A2, sample))); - abs_delta = (params->m_Adaptive_Lowpass___X1 - params->m_Adaptive_Lowpass___X2); + params->m_Adaptive_Lowpass_X1 = + ((fix16_mul((F16(1.) - params->m_Adaptive_Lowpass_A1), params->m_Adaptive_Lowpass_X1)) + + (fix16_mul(params->m_Adaptive_Lowpass_A1, sample))); + params->m_Adaptive_Lowpass_X2 = + ((fix16_mul((F16(1.) - params->m_Adaptive_Lowpass_A2), params->m_Adaptive_Lowpass_X2)) + + (fix16_mul(params->m_Adaptive_Lowpass_A2, sample))); + abs_delta = (params->m_Adaptive_Lowpass_X1 - params->m_Adaptive_Lowpass_X2); if ((abs_delta < F16(0.))) { abs_delta = (-abs_delta); } @@ -621,9 +620,9 @@ static fix16_t voc_algorithm_adaptive_lowpass_process(VocAlgorithmParams *params tau_a = ((fix16_mul(F16((VOC_ALGORITHM_LP_TAU_SLOW - VOC_ALGORITHM_LP_TAU_FAST)), f1)) + F16(VOC_ALGORITHM_LP_TAU_FAST)); a3 = (fix16_div(F16(VOC_ALGORITHM_SAMPLING_INTERVAL), (F16(VOC_ALGORITHM_SAMPLING_INTERVAL) + tau_a))); - params->m_Adaptive_Lowpass___X3 = - ((fix16_mul((F16(1.) - a3), params->m_Adaptive_Lowpass___X3)) + (fix16_mul(a3, sample))); - return params->m_Adaptive_Lowpass___X3; + params->m_Adaptive_Lowpass_X3 = + ((fix16_mul((F16(1.) - a3), params->m_Adaptive_Lowpass_X3)) + (fix16_mul(a3, sample))); + return params->m_Adaptive_Lowpass_X3; } } // namespace sgp40 } // namespace esphome diff --git a/esphome/components/sgp40/sensirion_voc_algorithm.h b/esphome/components/sgp40/sensirion_voc_algorithm.h index 05431635ad..adef6b29e8 100644 --- a/esphome/components/sgp40/sensirion_voc_algorithm.h +++ b/esphome/components/sgp40/sensirion_voc_algorithm.h @@ -1,5 +1,5 @@ #pragma once -#include +#include namespace esphome { namespace sgp40 { @@ -52,31 +52,31 @@ struct VocAlgorithmParams { fix16_t mUptime; fix16_t mSraw; fix16_t mVoc_Index; - fix16_t m_Mean_Variance_Estimator__Gating_Max_Duration_Minutes; - bool m_Mean_Variance_Estimator___Initialized; - fix16_t m_Mean_Variance_Estimator___Mean; - fix16_t m_Mean_Variance_Estimator___Sraw_Offset; - fix16_t m_Mean_Variance_Estimator___Std; - fix16_t m_Mean_Variance_Estimator___Gamma; - fix16_t m_Mean_Variance_Estimator___Gamma_Initial_Mean; - fix16_t m_Mean_Variance_Estimator___Gamma_Initial_Variance; - fix16_t m_Mean_Variance_Estimator__Gamma_Mean; - fix16_t m_Mean_Variance_Estimator__Gamma_Variance; - fix16_t m_Mean_Variance_Estimator___Uptime_Gamma; - fix16_t m_Mean_Variance_Estimator___Uptime_Gating; - fix16_t m_Mean_Variance_Estimator___Gating_Duration_Minutes; - fix16_t m_Mean_Variance_Estimator___Sigmoid__L; - fix16_t m_Mean_Variance_Estimator___Sigmoid__K; - fix16_t m_Mean_Variance_Estimator___Sigmoid__X0; - fix16_t m_Mox_Model__Sraw_Std; - fix16_t m_Mox_Model__Sraw_Mean; - fix16_t m_Sigmoid_Scaled__Offset; - fix16_t m_Adaptive_Lowpass__A1; - fix16_t m_Adaptive_Lowpass__A2; - bool m_Adaptive_Lowpass___Initialized; - fix16_t m_Adaptive_Lowpass___X1; - fix16_t m_Adaptive_Lowpass___X2; - fix16_t m_Adaptive_Lowpass___X3; + fix16_t m_Mean_Variance_Estimator_Gating_Max_Duration_Minutes; + bool m_Mean_Variance_Estimator_Initialized; + fix16_t m_Mean_Variance_Estimator_Mean; + fix16_t m_Mean_Variance_Estimator_Sraw_Offset; + fix16_t m_Mean_Variance_Estimator_Std; + fix16_t m_Mean_Variance_Estimator_Gamma; + fix16_t m_Mean_Variance_Estimator_Gamma_Initial_Mean; + fix16_t m_Mean_Variance_Estimator_Gamma_Initial_Variance; + fix16_t m_Mean_Variance_Estimator_Gamma_Mean; + fix16_t m_Mean_Variance_Estimator_Gamma_Variance; + fix16_t m_Mean_Variance_Estimator_Uptime_Gamma; + fix16_t m_Mean_Variance_Estimator_Uptime_Gating; + fix16_t m_Mean_Variance_Estimator_Gating_Duration_Minutes; + fix16_t m_Mean_Variance_Estimator_Sigmoid_L; + fix16_t m_Mean_Variance_Estimator_Sigmoid_K; + fix16_t m_Mean_Variance_Estimator_Sigmoid_X0; + fix16_t m_Mox_Model_Sraw_Std; + fix16_t m_Mox_Model_Sraw_Mean; + fix16_t m_Sigmoid_Scaled_Offset; + fix16_t m_Adaptive_Lowpass_A1; + fix16_t m_Adaptive_Lowpass_A2; + bool m_Adaptive_Lowpass_Initialized; + fix16_t m_Adaptive_Lowpass_X1; + fix16_t m_Adaptive_Lowpass_X2; + fix16_t m_Adaptive_Lowpass_X3; }; /** diff --git a/esphome/components/sgp40/sgp40.h b/esphome/components/sgp40/sgp40.h index d448b5e45c..b9ea365169 100644 --- a/esphome/components/sgp40/sgp40.h +++ b/esphome/components/sgp40/sgp40.h @@ -31,10 +31,10 @@ static const uint16_t SGP40_CMD_SELF_TEST = 0x280e; // Shortest time interval of 3H for storing baseline values. // Prevents wear of the flash because of too many write operations -const long SHORTEST_BASELINE_STORE_INTERVAL = 10800; +const uint32_t SHORTEST_BASELINE_STORE_INTERVAL = 10800; // Store anyway if the baseline difference exceeds the max storage diff value -const long MAXIMUM_STORAGE_DIFF = 50; +const uint32_t MAXIMUM_STORAGE_DIFF = 50; class SGP40Component; @@ -65,7 +65,7 @@ class SGP40Component : public PollingComponent, public sensor::Sensor, public i2 uint8_t generate_crc_(const uint8_t *data, uint8_t datalen); uint16_t measure_raw_(); ESPPreferenceObject pref_; - long seconds_since_last_store_; + int32_t seconds_since_last_store_; SGP40Baselines baselines_storage_; VocAlgorithmParams voc_algorithm_params_; bool store_baseline_; diff --git a/esphome/components/sim800l/sim800l.cpp b/esphome/components/sim800l/sim800l.cpp index 4fb4b0abf0..2cbf8d6ff2 100644 --- a/esphome/components/sim800l/sim800l.cpp +++ b/esphome/components/sim800l/sim800l.cpp @@ -1,6 +1,6 @@ #include "sim800l.h" #include "esphome/core/log.h" -#include +#include namespace esphome { namespace sim800l { @@ -40,7 +40,7 @@ void Sim800LComponent::update() { } } -void Sim800LComponent::send_cmd_(std::string message) { +void Sim800LComponent::send_cmd_(const std::string &message) { ESP_LOGV(TAG, "S: %s - %d", message.c_str(), this->state_); this->watch_dog_ = 0; this->write_str(message.c_str()); @@ -268,7 +268,7 @@ void Sim800LComponent::loop() { } } -void Sim800LComponent::send_sms(std::string recipient, std::string message) { +void Sim800LComponent::send_sms(const std::string &recipient, const std::string &message) { ESP_LOGD(TAG, "Sending to %s: %s", recipient.c_str(), message.c_str()); this->recipient_ = recipient; this->outgoing_message_ = message; @@ -279,7 +279,7 @@ void Sim800LComponent::dump_config() { ESP_LOGCONFIG(TAG, "SIM800L:"); ESP_LOGCONFIG(TAG, " RSSI: %d dB", this->rssi_); } -void Sim800LComponent::dial(std::string recipient) { +void Sim800LComponent::dial(const std::string &recipient) { ESP_LOGD(TAG, "Dialing %s", recipient.c_str()); this->recipient_ = recipient; this->dial_pending_ = true; diff --git a/esphome/components/sim800l/sim800l.h b/esphome/components/sim800l/sim800l.h index f8ccf88977..fa9c392bfc 100644 --- a/esphome/components/sim800l/sim800l.h +++ b/esphome/components/sim800l/sim800l.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "esphome/core/component.h" #include "esphome/components/uart/uart.h" #include "esphome/core/automation.h" @@ -43,11 +45,11 @@ class Sim800LComponent : public uart::UARTDevice, public PollingComponent { void add_on_sms_received_callback(std::function callback) { this->callback_.add(std::move(callback)); } - void send_sms(std::string recipient, std::string message); - void dial(std::string recipient); + void send_sms(const std::string &recipient, const std::string &message); + void dial(const std::string &recipient); protected: - void send_cmd_(std::string); + void send_cmd_(const std::string &); void parse_cmd_(std::string); std::string sender_; @@ -72,7 +74,7 @@ class Sim800LReceivedMessageTrigger : public Trigger { public: explicit Sim800LReceivedMessageTrigger(Sim800LComponent *parent) { parent->add_on_sms_received_callback( - [this](std::string message, std::string sender) { this->trigger(message, sender); }); + [this](std::string message, std::string sender) { this->trigger(std::move(message), std::move(sender)); }); } }; diff --git a/esphome/components/slow_pwm/slow_pwm_output.cpp b/esphome/components/slow_pwm/slow_pwm_output.cpp index 04a0d86bf7..b8fec2adf6 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.cpp +++ b/esphome/components/slow_pwm/slow_pwm_output.cpp @@ -12,7 +12,7 @@ void SlowPWMOutput::setup() { } void SlowPWMOutput::loop() { - unsigned long now = millis(); + uint32_t now = millis(); float scaled_state = this->state_ * this->period_; if (now - this->period_start_time_ > this->period_) { diff --git a/esphome/components/switch/switch.h b/esphome/components/switch/switch.h index cd6cec429f..966119a29f 100644 --- a/esphome/components/switch/switch.h +++ b/esphome/components/switch/switch.h @@ -8,15 +8,15 @@ namespace esphome { namespace switch_ { #define LOG_SWITCH(prefix, type, obj) \ - if (obj != nullptr) { \ - ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \ - if (!obj->get_icon().empty()) { \ - ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, obj->get_icon().c_str()); \ + if ((obj) != nullptr) { \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, (obj)->get_name().c_str()); \ + if (!(obj)->get_icon().empty()) { \ + ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \ } \ - if (obj->assumed_state()) { \ + if ((obj)->assumed_state()) { \ ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \ } \ - if (obj->is_inverted()) { \ + if ((obj)->is_inverted()) { \ ESP_LOGCONFIG(TAG, "%s Inverted: YES", prefix); \ } \ } diff --git a/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp b/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp index c00bf8f441..202cae37c3 100644 --- a/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp +++ b/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp @@ -5,7 +5,7 @@ namespace teleinfo { static const char *TAG = "teleinfo_sensor"; TeleInfoSensor::TeleInfoSensor(const char *tag) { this->tag = std::string(tag); } -void TeleInfoSensor::publish_val(std::string val) { +void TeleInfoSensor::publish_val(const std::string &val) { auto newval = parse_float(val); publish_state(*newval); } diff --git a/esphome/components/teleinfo/sensor/teleinfo_sensor.h b/esphome/components/teleinfo/sensor/teleinfo_sensor.h index de46cbfd1a..56781166ab 100644 --- a/esphome/components/teleinfo/sensor/teleinfo_sensor.h +++ b/esphome/components/teleinfo/sensor/teleinfo_sensor.h @@ -8,7 +8,7 @@ namespace teleinfo { class TeleInfoSensor : public TeleInfoListener, public sensor::Sensor, public Component { public: TeleInfoSensor(const char *tag); - void publish_val(std::string val) override; + void publish_val(const std::string &val) override; void dump_config() override; }; diff --git a/esphome/components/teleinfo/teleinfo.cpp b/esphome/components/teleinfo/teleinfo.cpp index bd233c9595..36e6b4a2b1 100644 --- a/esphome/components/teleinfo/teleinfo.cpp +++ b/esphome/components/teleinfo/teleinfo.cpp @@ -148,7 +148,7 @@ void TeleInfo::loop() { break; } } -void TeleInfo::publish_value_(std::string tag, std::string val) { +void TeleInfo::publish_value_(const std::string &tag, const std::string &val) { for (auto element : teleinfo_listeners_) { if (tag != element->tag) continue; diff --git a/esphome/components/teleinfo/teleinfo.h b/esphome/components/teleinfo/teleinfo.h index 3932c4758e..f10024691e 100644 --- a/esphome/components/teleinfo/teleinfo.h +++ b/esphome/components/teleinfo/teleinfo.h @@ -16,7 +16,7 @@ static const uint16_t MAX_BUF_SIZE = 1024; class TeleInfoListener { public: std::string tag; - virtual void publish_val(std::string val){}; + virtual void publish_val(const std::string &val){}; }; class TeleInfo : public PollingComponent, public uart::UARTDevice { public: @@ -44,7 +44,7 @@ class TeleInfo : public PollingComponent, public uart::UARTDevice { } state_{OFF}; bool read_chars_until_(bool drop, uint8_t c); bool check_crc_(const char *grp, const char *grp_end); - void publish_value_(std::string tag, std::string val); + void publish_value_(const std::string &tag, const std::string &val); }; } // namespace teleinfo } // namespace esphome diff --git a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp index ac48aeabbd..221e2cba4c 100644 --- a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp +++ b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp @@ -5,7 +5,7 @@ namespace teleinfo { static const char *TAG = "teleinfo_text_sensor"; TeleInfoTextSensor::TeleInfoTextSensor(const char *tag) { this->tag = std::string(tag); } -void TeleInfoTextSensor::publish_val(std::string val) { publish_state(val); } +void TeleInfoTextSensor::publish_val(const std::string &val) { publish_state(val); } void TeleInfoTextSensor::dump_config() { LOG_TEXT_SENSOR(" ", tag.c_str(), this); } } // namespace teleinfo } // namespace esphome diff --git a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h index be355151ce..5a7dc9d1a7 100644 --- a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h +++ b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h @@ -6,7 +6,7 @@ namespace teleinfo { class TeleInfoTextSensor : public TeleInfoListener, public text_sensor::TextSensor, public Component { public: TeleInfoTextSensor(const char *tag); - void publish_val(std::string val) override; + void publish_val(const std::string &val) override; void dump_config() override; }; } // namespace teleinfo diff --git a/esphome/components/text_sensor/automation.h b/esphome/components/text_sensor/automation.h index 6810d10b13..d82fd27c1f 100644 --- a/esphome/components/text_sensor/automation.h +++ b/esphome/components/text_sensor/automation.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "esphome/core/component.h" #include "esphome/core/automation.h" #include "esphome/components/text_sensor/text_sensor.h" @@ -10,7 +12,7 @@ namespace text_sensor { class TextSensorStateTrigger : public Trigger { public: explicit TextSensorStateTrigger(TextSensor *parent) { - parent->add_on_state_callback([this](std::string value) { this->trigger(value); }); + parent->add_on_state_callback([this](std::string value) { this->trigger(std::move(value)); }); } }; diff --git a/esphome/components/text_sensor/text_sensor.cpp b/esphome/components/text_sensor/text_sensor.cpp index d4f5ef434a..0b6a02b2d4 100644 --- a/esphome/components/text_sensor/text_sensor.cpp +++ b/esphome/components/text_sensor/text_sensor.cpp @@ -9,7 +9,7 @@ static const char *TAG = "text_sensor"; TextSensor::TextSensor() : TextSensor("") {} TextSensor::TextSensor(const std::string &name) : Nameable(name) {} -void TextSensor::publish_state(std::string state) { +void TextSensor::publish_state(const std::string &state) { this->state = state; this->has_state_ = true; ESP_LOGD(TAG, "'%s': Sending state '%s'", this->name_.c_str(), state.c_str()); diff --git a/esphome/components/text_sensor/text_sensor.h b/esphome/components/text_sensor/text_sensor.h index 85c2b644a0..5c6e5be51a 100644 --- a/esphome/components/text_sensor/text_sensor.h +++ b/esphome/components/text_sensor/text_sensor.h @@ -7,13 +7,13 @@ namespace esphome { namespace text_sensor { #define LOG_TEXT_SENSOR(prefix, type, obj) \ - if (obj != nullptr) { \ - ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \ - if (!obj->get_icon().empty()) { \ - ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, obj->get_icon().c_str()); \ + if ((obj) != nullptr) { \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, (obj)->get_name().c_str()); \ + if (!(obj)->get_icon().empty()) { \ + ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \ } \ - if (!obj->unique_id().empty()) { \ - ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, obj->unique_id().c_str()); \ + if (!(obj)->unique_id().empty()) { \ + ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, (obj)->unique_id().c_str()); \ } \ } @@ -22,7 +22,7 @@ class TextSensor : public Nameable { explicit TextSensor(); explicit TextSensor(const std::string &name); - void publish_state(std::string state); + void publish_state(const std::string &state); void set_icon(const std::string &icon); diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index 44ff505ecc..4bda6bdfe9 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -4,7 +4,7 @@ #ifdef ARDUINO_ARCH_ESP8266 #include "sys/time.h" #endif -#include "errno.h" +#include namespace esphome { namespace time { diff --git a/esphome/components/time/real_time_clock.h b/esphome/components/time/real_time_clock.h index c591482729..92a25fe993 100644 --- a/esphome/components/time/real_time_clock.h +++ b/esphome/components/time/real_time_clock.h @@ -1,11 +1,11 @@ #pragma once +#include "esphome/core/automation.h" #include "esphome/core/component.h" #include "esphome/core/helpers.h" -#include "esphome/core/automation.h" -#include -#include #include +#include +#include namespace esphome { namespace time { diff --git a/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp b/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp index 6b2954a6a0..abc4051514 100644 --- a/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp +++ b/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp @@ -7,7 +7,7 @@ namespace tuya { static const char *TAG = "tuya.binary_sensor"; void TuyaBinarySensor::setup() { - this->parent_->register_listener(this->sensor_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(this->sensor_id_, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported binary sensor %u is: %s", datapoint.id, ONOFF(datapoint.value_bool)); this->publish_state(datapoint.value_bool); }); diff --git a/esphome/components/tuya/climate/tuya_climate.cpp b/esphome/components/tuya/climate/tuya_climate.cpp index 962d18a391..1211a4856f 100644 --- a/esphome/components/tuya/climate/tuya_climate.cpp +++ b/esphome/components/tuya/climate/tuya_climate.cpp @@ -8,7 +8,7 @@ static const char *TAG = "tuya.climate"; void TuyaClimate::setup() { if (this->switch_id_.has_value()) { - this->parent_->register_listener(*this->switch_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->switch_id_, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported switch is: %s", ONOFF(datapoint.value_bool)); this->mode = climate::CLIMATE_MODE_OFF; if (datapoint.value_bool) { @@ -25,7 +25,7 @@ void TuyaClimate::setup() { }); } if (this->active_state_id_.has_value()) { - this->parent_->register_listener(*this->active_state_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->active_state_id_, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported active state is: %u", datapoint.value_enum); this->active_state_ = datapoint.value_enum; this->compute_state_(); @@ -33,7 +33,7 @@ void TuyaClimate::setup() { }); } if (this->target_temperature_id_.has_value()) { - this->parent_->register_listener(*this->target_temperature_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->target_temperature_id_, [this](const TuyaDatapoint &datapoint) { this->target_temperature = datapoint.value_int * this->target_temperature_multiplier_; ESP_LOGV(TAG, "MCU reported target temperature is: %.1f", this->target_temperature); this->compute_state_(); @@ -41,7 +41,7 @@ void TuyaClimate::setup() { }); } if (this->current_temperature_id_.has_value()) { - this->parent_->register_listener(*this->current_temperature_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->current_temperature_id_, [this](const TuyaDatapoint &datapoint) { this->current_temperature = datapoint.value_int * this->current_temperature_multiplier_; ESP_LOGV(TAG, "MCU reported current temperature is: %.1f", this->current_temperature); this->compute_state_(); diff --git a/esphome/components/tuya/fan/tuya_fan.cpp b/esphome/components/tuya/fan/tuya_fan.cpp index b2326034a1..d3da3139f5 100644 --- a/esphome/components/tuya/fan/tuya_fan.cpp +++ b/esphome/components/tuya/fan/tuya_fan.cpp @@ -13,7 +13,7 @@ void TuyaFan::setup() { this->fan_->set_traits(traits); if (this->speed_id_.has_value()) { - this->parent_->register_listener(*this->speed_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->speed_id_, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_enum); auto call = this->fan_->make_call(); if (datapoint.value_enum < this->speed_count_) @@ -24,7 +24,7 @@ void TuyaFan::setup() { }); } if (this->switch_id_.has_value()) { - this->parent_->register_listener(*this->switch_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->switch_id_, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported switch is: %s", ONOFF(datapoint.value_bool)); auto call = this->fan_->make_call(); call.set_state(datapoint.value_bool); @@ -32,7 +32,7 @@ void TuyaFan::setup() { }); } if (this->oscillation_id_.has_value()) { - this->parent_->register_listener(*this->oscillation_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->oscillation_id_, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported oscillation is: %s", ONOFF(datapoint.value_bool)); auto call = this->fan_->make_call(); call.set_oscillating(datapoint.value_bool); @@ -40,7 +40,7 @@ void TuyaFan::setup() { }); } if (this->direction_id_.has_value()) { - this->parent_->register_listener(*this->direction_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->direction_id_, [this](const TuyaDatapoint &datapoint) { auto call = this->fan_->make_call(); call.set_direction(datapoint.value_bool ? fan::FAN_DIRECTION_REVERSE : fan::FAN_DIRECTION_FORWARD); call.perform(); diff --git a/esphome/components/tuya/light/tuya_light.cpp b/esphome/components/tuya/light/tuya_light.cpp index 4befad401e..10aff93f75 100644 --- a/esphome/components/tuya/light/tuya_light.cpp +++ b/esphome/components/tuya/light/tuya_light.cpp @@ -8,7 +8,7 @@ static const char *TAG = "tuya.light"; void TuyaLight::setup() { if (this->color_temperature_id_.has_value()) { - this->parent_->register_listener(*this->color_temperature_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->color_temperature_id_, [this](const TuyaDatapoint &datapoint) { auto call = this->state_->make_call(); call.set_color_temperature(this->cold_white_temperature_ + (this->warm_white_temperature_ - this->cold_white_temperature_) * @@ -17,14 +17,14 @@ void TuyaLight::setup() { }); } if (this->dimmer_id_.has_value()) { - this->parent_->register_listener(*this->dimmer_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->dimmer_id_, [this](const TuyaDatapoint &datapoint) { auto call = this->state_->make_call(); call.set_brightness(float(datapoint.value_uint) / this->max_value_); call.perform(); }); } if (switch_id_.has_value()) { - this->parent_->register_listener(*this->switch_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(*this->switch_id_, [this](const TuyaDatapoint &datapoint) { auto call = this->state_->make_call(); call.set_state(datapoint.value_bool); call.perform(); diff --git a/esphome/components/tuya/sensor/tuya_sensor.cpp b/esphome/components/tuya/sensor/tuya_sensor.cpp index 483552950f..d5fad63f64 100644 --- a/esphome/components/tuya/sensor/tuya_sensor.cpp +++ b/esphome/components/tuya/sensor/tuya_sensor.cpp @@ -7,7 +7,7 @@ namespace tuya { static const char *TAG = "tuya.sensor"; void TuyaSensor::setup() { - this->parent_->register_listener(this->sensor_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(this->sensor_id_, [this](const TuyaDatapoint &datapoint) { if (datapoint.type == TuyaDatapointType::BOOLEAN) { ESP_LOGV(TAG, "MCU reported sensor %u is: %s", datapoint.id, ONOFF(datapoint.value_bool)); this->publish_state(datapoint.value_bool); diff --git a/esphome/components/tuya/switch/tuya_switch.cpp b/esphome/components/tuya/switch/tuya_switch.cpp index c735b32341..62008c3580 100644 --- a/esphome/components/tuya/switch/tuya_switch.cpp +++ b/esphome/components/tuya/switch/tuya_switch.cpp @@ -7,7 +7,7 @@ namespace tuya { static const char *TAG = "tuya.switch"; void TuyaSwitch::setup() { - this->parent_->register_listener(this->switch_id_, [this](TuyaDatapoint datapoint) { + this->parent_->register_listener(this->switch_id_, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported switch %u is: %s", this->switch_id_, ONOFF(datapoint.value_bool)); this->publish_state(datapoint.value_bool); }); diff --git a/esphome/components/tuya/tuya.cpp b/esphome/components/tuya/tuya.cpp index 3f09db068d..1a116219a6 100644 --- a/esphome/components/tuya/tuya.cpp +++ b/esphome/components/tuya/tuya.cpp @@ -339,7 +339,7 @@ void Tuya::process_command_queue_() { } } -void Tuya::send_command_(TuyaCommand command) { +void Tuya::send_command_(const TuyaCommand &command) { command_queue_.push_back(command); process_command_queue_(); } @@ -427,7 +427,7 @@ void Tuya::set_datapoint_value(uint8_t datapoint_id, uint32_t value) { this->send_datapoint_command_(datapoint->id, datapoint->type, data); } -void Tuya::set_datapoint_value(uint8_t datapoint_id, std::string value) { +void Tuya::set_datapoint_value(uint8_t datapoint_id, const std::string &value) { ESP_LOGD(TAG, "Setting datapoint %u to %s", datapoint_id, value.c_str()); optional datapoint = this->get_datapoint_(datapoint_id); if (!datapoint.has_value()) { diff --git a/esphome/components/tuya/tuya.h b/esphome/components/tuya/tuya.h index 42848b4914..4ca4f56366 100644 --- a/esphome/components/tuya/tuya.h +++ b/esphome/components/tuya/tuya.h @@ -76,7 +76,7 @@ class Tuya : public Component, public uart::UARTDevice { void dump_config() override; void register_listener(uint8_t datapoint_id, const std::function &func); void set_datapoint_value(uint8_t datapoint_id, uint32_t value); - void set_datapoint_value(uint8_t datapoint_id, std::string value); + void set_datapoint_value(uint8_t datapoint_id, const std::string &value); #ifdef USE_TIME void set_time_id(time::RealTimeClock *time_id) { this->time_id_ = time_id; } #endif @@ -93,7 +93,7 @@ class Tuya : public Component, public uart::UARTDevice { void handle_command_(uint8_t command, uint8_t version, const uint8_t *buffer, size_t len); void send_raw_command_(TuyaCommand command); void process_command_queue_(); - void send_command_(TuyaCommand command); + void send_command_(const TuyaCommand &command); void send_empty_command_(TuyaCommandType command); void send_datapoint_command_(uint8_t datapoint_id, TuyaDatapointType datapoint_type, std::vector data); void send_wifi_status_(); diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index fbb215ee17..381366b420 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -242,7 +242,7 @@ void WebServer::handle_js_request(AsyncWebServerRequest *request) { void WebServer::on_sensor_update(sensor::Sensor *obj, float state) { this->events_.send(this->sensor_json(obj, state).c_str(), "state"); } -void WebServer::handle_sensor_request(AsyncWebServerRequest *request, UrlMatch match) { +void WebServer::handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match) { for (sensor::Sensor *obj : App.get_sensors()) { if (obj->is_internal()) continue; @@ -267,10 +267,10 @@ std::string WebServer::sensor_json(sensor::Sensor *obj, float value) { #endif #ifdef USE_TEXT_SENSOR -void WebServer::on_text_sensor_update(text_sensor::TextSensor *obj, std::string state) { +void WebServer::on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state) { this->events_.send(this->text_sensor_json(obj, state).c_str(), "state"); } -void WebServer::handle_text_sensor_request(AsyncWebServerRequest *request, UrlMatch match) { +void WebServer::handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match) { for (text_sensor::TextSensor *obj : App.get_text_sensors()) { if (obj->is_internal()) continue; @@ -302,7 +302,7 @@ std::string WebServer::switch_json(switch_::Switch *obj, bool value) { root["value"] = value; }); } -void WebServer::handle_switch_request(AsyncWebServerRequest *request, UrlMatch match) { +void WebServer::handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match) { for (switch_::Switch *obj : App.get_switches()) { if (obj->is_internal()) continue; @@ -343,7 +343,7 @@ std::string WebServer::binary_sensor_json(binary_sensor::BinarySensor *obj, bool root["value"] = value; }); } -void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, UrlMatch match) { +void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match) { for (binary_sensor::BinarySensor *obj : App.get_binary_sensors()) { if (obj->is_internal()) continue; @@ -387,7 +387,7 @@ std::string WebServer::fan_json(fan::FanState *obj) { root["oscillation"] = obj->oscillating; }); } -void WebServer::handle_fan_request(AsyncWebServerRequest *request, UrlMatch match) { +void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match) { for (fan::FanState *obj : App.get_fans()) { if (obj->is_internal()) continue; @@ -453,7 +453,7 @@ void WebServer::on_light_update(light::LightState *obj) { return; this->events_.send(this->light_json(obj).c_str(), "state"); } -void WebServer::handle_light_request(AsyncWebServerRequest *request, UrlMatch match) { +void WebServer::handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match) { for (light::LightState *obj : App.get_lights()) { if (obj->is_internal()) continue; @@ -528,7 +528,7 @@ void WebServer::on_cover_update(cover::Cover *obj) { return; this->events_.send(this->cover_json(obj).c_str(), "state"); } -void WebServer::handle_cover_request(AsyncWebServerRequest *request, UrlMatch match) { +void WebServer::handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match) { for (cover::Cover *obj : App.get_covers()) { if (obj->is_internal()) continue; diff --git a/esphome/components/web_server/web_server.h b/esphome/components/web_server/web_server.h index b3bf2ef7f7..89e23b7071 100644 --- a/esphome/components/web_server/web_server.h +++ b/esphome/components/web_server/web_server.h @@ -88,7 +88,7 @@ class WebServer : public Controller, public Component, public AsyncWebHandler { #ifdef USE_SENSOR void on_sensor_update(sensor::Sensor *obj, float state) override; /// Handle a sensor request under '/sensor/'. - void handle_sensor_request(AsyncWebServerRequest *request, UrlMatch match); + void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match); /// Dump the sensor state with its value as a JSON string. std::string sensor_json(sensor::Sensor *obj, float value); @@ -98,7 +98,7 @@ class WebServer : public Controller, public Component, public AsyncWebHandler { void on_switch_update(switch_::Switch *obj, bool state) override; /// Handle a switch request under '/switch//'. - void handle_switch_request(AsyncWebServerRequest *request, UrlMatch match); + void handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match); /// Dump the switch state with its value as a JSON string. std::string switch_json(switch_::Switch *obj, bool value); @@ -108,7 +108,7 @@ class WebServer : public Controller, public Component, public AsyncWebHandler { void on_binary_sensor_update(binary_sensor::BinarySensor *obj, bool state) override; /// Handle a binary sensor request under '/binary_sensor/'. - void handle_binary_sensor_request(AsyncWebServerRequest *request, UrlMatch match); + void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match); /// Dump the binary sensor state with its value as a JSON string. std::string binary_sensor_json(binary_sensor::BinarySensor *obj, bool value); @@ -118,7 +118,7 @@ class WebServer : public Controller, public Component, public AsyncWebHandler { void on_fan_update(fan::FanState *obj) override; /// Handle a fan request under '/fan//'. - void handle_fan_request(AsyncWebServerRequest *request, UrlMatch match); + void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match); /// Dump the fan state as a JSON string. std::string fan_json(fan::FanState *obj); @@ -128,17 +128,17 @@ class WebServer : public Controller, public Component, public AsyncWebHandler { void on_light_update(light::LightState *obj) override; /// Handle a light request under '/light//'. - void handle_light_request(AsyncWebServerRequest *request, UrlMatch match); + void handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match); /// Dump the light state as a JSON string. std::string light_json(light::LightState *obj); #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; /// Handle a text sensor request under '/text_sensor/'. - void handle_text_sensor_request(AsyncWebServerRequest *request, UrlMatch match); + void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match); /// Dump the text sensor state with its value as a JSON string. std::string text_sensor_json(text_sensor::TextSensor *obj, const std::string &value); @@ -148,7 +148,7 @@ class WebServer : public Controller, public Component, public AsyncWebHandler { void on_cover_update(cover::Cover *obj) override; /// Handle a cover request under '/cover//'. - void handle_cover_request(AsyncWebServerRequest *request, UrlMatch match); + void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match); /// Dump the cover state as a JSON string. std::string cover_json(cover::Cover *obj); diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index de7ffb4f09..fcb1b177a5 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -220,8 +220,8 @@ void WiFiComponent::set_sta(const WiFiAP &ap) { void WiFiComponent::clear_sta() { this->sta_.clear(); } void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &password) { SavedWifiSettings save{}; - strcpy(save.ssid, ssid.c_str()); - strcpy(save.password, password.c_str()); + strncpy(save.ssid, ssid.c_str(), sizeof(save.ssid)); + strncpy(save.password, password.c_str(), sizeof(save.password)); this->pref_.save(&save); WiFiAP sta{}; @@ -626,7 +626,7 @@ void WiFiAP::set_password(const std::string &password) { this->password_ = passw void WiFiAP::set_eap(optional eap_auth) { this->eap_ = eap_auth; } #endif void WiFiAP::set_channel(optional channel) { this->channel_ = channel; } -void WiFiAP::set_manual_ip(optional manual_ip) { this->manual_ip_ = manual_ip; } +void WiFiAP::set_manual_ip(optional manual_ip) { this->manual_ip_ = std::move(manual_ip); } void WiFiAP::set_hidden(bool hidden) { this->hidden_ = hidden; } const std::string &WiFiAP::get_ssid() const { return this->ssid_; } const optional &WiFiAP::get_bssid() const { return this->bssid_; } @@ -638,9 +638,14 @@ const optional &WiFiAP::get_channel() const { return this->channel_; } const optional &WiFiAP::get_manual_ip() const { return this->manual_ip_; } bool WiFiAP::get_hidden() const { return this->hidden_; } -WiFiScanResult::WiFiScanResult(const bssid_t &bssid, const std::string &ssid, uint8_t channel, int8_t rssi, - bool with_auth, bool is_hidden) - : bssid_(bssid), ssid_(ssid), channel_(channel), rssi_(rssi), with_auth_(with_auth), is_hidden_(is_hidden) {} +WiFiScanResult::WiFiScanResult(const bssid_t &bssid, std::string ssid, uint8_t channel, int8_t rssi, bool with_auth, + bool is_hidden) + : bssid_(bssid), + ssid_(std::move(ssid)), + channel_(channel), + rssi_(rssi), + with_auth_(with_auth), + is_hidden_(is_hidden) {} bool WiFiScanResult::matches(const WiFiAP &config) { if (config.get_hidden()) { // User configured a hidden network, only match actually hidden networks diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index 753455ddb1..18f46eaa4a 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -115,8 +115,7 @@ class WiFiAP { class WiFiScanResult { public: - WiFiScanResult(const bssid_t &bssid, const std::string &ssid, uint8_t channel, int8_t rssi, bool with_auth, - bool is_hidden); + WiFiScanResult(const bssid_t &bssid, std::string ssid, uint8_t channel, int8_t rssi, bool with_auth, bool is_hidden); bool matches(const WiFiAP &config); @@ -251,7 +250,7 @@ class WiFiComponent : public Component { bool wifi_sta_ip_config_(optional manual_ip); IPAddress wifi_sta_ip_(); bool wifi_apply_hostname_(); - bool wifi_sta_connect_(WiFiAP ap); + bool wifi_sta_connect_(const WiFiAP &ap); void wifi_pre_setup_(); wl_status_t wifi_sta_status_(); bool wifi_scan_start_(); diff --git a/esphome/components/wifi/wifi_component_esp32.cpp b/esphome/components/wifi/wifi_component_esp32.cpp index cf65ed3725..a402973c6b 100644 --- a/esphome/components/wifi/wifi_component_esp32.cpp +++ b/esphome/components/wifi/wifi_component_esp32.cpp @@ -149,7 +149,7 @@ bool WiFiComponent::wifi_apply_hostname_() { } return true; } -bool WiFiComponent::wifi_sta_connect_(WiFiAP ap) { +bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) { // enable STA if (!this->wifi_mode_(true, {})) return false; diff --git a/esphome/components/wifi/wifi_component_esp8266.cpp b/esphome/components/wifi/wifi_component_esp8266.cpp index dee3d5a4a5..d6ded763d0 100644 --- a/esphome/components/wifi/wifi_component_esp8266.cpp +++ b/esphome/components/wifi/wifi_component_esp8266.cpp @@ -200,7 +200,7 @@ bool WiFiComponent::wifi_apply_hostname_() { return ret; } -bool WiFiComponent::wifi_sta_connect_(WiFiAP ap) { +bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) { // enable STA if (!this->wifi_mode_(true, {})) return false; @@ -209,8 +209,8 @@ bool WiFiComponent::wifi_sta_connect_(WiFiAP ap) { struct station_config conf {}; memset(&conf, 0, sizeof(conf)); - strcpy(reinterpret_cast(conf.ssid), ap.get_ssid().c_str()); - strcpy(reinterpret_cast(conf.password), ap.get_password().c_str()); + strncpy(reinterpret_cast(conf.ssid), ap.get_ssid().c_str(), sizeof(conf.ssid)); + strncpy(reinterpret_cast(conf.password), ap.get_password().c_str(), sizeof(conf.password)); if (ap.get_bssid().has_value()) { conf.bssid_set = 1; @@ -688,7 +688,7 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { return false; struct softap_config conf {}; - strcpy(reinterpret_cast(conf.ssid), ap.get_ssid().c_str()); + strncpy(reinterpret_cast(conf.ssid), ap.get_ssid().c_str(), sizeof(conf.ssid)); conf.ssid_len = static_cast(ap.get_ssid().size()); conf.channel = ap.get_channel().value_or(1); conf.ssid_hidden = ap.get_hidden(); @@ -700,7 +700,7 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { *conf.password = 0; } else { conf.authmode = AUTH_WPA2_PSK; - strcpy(reinterpret_cast(conf.password), ap.get_password().c_str()); + strncpy(reinterpret_cast(conf.password), ap.get_password().c_str(), sizeof(conf.password)); } ETS_UART_INTR_DISABLE(); diff --git a/esphome/components/xpt2046/xpt2046.cpp b/esphome/components/xpt2046/xpt2046.cpp index 3e22e82859..6a3b7bbcbb 100644 --- a/esphome/components/xpt2046/xpt2046.cpp +++ b/esphome/components/xpt2046/xpt2046.cpp @@ -36,7 +36,7 @@ void XPT2046Component::loop() { void XPT2046Component::update() { int16_t data[6]; bool touch = false; - unsigned long now = millis(); + uint32_t now = millis(); this->z_raw = 0; diff --git a/esphome/components/xpt2046/xpt2046.h b/esphome/components/xpt2046/xpt2046.h index 7fd80c3228..e7270f7d7d 100644 --- a/esphome/components/xpt2046/xpt2046.h +++ b/esphome/components/xpt2046/xpt2046.h @@ -111,7 +111,7 @@ class XPT2046Component : public PollingComponent, bool swap_x_y_; uint32_t report_millis_; - unsigned long last_pos_ms_{0}; + uint32_t last_pos_ms_{0}; GPIOPin *irq_pin_{nullptr}; bool last_irq_{true}; diff --git a/esphome/components/zyaura/zyaura.cpp b/esphome/components/zyaura/zyaura.cpp index 3b1a2a5069..265b70aa74 100644 --- a/esphome/components/zyaura/zyaura.cpp +++ b/esphome/components/zyaura/zyaura.cpp @@ -6,7 +6,7 @@ namespace zyaura { static const char *TAG = "zyaura"; -bool ICACHE_RAM_ATTR ZaDataProcessor::decode(unsigned long ms, bool data) { +bool ICACHE_RAM_ATTR ZaDataProcessor::decode(uint32_t ms, bool data) { // check if a new message has started, based on time since previous bit if ((ms - this->prev_ms_) > ZA_MAX_MS) { this->num_bits_ = 0; diff --git a/esphome/components/zyaura/zyaura.h b/esphome/components/zyaura/zyaura.h index fd26947e28..eed0c55c35 100644 --- a/esphome/components/zyaura/zyaura.h +++ b/esphome/components/zyaura/zyaura.h @@ -31,13 +31,13 @@ struct ZaMessage { class ZaDataProcessor { public: - bool decode(unsigned long ms, bool data); + bool decode(uint32_t ms, bool data); ZaMessage *message = new ZaMessage; protected: uint8_t buffer_[ZA_MSG_LEN]; int num_bits_ = 0; - unsigned long prev_ms_; + uint32_t prev_ms_; }; class ZaSensorStore { diff --git a/esphome/core/color.h b/esphome/core/color.h index d2f225dc3a..6e8c769d10 100644 --- a/esphome/core/color.h +++ b/esphome/core/color.h @@ -44,7 +44,7 @@ struct Color { w((colorcode >> 24) & 0xFF) {} inline bool is_on() ALWAYS_INLINE { return this->raw_32 != 0; } - inline Color &operator=(const Color &rhs) ALWAYS_INLINE { + inline Color &operator=(const Color &rhs) ALWAYS_INLINE { // NOLINT this->r = rhs.r; this->g = rhs.g; this->b = rhs.b; diff --git a/esphome/core/component.cpp b/esphome/core/component.cpp index c571e5e23f..5568134c03 100644 --- a/esphome/core/component.cpp +++ b/esphome/core/component.cpp @@ -1,8 +1,10 @@ #include "esphome/core/component.h" -#include "esphome/core/helpers.h" -#include "esphome/core/esphal.h" -#include "esphome/core/log.h" + #include "esphome/core/application.h" +#include "esphome/core/esphal.h" +#include "esphome/core/helpers.h" +#include "esphome/core/log.h" +#include namespace esphome { @@ -173,7 +175,7 @@ void Nameable::set_name(const std::string &name) { this->name_ = name; this->calc_object_id_(); } -Nameable::Nameable(const std::string &name) : name_(name) { this->calc_object_id_(); } +Nameable::Nameable(std::string name) : name_(std::move(name)) { this->calc_object_id_(); } const std::string &Nameable::get_object_id() { return this->object_id_; } bool Nameable::is_internal() const { return this->internal_; } diff --git a/esphome/core/component.h b/esphome/core/component.h index ad3619386b..001620fe4a 100644 --- a/esphome/core/component.h +++ b/esphome/core/component.h @@ -246,7 +246,7 @@ class PollingComponent : public Component { class Nameable { public: Nameable() : Nameable("") {} - explicit Nameable(const std::string &name); + explicit Nameable(std::string name); const std::string &get_name() const; void set_name(const std::string &name); /// Get the sanitized name of this nameable as an ID. Caching it internally. diff --git a/esphome/core/controller.cpp b/esphome/core/controller.cpp index bd68d777ff..f3d10b23ff 100644 --- a/esphome/core/controller.cpp +++ b/esphome/core/controller.cpp @@ -44,7 +44,7 @@ void Controller::setup_controller() { #ifdef USE_TEXT_SENSOR for (auto *obj : App.get_text_sensors()) { if (!obj->is_internal()) - obj->add_on_state_callback([this, obj](std::string state) { this->on_text_sensor_update(obj, state); }); + obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_sensor_update(obj, state); }); } #endif #ifdef USE_CLIMATE diff --git a/esphome/core/controller.h b/esphome/core/controller.h index fa7d1f2ef0..0e94a43c4c 100644 --- a/esphome/core/controller.h +++ b/esphome/core/controller.h @@ -50,7 +50,7 @@ class Controller { virtual void on_cover_update(cover::Cover *obj){}; #endif #ifdef USE_TEXT_SENSOR - virtual void on_text_sensor_update(text_sensor::TextSensor *obj, std::string state){}; + virtual void on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state){}; #endif #ifdef USE_CLIMATE virtual void on_climate_update(climate::Climate *obj){}; diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index db26e62781..85682f1864 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -201,27 +201,27 @@ std::string to_string(int val) { sprintf(buf, "%d", val); return buf; } -std::string to_string(long val) { +std::string to_string(long val) { // NOLINT char buf[64]; sprintf(buf, "%ld", val); return buf; } -std::string to_string(long long val) { +std::string to_string(long long val) { // NOLINT char buf[64]; sprintf(buf, "%lld", val); return buf; } -std::string to_string(unsigned val) { +std::string to_string(unsigned val) { // NOLINT char buf[64]; sprintf(buf, "%u", val); return buf; } -std::string to_string(unsigned long val) { +std::string to_string(unsigned long val) { // NOLINT char buf[64]; sprintf(buf, "%lu", val); return buf; } -std::string to_string(unsigned long long val) { +std::string to_string(unsigned long long val) { // NOLINT char buf[64]; sprintf(buf, "%llu", val); return buf; diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index d49415ca6b..5369f634f9 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -37,11 +37,11 @@ std::string get_mac_address_pretty(); std::string to_string(const std::string &val); std::string to_string(int val); -std::string to_string(long val); -std::string to_string(long long val); -std::string to_string(unsigned val); -std::string to_string(unsigned long val); -std::string to_string(unsigned long long val); +std::string to_string(long val); // NOLINT +std::string to_string(long long val); // NOLINT +std::string to_string(unsigned val); // NOLINT +std::string to_string(unsigned long val); // NOLINT +std::string to_string(unsigned long long val); // NOLINT std::string to_string(float val); std::string to_string(double val); std::string to_string(long double val); diff --git a/esphome/core/optional.h b/esphome/core/optional.h index f6b050f5f8..7ace7b122a 100644 --- a/esphome/core/optional.h +++ b/esphome/core/optional.h @@ -42,7 +42,7 @@ template class optional { // NOLINT optional(nullopt_t) {} - optional(T const &arg) : has_value_(true), value_(arg) {} + optional(T const &arg) : has_value_(true), value_(arg) {} // NOLINT template optional(optional const &other) : has_value_(other.has_value()), value_(other.value()) {} diff --git a/esphome/core/preferences.cpp b/esphome/core/preferences.cpp index 2d58fc9efb..7df30bedb5 100644 --- a/esphome/core/preferences.cpp +++ b/esphome/core/preferences.cpp @@ -88,7 +88,7 @@ static inline bool esp_rtc_user_mem_write(uint32_t index, uint32_t value) { return true; } -extern "C" uint32_t _SPIFFS_end; +extern "C" uint32_t _SPIFFS_end; // NOLINT static const uint32_t get_esp8266_flash_sector() { union { diff --git a/esphome/core/util.cpp b/esphome/core/util.cpp index 19b8ab89e9..e918cd2e76 100644 --- a/esphome/core/util.cpp +++ b/esphome/core/util.cpp @@ -80,7 +80,7 @@ void network_setup_mdns(IPAddress address, int interface) { // see https://github.com/esp8266/Arduino/issues/6114 if (interface == 1) return; - MDNS.begin(App.get_name().c_str(), address); + MDNS.begin(App.get_name().c_str(), std::move(address)); mdns_setup = true; #endif #ifdef ARDUINO_ARCH_ESP32 diff --git a/esphome/core/util.h b/esphome/core/util.h index 180c7aaefa..2d58eff893 100644 --- a/esphome/core/util.h +++ b/esphome/core/util.h @@ -5,11 +5,6 @@ namespace esphome { -/// Macro for IDF version comparision -#ifndef ESP_IDF_VERSION_VAL -#define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) -#endif - /// Return whether the node is connected to the network (through wifi, eth, ...) bool network_is_connected(); /// Get the active network hostname