mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-29 22:24:26 +00:00 
			
		
		
		
	Activate some clang-tidy checks (#1884)
This commit is contained in:
		
							
								
								
									
										24
									
								
								.clang-tidy
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								.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 | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -7,7 +7,7 @@ namespace apds9960 { | ||||
| static const char *TAG = "apds9960"; | ||||
|  | ||||
| #define APDS9960_ERROR_CHECK(func) \ | ||||
|   if (!func) { \ | ||||
|   if (!(func)) { \ | ||||
|     this->mark_failed(); \ | ||||
|     return; \ | ||||
|   } | ||||
|   | ||||
| @@ -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_) | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/core/automation.h" | ||||
| #include "api_pb2.h" | ||||
| @@ -20,8 +22,8 @@ template<typename T> enums::ServiceArgType to_service_arg_type(); | ||||
|  | ||||
| template<typename... Ts> class UserServiceBase : public UserServiceDescriptor { | ||||
|  public: | ||||
|   UserServiceBase(const std::string &name, const std::array<std::string, sizeof...(Ts)> &arg_names) | ||||
|       : name_(name), arg_names_(arg_names) { | ||||
|   UserServiceBase(std::string name, const std::array<std::string, sizeof...(Ts)> &arg_names) | ||||
|       : name_(std::move(name)), arg_names_(arg_names) { | ||||
|     this->key_ = fnv1_hash(this->name_); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/core/automation.h" | ||||
| #include "esphome/components/binary_sensor/binary_sensor.h" | ||||
| @@ -87,8 +89,8 @@ class DoubleClickTrigger : public Trigger<> { | ||||
|  | ||||
| class MultiClickTrigger : public Trigger<>, public Component { | ||||
|  public: | ||||
|   explicit MultiClickTrigger(BinarySensor *parent, const std::vector<MultiClickTriggerEvent> &timing) | ||||
|       : parent_(parent), timing_(timing) {} | ||||
|   explicit MultiClickTrigger(BinarySensor *parent, std::vector<MultiClickTriggerEvent> timing) | ||||
|       : parent_(parent), timing_(std::move(timing)) {} | ||||
|  | ||||
|   void setup() override { | ||||
|     this->last_state_ = this->parent_->state; | ||||
|   | ||||
| @@ -61,7 +61,7 @@ void BinarySensor::add_filter(Filter *filter) { | ||||
|     last_filter->next_ = filter; | ||||
|   } | ||||
| } | ||||
| void BinarySensor::add_filters(std::vector<Filter *> filters) { | ||||
| void BinarySensor::add_filters(const std::vector<Filter *> &filters) { | ||||
|   for (Filter *filter : filters) { | ||||
|     this->add_filter(filter); | ||||
|   } | ||||
|   | ||||
| @@ -9,10 +9,10 @@ namespace esphome { | ||||
| namespace binary_sensor { | ||||
|  | ||||
| #define LOG_BINARY_SENSOR(prefix, type, obj) \ | ||||
|   if (obj != nullptr) { \ | ||||
|     ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, obj->get_name().c_str()); \ | ||||
|     if (!obj->get_device_class().empty()) { \ | ||||
|       ESP_LOGCONFIG(TAG, "%s  Device Class: '%s'", prefix, obj->get_device_class().c_str()); \ | ||||
|   if ((obj) != nullptr) { \ | ||||
|     ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, type, (obj)->get_name().c_str()); \ | ||||
|     if (!(obj)->get_device_class().empty()) { \ | ||||
|       ESP_LOGCONFIG(TAG, "%s  Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \ | ||||
|     } \ | ||||
|   } | ||||
|  | ||||
| @@ -60,7 +60,7 @@ class BinarySensor : public Nameable { | ||||
|   std::string get_device_class(); | ||||
|  | ||||
|   void add_filter(Filter *filter); | ||||
|   void add_filters(std::vector<Filter *> filters); | ||||
|   void add_filters(const std::vector<Filter *> &filters); | ||||
|  | ||||
|   // ========== INTERNAL METHODS ========== | ||||
|   // (In most use cases you won't need these) | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #include "filter.h" | ||||
|  | ||||
| #include "binary_sensor.h" | ||||
| #include <utility> | ||||
|  | ||||
| namespace esphome { | ||||
|  | ||||
| @@ -64,7 +66,7 @@ float DelayedOffFilter::get_setup_priority() const { return setup_priority::HARD | ||||
|  | ||||
| optional<bool> InvertFilter::new_value(bool value, bool is_initial) { return !value; } | ||||
|  | ||||
| AutorepeatFilter::AutorepeatFilter(const std::vector<AutorepeatFilterTiming> &timings) : timings_(timings) {} | ||||
| AutorepeatFilter::AutorepeatFilter(std::vector<AutorepeatFilterTiming> timings) : timings_(std::move(timings)) {} | ||||
|  | ||||
| optional<bool> AutorepeatFilter::new_value(bool value, bool is_initial) { | ||||
|   if (value) { | ||||
| @@ -108,7 +110,7 @@ void AutorepeatFilter::next_value_(bool val) { | ||||
|  | ||||
| float AutorepeatFilter::get_setup_priority() const { return setup_priority::HARDWARE; } | ||||
|  | ||||
| LambdaFilter::LambdaFilter(const std::function<optional<bool>(bool)> &f) : f_(f) {} | ||||
| LambdaFilter::LambdaFilter(std::function<optional<bool>(bool)> f) : f_(std::move(f)) {} | ||||
|  | ||||
| optional<bool> LambdaFilter::new_value(bool value, bool is_initial) { return this->f_(value); } | ||||
|  | ||||
|   | ||||
| @@ -79,7 +79,7 @@ struct AutorepeatFilterTiming { | ||||
|  | ||||
| class AutorepeatFilter : public Filter, public Component { | ||||
|  public: | ||||
|   explicit AutorepeatFilter(const std::vector<AutorepeatFilterTiming> &timings); | ||||
|   explicit AutorepeatFilter(std::vector<AutorepeatFilterTiming> timings); | ||||
|  | ||||
|   optional<bool> new_value(bool value, bool is_initial) override; | ||||
|  | ||||
| @@ -95,7 +95,7 @@ class AutorepeatFilter : public Filter, public Component { | ||||
|  | ||||
| class LambdaFilter : public Filter { | ||||
|  public: | ||||
|   explicit LambdaFilter(const std::function<optional<bool>(bool)> &f); | ||||
|   explicit LambdaFilter(std::function<optional<bool>(bool)> f); | ||||
|  | ||||
|   optional<bool> new_value(bool value, bool is_initial) override; | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "esphome/components/climate/climate.h" | ||||
| #include "esphome/components/remote_base/remote_base.h" | ||||
| #include "esphome/components/remote_transmitter/remote_transmitter.h" | ||||
| @@ -27,8 +29,8 @@ class ClimateIR : public climate::Climate, public Component, public remote_base: | ||||
|     this->temperature_step_ = temperature_step; | ||||
|     this->supports_dry_ = supports_dry; | ||||
|     this->supports_fan_only_ = supports_fan_only; | ||||
|     this->fan_modes_ = fan_modes; | ||||
|     this->swing_modes_ = swing_modes; | ||||
|     this->fan_modes_ = std::move(fan_modes); | ||||
|     this->swing_modes_ = std::move(swing_modes); | ||||
|   } | ||||
|  | ||||
|   void setup() override; | ||||
|   | ||||
| @@ -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()); \ | ||||
|     } \ | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -9,7 +9,9 @@ namespace custom { | ||||
|  | ||||
| class CustomBinaryOutputConstructor { | ||||
|  public: | ||||
|   CustomBinaryOutputConstructor(std::function<std::vector<output::BinaryOutput *>()> init) { this->outputs_ = init(); } | ||||
|   CustomBinaryOutputConstructor(const std::function<std::vector<output::BinaryOutput *>()> &init) { | ||||
|     this->outputs_ = init(); | ||||
|   } | ||||
|  | ||||
|   output::BinaryOutput *get_output(int i) { return this->outputs_[i]; } | ||||
|  | ||||
| @@ -19,7 +21,9 @@ class CustomBinaryOutputConstructor { | ||||
|  | ||||
| class CustomFloatOutputConstructor { | ||||
|  public: | ||||
|   CustomFloatOutputConstructor(std::function<std::vector<output::FloatOutput *>()> init) { this->outputs_ = init(); } | ||||
|   CustomFloatOutputConstructor(const std::function<std::vector<output::FloatOutput *>()> &init) { | ||||
|     this->outputs_ = init(); | ||||
|   } | ||||
|  | ||||
|   output::FloatOutput *get_output(int i) { return this->outputs_[i]; } | ||||
|  | ||||
|   | ||||
| @@ -8,7 +8,7 @@ namespace custom { | ||||
|  | ||||
| class CustomSwitchConstructor : public Component { | ||||
|  public: | ||||
|   CustomSwitchConstructor(std::function<std::vector<switch_::Switch *>()> init) { this->switches_ = init(); } | ||||
|   CustomSwitchConstructor(const std::function<std::vector<switch_::Switch *>()> &init) { this->switches_ = init(); } | ||||
|  | ||||
|   switch_::Switch *get_switch(int i) { return this->switches_[i]; } | ||||
|  | ||||
|   | ||||
| @@ -8,7 +8,7 @@ namespace custom { | ||||
|  | ||||
| class CustomTextSensorConstructor : public Component { | ||||
|  public: | ||||
|   CustomTextSensorConstructor(std::function<std::vector<text_sensor::TextSensor *>()> init) { | ||||
|   CustomTextSensorConstructor(const std::function<std::vector<text_sensor::TextSensor *>()> &init) { | ||||
|     this->text_sensors_ = init(); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -103,7 +103,10 @@ class DFPlayer : public uart::UARTDevice, public Component { | ||||
| }; | ||||
|  | ||||
| #define DFPLAYER_SIMPLE_ACTION(ACTION_CLASS, ACTION_METHOD) \ | ||||
|   template<typename... Ts> class ACTION_CLASS : public Action<Ts...>, public Parented<DFPlayer> { \ | ||||
|   template<typename... Ts> \ | ||||
|   class ACTION_CLASS : /* NOLINT */ \ | ||||
|                        public Action<Ts...>, \ | ||||
|                        public Parented<DFPlayer> { \ | ||||
|     void play(Ts... x) override { this->parent_->ACTION_METHOD(); } \ | ||||
|   }; | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,9 @@ | ||||
| #include "display_buffer.h" | ||||
|  | ||||
| #include "esphome/core/application.h" | ||||
| #include "esphome/core/color.h" | ||||
| #include "esphome/core/log.h" | ||||
| #include "esphome/core/application.h" | ||||
| #include <utility> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace display { | ||||
| @@ -524,7 +526,7 @@ void Animation::next_frame() { | ||||
|   } | ||||
| } | ||||
|  | ||||
| DisplayPage::DisplayPage(const display_writer_t &writer) : writer_(writer) {} | ||||
| DisplayPage::DisplayPage(display_writer_t writer) : writer_(std::move(writer)) {} | ||||
| void DisplayPage::show() { this->parent_->show_page(this); } | ||||
| void DisplayPage::show_next() { this->next_->show(); } | ||||
| void DisplayPage::show_prev() { this->prev_->show(); } | ||||
|   | ||||
| @@ -86,10 +86,10 @@ class DisplayOnPageChangeTrigger; | ||||
| using display_writer_t = std::function<void(DisplayBuffer &)>; | ||||
|  | ||||
| #define LOG_DISPLAY(prefix, type, obj) \ | ||||
|   if (obj != nullptr) { \ | ||||
|   if ((obj) != nullptr) { \ | ||||
|     ESP_LOGCONFIG(TAG, prefix type); \ | ||||
|     ESP_LOGCONFIG(TAG, "%s  Rotations: %d °", prefix, obj->rotation_); \ | ||||
|     ESP_LOGCONFIG(TAG, "%s  Dimensions: %dpx x %dpx", prefix, obj->get_width(), obj->get_height()); \ | ||||
|     ESP_LOGCONFIG(TAG, "%s  Rotations: %d °", prefix, (obj)->rotation_); \ | ||||
|     ESP_LOGCONFIG(TAG, "%s  Dimensions: %dpx x %dpx", prefix, (obj)->get_width(), (obj)->get_height()); \ | ||||
|   } | ||||
|  | ||||
| class DisplayBuffer { | ||||
| @@ -327,7 +327,7 @@ class DisplayBuffer { | ||||
|  | ||||
| class DisplayPage { | ||||
|  public: | ||||
|   DisplayPage(const display_writer_t &writer); | ||||
|   DisplayPage(display_writer_t writer); | ||||
|   void show(); | ||||
|   void show_next(); | ||||
|   void show_prev(); | ||||
|   | ||||
| @@ -51,7 +51,7 @@ union E131RawPacket { | ||||
|  | ||||
| // We need to have at least one `1` value | ||||
| // Get the offset of `property_values[1]` | ||||
| const long E131_MIN_PACKET_SIZE = reinterpret_cast<long>(&((E131RawPacket *) nullptr)->property_values[1]); | ||||
| const size_t E131_MIN_PACKET_SIZE = reinterpret_cast<size_t>(&((E131RawPacket *) nullptr)->property_values[1]); | ||||
|  | ||||
| bool E131Component::join_igmp_groups_() { | ||||
|   if (listen_method_ != E131_MULTICAST) | ||||
|   | ||||
| @@ -9,6 +9,11 @@ | ||||
| #include <eth_phy/phy_tlk110.h> | ||||
| #include <lwip/dns.h> | ||||
|  | ||||
| /// Macro for IDF version comparision | ||||
| #ifndef ESP_IDF_VERSION_VAL | ||||
| #define ESP_IDF_VERSION_VAL(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch)) | ||||
| #endif | ||||
|  | ||||
| // Defined in WiFiGeneric.cpp, sets global initialized flag, starts network event task queue and calls | ||||
| // tcpip_adapter_init() | ||||
| extern void tcpipInit(); | ||||
|   | ||||
| @@ -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_; | ||||
| }; | ||||
|   | ||||
| @@ -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"; | ||||
|  | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -1,7 +1,5 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "Arduino.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace hm3301 { | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,5 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include "abstract_aqi_calculator.h" | ||||
| 
 | ||||
| namespace esphome { | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -1,3 +1,5 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include "esphome/core/log.h" | ||||
| #include "abstract_aqi_calculator.h" | ||||
| 
 | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -1,10 +1,11 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "esphome/components/json/json_util.h" | ||||
| #include "esphome/core/automation.h" | ||||
| #include "esphome/core/component.h" | ||||
| #include <list> | ||||
| #include <map> | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/core/automation.h" | ||||
| #include "esphome/components/json/json_util.h" | ||||
| #include <utility> | ||||
|  | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
| #include <HTTPClient.h> | ||||
| @@ -33,8 +34,8 @@ class HttpRequestComponent : public Component { | ||||
|   void set_method(const char *method) { this->method_ = method; } | ||||
|   void set_useragent(const char *useragent) { this->useragent_ = useragent; } | ||||
|   void set_timeout(uint16_t timeout) { this->timeout_ = timeout; } | ||||
|   void set_body(std::string body) { this->body_ = body; } | ||||
|   void set_headers(std::list<Header> headers) { this->headers_ = headers; } | ||||
|   void set_body(std::string body) { this->body_ = std::move(body); } | ||||
|   void set_headers(std::list<Header> headers) { this->headers_ = std::move(headers); } | ||||
|   void send(const std::vector<HttpRequestResponseTrigger *> &response_triggers); | ||||
|   void close(); | ||||
|   const char *get_string(); | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include <string> | ||||
| #include "WString.h" | ||||
| #include <cstdint> | ||||
| #include <string> | ||||
| #include <vector> | ||||
|  | ||||
| namespace improv { | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/components/light/light_state.h" | ||||
| #include "esphome/components/light/addressable_light.h" | ||||
| @@ -51,9 +53,9 @@ class AddressableLightEffect : public LightEffect { | ||||
| class AddressableLambdaLightEffect : public AddressableLightEffect { | ||||
|  public: | ||||
|   AddressableLambdaLightEffect(const std::string &name, | ||||
|                                const std::function<void(AddressableLight &, Color, bool initial_run)> &f, | ||||
|                                std::function<void(AddressableLight &, Color, bool initial_run)> f, | ||||
|                                uint32_t update_interval) | ||||
|       : AddressableLightEffect(name), f_(f), update_interval_(update_interval) {} | ||||
|       : AddressableLightEffect(name), f_(std::move(f)), update_interval_(update_interval) {} | ||||
|   void start() override { this->initial_run_ = true; } | ||||
|   void apply(AddressableLight &it, const Color ¤t_color) override { | ||||
|     const uint32_t now = millis(); | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "light_effect.h" | ||||
| #include "esphome/core/automation.h" | ||||
|  | ||||
| @@ -85,8 +87,8 @@ class RandomLightEffect : public LightEffect { | ||||
|  | ||||
| class LambdaLightEffect : public LightEffect { | ||||
|  public: | ||||
|   LambdaLightEffect(const std::string &name, const std::function<void()> &f, uint32_t update_interval) | ||||
|       : LightEffect(name), f_(f), update_interval_(update_interval) {} | ||||
|   LambdaLightEffect(const std::string &name, std::function<void()> f, uint32_t update_interval) | ||||
|       : LightEffect(name), f_(std::move(f)), update_interval_(update_interval) {} | ||||
|  | ||||
|   void apply() override { | ||||
|     const uint32_t now = millis(); | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "esphome/core/component.h" | ||||
| #include "light_color_values.h" | ||||
| #include "light_state.h" | ||||
| @@ -11,7 +13,7 @@ class LightState; | ||||
|  | ||||
| class LightEffect { | ||||
|  public: | ||||
|   explicit LightEffect(const std::string &name) : name_(name) {} | ||||
|   explicit LightEffect(std::string name) : name_(std::move(name)) {} | ||||
|  | ||||
|   /// Initialize this LightEffect. Will be called once after creation. | ||||
|   virtual void start() {} | ||||
|   | ||||
| @@ -173,7 +173,7 @@ void LightState::loop() { | ||||
| } | ||||
| LightTraits LightState::get_traits() { return this->output_->get_traits(); } | ||||
| const std::vector<LightEffect *> &LightState::get_effects() const { return this->effects_; } | ||||
| void LightState::add_effects(const std::vector<LightEffect *> effects) { | ||||
| void LightState::add_effects(const std::vector<LightEffect *> &effects) { | ||||
|   this->effects_.reserve(this->effects_.size() + effects.size()); | ||||
|   for (auto *effect : effects) { | ||||
|     this->effects_.push_back(effect); | ||||
|   | ||||
| @@ -269,7 +269,7 @@ class LightState : public Nameable, public Component { | ||||
|  | ||||
|   const std::vector<LightEffect *> &get_effects() const; | ||||
|  | ||||
|   void add_effects(std::vector<LightEffect *> effects); | ||||
|   void add_effects(const std::vector<LightEffect *> &effects); | ||||
|  | ||||
|   void current_values_as_binary(bool *binary); | ||||
|  | ||||
|   | ||||
| @@ -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) || | ||||
|   | ||||
| @@ -99,7 +99,7 @@ class MAX7219Component : public PollingComponent, | ||||
|   uint8_t orientation_; | ||||
|   uint8_t bckgrnd_ = 0x0; | ||||
|   std::vector<uint8_t> max_displaybuffer_; | ||||
|   unsigned long last_scroll_ = 0; | ||||
|   uint32_t last_scroll_ = 0; | ||||
|   uint16_t stepsleft_; | ||||
|   size_t get_buffer_length_(); | ||||
|   optional<max7219_writer_t> writer_local_{}; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/components/sensor/sensor.h" | ||||
| #include "esphome/components/midea_dongle/midea_dongle.h" | ||||
| @@ -27,9 +29,11 @@ class MideaAC : public midea_dongle::MideaAppliance, public climate::Climate, pu | ||||
|   void set_preset_boost(bool state) { this->traits_preset_boost_ = state; } | ||||
|   bool allow_preset(climate::ClimatePreset preset) const; | ||||
|   void set_custom_fan_modes(std::vector<std::string> custom_fan_modes) { | ||||
|     this->traits_custom_fan_modes_ = custom_fan_modes; | ||||
|     this->traits_custom_fan_modes_ = std::move(custom_fan_modes); | ||||
|   } | ||||
|   void set_custom_presets(std::vector<std::string> custom_presets) { | ||||
|     this->traits_custom_presets_ = std::move(custom_presets); | ||||
|   } | ||||
|   void set_custom_presets(std::vector<std::string> custom_presets) { this->traits_custom_presets_ = custom_presets; } | ||||
|   bool allow_custom_preset(const std::string &custom_preset) const; | ||||
|  | ||||
|  protected: | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -1,8 +1,10 @@ | ||||
| #include "mqtt_client.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| #include "esphome/core/application.h" | ||||
| #include "esphome/core/helpers.h" | ||||
| #include "esphome/core/log.h" | ||||
| #include "esphome/core/util.h" | ||||
| #include <utility> | ||||
| #ifdef USE_LOGGER | ||||
| #include "esphome/components/logger/logger.h" | ||||
| #endif | ||||
| @@ -340,7 +342,7 @@ void MQTTClientComponent::subscribe(const std::string &topic, mqtt_callback_t ca | ||||
|   this->subscriptions_.push_back(subscription); | ||||
| } | ||||
|  | ||||
| void MQTTClientComponent::subscribe_json(const std::string &topic, mqtt_json_callback_t callback, uint8_t qos) { | ||||
| void MQTTClientComponent::subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos) { | ||||
|   auto f = [callback](const std::string &topic, const std::string &payload) { | ||||
|     json::parse_json(payload, [topic, callback](JsonObject &root) { callback(topic, root); }); | ||||
|   }; | ||||
| @@ -561,7 +563,7 @@ void MQTTClientComponent::add_ssl_fingerprint(const std::array<uint8_t, SHA1_SIZ | ||||
| MQTTClientComponent *global_mqtt_client = nullptr; | ||||
|  | ||||
| // MQTTMessageTrigger | ||||
| MQTTMessageTrigger::MQTTMessageTrigger(const std::string &topic) : topic_(topic) {} | ||||
| MQTTMessageTrigger::MQTTMessageTrigger(std::string topic) : topic_(std::move(topic)) {} | ||||
| void MQTTMessageTrigger::set_qos(uint8_t qos) { this->qos_ = qos; } | ||||
| void MQTTMessageTrigger::set_payload(const std::string &payload) { this->payload_ = payload; } | ||||
| void MQTTMessageTrigger::setup() { | ||||
|   | ||||
| @@ -157,7 +157,7 @@ class MQTTClientComponent : public Component { | ||||
|    * received. | ||||
|    * @param qos The QoS of this subscription. | ||||
|    */ | ||||
|   void subscribe_json(const std::string &topic, mqtt_json_callback_t callback, uint8_t qos = 0); | ||||
|   void subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos = 0); | ||||
|  | ||||
|   /** Unsubscribe from an MQTT topic. | ||||
|    * | ||||
| @@ -279,7 +279,7 @@ extern MQTTClientComponent *global_mqtt_client; | ||||
|  | ||||
| class MQTTMessageTrigger : public Trigger<std::string>, public Component { | ||||
|  public: | ||||
|   explicit MQTTMessageTrigger(const std::string &topic); | ||||
|   explicit MQTTMessageTrigger(std::string topic); | ||||
|  | ||||
|   void set_qos(uint8_t qos); | ||||
|   void set_payload(const std::string &payload); | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #include "mqtt_subscribe_text_sensor.h" | ||||
|  | ||||
| #include "esphome/core/log.h" | ||||
| #include <utility> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace mqtt_subscribe { | ||||
| @@ -8,7 +10,7 @@ static const char *TAG = "mqtt_subscribe.text_sensor"; | ||||
|  | ||||
| void MQTTSubscribeTextSensor::setup() { | ||||
|   this->parent_->subscribe( | ||||
|       this->topic_, [this](const std::string &topic, std::string payload) { this->publish_state(payload); }, | ||||
|       this->topic_, [this](const std::string &topic, const std::string &payload) { this->publish_state(payload); }, | ||||
|       this->qos_); | ||||
| } | ||||
| float MQTTSubscribeTextSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; } | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/components/light/addressable_light.h" | ||||
|  | ||||
| @@ -31,7 +33,7 @@ class AddressableSegment { | ||||
|  | ||||
| class PartitionLightOutput : public light::AddressableLight { | ||||
|  public: | ||||
|   explicit PartitionLightOutput(std::vector<AddressableSegment> segments) : segments_(segments) { | ||||
|   explicit PartitionLightOutput(std::vector<AddressableSegment> segments) : segments_(std::move(segments)) { | ||||
|     int32_t off = 0; | ||||
|     for (auto &seg : this->segments_) { | ||||
|       seg.set_dst_offset(off); | ||||
|   | ||||
| @@ -33,7 +33,7 @@ class RemoteTransmitData { | ||||
|  | ||||
|   const std::vector<int32_t> &get_data() const { return this->data_; } | ||||
|  | ||||
|   void set_data(std::vector<int32_t> data) { | ||||
|   void set_data(const std::vector<int32_t> &data) { | ||||
|     this->data_.clear(); | ||||
|     this->data_.reserve(data.size()); | ||||
|     for (auto dat : data) | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #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<uint8_t> rx_buffer_; | ||||
|   uint32_t last_bridge_byte_{0}; | ||||
| @@ -83,7 +85,8 @@ class RFBridgeReceivedCodeTrigger : public Trigger<RFBridgeData> { | ||||
| class RFBridgeReceivedAdvancedCodeTrigger : public Trigger<RFBridgeAdvancedData> { | ||||
|  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)); }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <queue> | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/core/helpers.h" | ||||
| #include <queue> | ||||
| #include <utility> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace sensor { | ||||
| @@ -335,7 +336,7 @@ class CalibrateLinearFilter : public Filter { | ||||
|  | ||||
| class CalibratePolynomialFilter : public Filter { | ||||
|  public: | ||||
|   CalibratePolynomialFilter(const std::vector<float> &coefficients) : coefficients_(coefficients) {} | ||||
|   CalibratePolynomialFilter(std::vector<float> coefficients) : coefficients_(std::move(coefficients)) {} | ||||
|   optional<float> new_value(float value) override; | ||||
|  | ||||
|  protected: | ||||
|   | ||||
| @@ -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); \ | ||||
|     } \ | ||||
|   } | ||||
|   | ||||
| @@ -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_); | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| #pragma once | ||||
| #include <stdint.h> | ||||
| #include <cstdint> | ||||
| 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; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -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_; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| #include "sim800l.h" | ||||
| #include "esphome/core/log.h" | ||||
| #include <string.h> | ||||
| #include <cstring> | ||||
|  | ||||
| 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; | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #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<void(std::string, std::string)> 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<std::string, std::string> { | ||||
|  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)); }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -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_) { | ||||
|   | ||||
| @@ -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); \ | ||||
|     } \ | ||||
|   } | ||||
|   | ||||
| @@ -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); | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <utility> | ||||
|  | ||||
| #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<std::string> { | ||||
|  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)); }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
| #ifdef ARDUINO_ARCH_ESP8266 | ||||
| #include "sys/time.h" | ||||
| #endif | ||||
| #include "errno.h" | ||||
| #include <cerrno> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace time { | ||||
|   | ||||
| @@ -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 <stdlib.h> | ||||
| #include <time.h> | ||||
| #include <bitset> | ||||
| #include <cstdlib> | ||||
| #include <ctime> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace time { | ||||
|   | ||||
| @@ -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); | ||||
|   }); | ||||
|   | ||||
| @@ -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_(); | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   }); | ||||
|   | ||||
| @@ -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<TuyaDatapoint> datapoint = this->get_datapoint_(datapoint_id); | ||||
|   if (!datapoint.has_value()) { | ||||
|   | ||||
| @@ -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<void(TuyaDatapoint)> &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<uint8_t> data); | ||||
|   void send_wifi_status_(); | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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/<id>'. | ||||
|   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/<id>/</turn_on/turn_off/toggle>'. | ||||
|   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/<id>'. | ||||
|   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/<id>/</turn_on/turn_off/toggle>'. | ||||
|   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/<id>/</turn_on/turn_off/toggle>'. | ||||
|   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/<id>'. | ||||
|   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/<id>/<open/close/stop/set>'. | ||||
|   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); | ||||
|   | ||||
| @@ -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<EAPAuth> eap_auth) { this->eap_ = eap_auth; } | ||||
| #endif | ||||
| void WiFiAP::set_channel(optional<uint8_t> channel) { this->channel_ = channel; } | ||||
| void WiFiAP::set_manual_ip(optional<ManualIP> manual_ip) { this->manual_ip_ = manual_ip; } | ||||
| void WiFiAP::set_manual_ip(optional<ManualIP> 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<bssid_t> &WiFiAP::get_bssid() const { return this->bssid_; } | ||||
| @@ -638,9 +638,14 @@ const optional<uint8_t> &WiFiAP::get_channel() const { return this->channel_; } | ||||
| const optional<ManualIP> &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 | ||||
|   | ||||
| @@ -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<ManualIP> 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_(); | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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<char *>(conf.ssid), ap.get_ssid().c_str()); | ||||
|   strcpy(reinterpret_cast<char *>(conf.password), ap.get_password().c_str()); | ||||
|   strncpy(reinterpret_cast<char *>(conf.ssid), ap.get_ssid().c_str(), sizeof(conf.ssid)); | ||||
|   strncpy(reinterpret_cast<char *>(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<char *>(conf.ssid), ap.get_ssid().c_str()); | ||||
|   strncpy(reinterpret_cast<char *>(conf.ssid), ap.get_ssid().c_str(), sizeof(conf.ssid)); | ||||
|   conf.ssid_len = static_cast<uint8>(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<char *>(conf.password), ap.get_password().c_str()); | ||||
|     strncpy(reinterpret_cast<char *>(conf.password), ap.get_password().c_str(), sizeof(conf.password)); | ||||
|   } | ||||
|  | ||||
|   ETS_UART_INTR_DISABLE(); | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -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}; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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 <utility> | ||||
|  | ||||
| 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_; } | ||||
|   | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user