1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-06 18:11:49 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
J. Nick Koston
358296a57e [remote_base] Eliminate substr() allocations in Pronto dump logging 2025-11-04 22:32:20 -06:00
235 changed files with 778 additions and 1652 deletions

View File

@@ -51,79 +51,7 @@ This document provides essential context for AI models interacting with this pro
* **Naming Conventions:** * **Naming Conventions:**
* **Python:** Follows PEP 8. Use clear, descriptive names following snake_case. * **Python:** Follows PEP 8. Use clear, descriptive names following snake_case.
* **C++:** Follows the Google C++ Style Guide with these specifics (following clang-tidy conventions): * **C++:** Follows the Google C++ Style Guide.
- Function, method, and variable names: `lower_snake_case`
- Class/struct/enum names: `UpperCamelCase`
- Top-level constants (global/namespace scope): `UPPER_SNAKE_CASE`
- Function-local constants: `lower_snake_case`
- Protected/private fields: `lower_snake_case_with_trailing_underscore_`
- Favor descriptive names over abbreviations
* **C++ Field Visibility:**
* **Prefer `protected`:** Use `protected` for most class fields to enable extensibility and testing. Fields should be `lower_snake_case_with_trailing_underscore_`.
* **Use `private` for safety-critical cases:** Use `private` visibility when direct field access could introduce bugs or violate invariants:
1. **Pointer lifetime issues:** When setters validate and store pointers from known lists to prevent dangling references.
```cpp
// Helper to find matching string in vector and return its pointer
inline const char *vector_find(const std::vector<const char *> &vec, const char *value) {
for (const char *item : vec) {
if (strcmp(item, value) == 0)
return item;
}
return nullptr;
}
class ClimateDevice {
public:
void set_custom_fan_modes(std::initializer_list<const char *> modes) {
this->custom_fan_modes_ = modes;
this->active_custom_fan_mode_ = nullptr; // Reset when modes change
}
bool set_custom_fan_mode(const char *mode) {
// Find mode in supported list and store that pointer (not the input pointer)
const char *validated_mode = vector_find(this->custom_fan_modes_, mode);
if (validated_mode != nullptr) {
this->active_custom_fan_mode_ = validated_mode;
return true;
}
return false;
}
private:
std::vector<const char *> custom_fan_modes_; // Pointers to string literals in flash
const char *active_custom_fan_mode_{nullptr}; // Must point to entry in custom_fan_modes_
};
```
2. **Invariant coupling:** When multiple fields must remain synchronized to prevent buffer overflows or data corruption.
```cpp
class Buffer {
public:
void resize(size_t new_size) {
auto new_data = std::make_unique<uint8_t[]>(new_size);
if (this->data_) {
std::memcpy(new_data.get(), this->data_.get(), std::min(this->size_, new_size));
}
this->data_ = std::move(new_data);
this->size_ = new_size; // Must stay in sync with data_
}
private:
std::unique_ptr<uint8_t[]> data_;
size_t size_{0}; // Must match allocated size of data_
};
```
3. **Resource management:** When setters perform cleanup or registration operations that derived classes might skip.
* **Provide `protected` accessor methods:** When derived classes need controlled access to `private` members.
* **C++ Preprocessor Directives:**
* **Avoid `#define` for constants:** Using `#define` for constants is discouraged and should be replaced with `const` variables or enums.
* **Use `#define` only for:**
- Conditional compilation (`#ifdef`, `#ifndef`)
- Compile-time sizes calculated during Python code generation (e.g., configuring `std::array` or `StaticVector` dimensions via `cg.add_define()`)
* **C++ Additional Conventions:**
* **Member access:** Prefix all class member access with `this->` (e.g., `this->value_` not `value_`)
* **Indentation:** Use spaces (two per indentation level), not tabs
* **Type aliases:** Prefer `using type_t = int;` over `typedef int type_t;`
* **Line length:** Wrap lines at no more than 120 characters
* **Component Structure:** * **Component Structure:**
* **Standard Files:** * **Standard Files:**

View File

@@ -105,7 +105,7 @@ template<typename... Ts> class AGS10NewI2cAddressAction : public Action<Ts...>,
public: public:
TEMPLATABLE_VALUE(uint8_t, new_address) TEMPLATABLE_VALUE(uint8_t, new_address)
void play(const Ts &...x) override { this->parent_->new_i2c_address(this->new_address_.value(x...)); } void play(Ts... x) override { this->parent_->new_i2c_address(this->new_address_.value(x...)); }
}; };
enum AGS10SetZeroPointActionMode { enum AGS10SetZeroPointActionMode {
@@ -122,7 +122,7 @@ template<typename... Ts> class AGS10SetZeroPointAction : public Action<Ts...>, p
TEMPLATABLE_VALUE(uint16_t, value) TEMPLATABLE_VALUE(uint16_t, value)
TEMPLATABLE_VALUE(AGS10SetZeroPointActionMode, mode) TEMPLATABLE_VALUE(AGS10SetZeroPointActionMode, mode)
void play(const Ts &...x) override { void play(Ts... x) override {
switch (this->mode_.value(x...)) { switch (this->mode_.value(x...)) {
case FACTORY_DEFAULT: case FACTORY_DEFAULT:
this->parent_->set_zero_point_with_factory_defaults(); this->parent_->set_zero_point_with_factory_defaults();

View File

@@ -13,7 +13,7 @@ template<typename... Ts> class SetAutoMuteAction : public Action<Ts...> {
TEMPLATABLE_VALUE(uint8_t, auto_mute_mode) TEMPLATABLE_VALUE(uint8_t, auto_mute_mode)
void play(const Ts &...x) override { this->aic3204_->set_auto_mute_mode(this->auto_mute_mode_.value(x...)); } void play(Ts... x) override { this->aic3204_->set_auto_mute_mode(this->auto_mute_mode_.value(x...)); }
protected: protected:
AIC3204 *aic3204_; AIC3204 *aic3204_;

View File

@@ -89,7 +89,7 @@ template<typename... Ts> class ArmAwayAction : public Action<Ts...> {
TEMPLATABLE_VALUE(std::string, code) TEMPLATABLE_VALUE(std::string, code)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->alarm_control_panel_->make_call(); auto call = this->alarm_control_panel_->make_call();
auto code = this->code_.optional_value(x...); auto code = this->code_.optional_value(x...);
if (code.has_value()) { if (code.has_value()) {
@@ -109,7 +109,7 @@ template<typename... Ts> class ArmHomeAction : public Action<Ts...> {
TEMPLATABLE_VALUE(std::string, code) TEMPLATABLE_VALUE(std::string, code)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->alarm_control_panel_->make_call(); auto call = this->alarm_control_panel_->make_call();
auto code = this->code_.optional_value(x...); auto code = this->code_.optional_value(x...);
if (code.has_value()) { if (code.has_value()) {
@@ -129,7 +129,7 @@ template<typename... Ts> class ArmNightAction : public Action<Ts...> {
TEMPLATABLE_VALUE(std::string, code) TEMPLATABLE_VALUE(std::string, code)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->alarm_control_panel_->make_call(); auto call = this->alarm_control_panel_->make_call();
auto code = this->code_.optional_value(x...); auto code = this->code_.optional_value(x...);
if (code.has_value()) { if (code.has_value()) {
@@ -149,7 +149,7 @@ template<typename... Ts> class DisarmAction : public Action<Ts...> {
TEMPLATABLE_VALUE(std::string, code) TEMPLATABLE_VALUE(std::string, code)
void play(const Ts &...x) override { this->alarm_control_panel_->disarm(this->code_.optional_value(x...)); } void play(Ts... x) override { this->alarm_control_panel_->disarm(this->code_.optional_value(x...)); }
protected: protected:
AlarmControlPanel *alarm_control_panel_; AlarmControlPanel *alarm_control_panel_;
@@ -159,7 +159,7 @@ template<typename... Ts> class PendingAction : public Action<Ts...> {
public: public:
explicit PendingAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {} explicit PendingAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
void play(const Ts &...x) override { this->alarm_control_panel_->make_call().pending().perform(); } void play(Ts... x) override { this->alarm_control_panel_->make_call().pending().perform(); }
protected: protected:
AlarmControlPanel *alarm_control_panel_; AlarmControlPanel *alarm_control_panel_;
@@ -169,7 +169,7 @@ template<typename... Ts> class TriggeredAction : public Action<Ts...> {
public: public:
explicit TriggeredAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {} explicit TriggeredAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
void play(const Ts &...x) override { this->alarm_control_panel_->make_call().triggered().perform(); } void play(Ts... x) override { this->alarm_control_panel_->make_call().triggered().perform(); }
protected: protected:
AlarmControlPanel *alarm_control_panel_; AlarmControlPanel *alarm_control_panel_;
@@ -178,7 +178,7 @@ template<typename... Ts> class TriggeredAction : public Action<Ts...> {
template<typename... Ts> class AlarmControlPanelCondition : public Condition<Ts...> { template<typename... Ts> class AlarmControlPanelCondition : public Condition<Ts...> {
public: public:
AlarmControlPanelCondition(AlarmControlPanel *parent) : parent_(parent) {} AlarmControlPanelCondition(AlarmControlPanel *parent) : parent_(parent) {}
bool check(const Ts &...x) override { bool check(Ts... x) override {
return this->parent_->is_state_armed(this->parent_->get_state()) || return this->parent_->is_state_armed(this->parent_->get_state()) ||
this->parent_->get_state() == ACP_STATE_PENDING || this->parent_->get_state() == ACP_STATE_TRIGGERED; this->parent_->get_state() == ACP_STATE_PENDING || this->parent_->get_state() == ACP_STATE_TRIGGERED;
} }

View File

@@ -39,7 +39,7 @@ class Animation : public image::Image {
template<typename... Ts> class AnimationNextFrameAction : public Action<Ts...> { template<typename... Ts> class AnimationNextFrameAction : public Action<Ts...> {
public: public:
AnimationNextFrameAction(Animation *parent) : parent_(parent) {} AnimationNextFrameAction(Animation *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->next_frame(); } void play(Ts... x) override { this->parent_->next_frame(); }
protected: protected:
Animation *parent_; Animation *parent_;
@@ -48,7 +48,7 @@ template<typename... Ts> class AnimationNextFrameAction : public Action<Ts...> {
template<typename... Ts> class AnimationPrevFrameAction : public Action<Ts...> { template<typename... Ts> class AnimationPrevFrameAction : public Action<Ts...> {
public: public:
AnimationPrevFrameAction(Animation *parent) : parent_(parent) {} AnimationPrevFrameAction(Animation *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->prev_frame(); } void play(Ts... x) override { this->parent_->prev_frame(); }
protected: protected:
Animation *parent_; Animation *parent_;
@@ -58,7 +58,7 @@ template<typename... Ts> class AnimationSetFrameAction : public Action<Ts...> {
public: public:
AnimationSetFrameAction(Animation *parent) : parent_(parent) {} AnimationSetFrameAction(Animation *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint16_t, frame) TEMPLATABLE_VALUE(uint16_t, frame)
void play(const Ts &...x) override { this->parent_->set_frame(this->frame_.value(x...)); } void play(Ts... x) override { this->parent_->set_frame(this->frame_.value(x...)); }
protected: protected:
Animation *parent_; Animation *parent_;

View File

@@ -237,7 +237,7 @@ extern APIServer *global_api_server; // NOLINT(cppcoreguidelines-avoid-non-cons
template<typename... Ts> class APIConnectedCondition : public Condition<Ts...> { template<typename... Ts> class APIConnectedCondition : public Condition<Ts...> {
public: public:
bool check(const Ts &...x) override { return global_api_server->is_connected(); } bool check(Ts... x) override { return global_api_server->is_connected(); }
}; };
} // namespace esphome::api } // namespace esphome::api

View File

@@ -9,11 +9,11 @@
namespace esphome::api { namespace esphome::api {
#ifdef USE_API_SERVICES #ifdef USE_API_SERVICES
template<typename T, typename... Ts> class CustomAPIDeviceService : public UserServiceDynamic<Ts...> { template<typename T, typename... Ts> class CustomAPIDeviceService : public UserServiceBase<Ts...> {
public: public:
CustomAPIDeviceService(const std::string &name, const std::array<std::string, sizeof...(Ts)> &arg_names, T *obj, CustomAPIDeviceService(const std::string &name, const std::array<std::string, sizeof...(Ts)> &arg_names, T *obj,
void (T::*callback)(Ts...)) void (T::*callback)(Ts...))
: UserServiceDynamic<Ts...>(name, arg_names), obj_(obj), callback_(callback) {} : UserServiceBase<Ts...>(name, arg_names), obj_(obj), callback_(callback) {}
protected: protected:
void execute(Ts... x) override { (this->obj_->*this->callback_)(x...); } // NOLINT void execute(Ts... x) override { (this->obj_->*this->callback_)(x...); } // NOLINT

View File

@@ -133,7 +133,7 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts
Trigger<std::string, Ts...> *get_error_trigger() const { return this->error_trigger_; } Trigger<std::string, Ts...> *get_error_trigger() const { return this->error_trigger_; }
#endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES
void play(const Ts &...x) override { void play(Ts... x) override {
HomeassistantActionRequest resp; HomeassistantActionRequest resp;
std::string service_value = this->service_.value(x...); std::string service_value = this->service_.value(x...);
resp.set_service(StringRef(service_value)); resp.set_service(StringRef(service_value));

View File

@@ -23,57 +23,11 @@ template<typename T> T get_execute_arg_value(const ExecuteServiceArgument &arg);
template<typename T> enums::ServiceArgType to_service_arg_type(); template<typename T> enums::ServiceArgType to_service_arg_type();
// Base class for YAML-defined services (most common case)
// Stores only pointers to string literals in flash - no heap allocation
template<typename... Ts> class UserServiceBase : public UserServiceDescriptor { template<typename... Ts> class UserServiceBase : public UserServiceDescriptor {
public: public:
UserServiceBase(const char *name, const std::array<const char *, sizeof...(Ts)> &arg_names) UserServiceBase(std::string name, const std::array<std::string, sizeof...(Ts)> &arg_names)
: name_(name), arg_names_(arg_names) {
this->key_ = fnv1_hash(name);
}
ListEntitiesServicesResponse encode_list_service_response() override {
ListEntitiesServicesResponse msg;
msg.set_name(StringRef(this->name_));
msg.key = this->key_;
std::array<enums::ServiceArgType, sizeof...(Ts)> arg_types = {to_service_arg_type<Ts>()...};
msg.args.init(sizeof...(Ts));
for (size_t i = 0; i < sizeof...(Ts); i++) {
auto &arg = msg.args.emplace_back();
arg.type = arg_types[i];
arg.set_name(StringRef(this->arg_names_[i]));
}
return msg;
}
bool execute_service(const ExecuteServiceRequest &req) override {
if (req.key != this->key_)
return false;
if (req.args.size() != sizeof...(Ts))
return false;
this->execute_(req.args, typename gens<sizeof...(Ts)>::type());
return true;
}
protected:
virtual void execute(Ts... x) = 0;
template<typename ArgsContainer, int... S> void execute_(const ArgsContainer &args, seq<S...> type) {
this->execute((get_execute_arg_value<Ts>(args[S]))...);
}
// Pointers to string literals in flash - no heap allocation
const char *name_;
std::array<const char *, sizeof...(Ts)> arg_names_;
uint32_t key_{0};
};
// Separate class for custom_api_device services (rare case)
// Stores copies of runtime-generated names
template<typename... Ts> class UserServiceDynamic : public UserServiceDescriptor {
public:
UserServiceDynamic(std::string name, const std::array<std::string, sizeof...(Ts)> &arg_names)
: name_(std::move(name)), arg_names_(arg_names) { : name_(std::move(name)), arg_names_(arg_names) {
this->key_ = fnv1_hash(this->name_.c_str()); this->key_ = fnv1_hash(this->name_);
} }
ListEntitiesServicesResponse encode_list_service_response() override { ListEntitiesServicesResponse encode_list_service_response() override {
@@ -93,7 +47,7 @@ template<typename... Ts> class UserServiceDynamic : public UserServiceDescriptor
bool execute_service(const ExecuteServiceRequest &req) override { bool execute_service(const ExecuteServiceRequest &req) override {
if (req.key != this->key_) if (req.key != this->key_)
return false; return false;
if (req.args.size() != sizeof...(Ts)) if (req.args.size() != this->arg_names_.size())
return false; return false;
this->execute_(req.args, typename gens<sizeof...(Ts)>::type()); this->execute_(req.args, typename gens<sizeof...(Ts)>::type());
return true; return true;
@@ -105,16 +59,14 @@ template<typename... Ts> class UserServiceDynamic : public UserServiceDescriptor
this->execute((get_execute_arg_value<Ts>(args[S]))...); this->execute((get_execute_arg_value<Ts>(args[S]))...);
} }
// Heap-allocated strings for runtime-generated names
std::string name_; std::string name_;
std::array<std::string, sizeof...(Ts)> arg_names_;
uint32_t key_{0}; uint32_t key_{0};
std::array<std::string, sizeof...(Ts)> arg_names_;
}; };
template<typename... Ts> class UserServiceTrigger : public UserServiceBase<Ts...>, public Trigger<Ts...> { template<typename... Ts> class UserServiceTrigger : public UserServiceBase<Ts...>, public Trigger<Ts...> {
public: public:
// Constructor for static names (YAML-defined services - used by code generator) UserServiceTrigger(const std::string &name, const std::array<std::string, sizeof...(Ts)> &arg_names)
UserServiceTrigger(const char *name, const std::array<const char *, sizeof...(Ts)> &arg_names)
: UserServiceBase<Ts...>(name, arg_names) {} : UserServiceBase<Ts...>(name, arg_names) {}
protected: protected:

View File

@@ -10,7 +10,7 @@ namespace at581x {
template<typename... Ts> class AT581XResetAction : public Action<Ts...>, public Parented<AT581XComponent> { template<typename... Ts> class AT581XResetAction : public Action<Ts...>, public Parented<AT581XComponent> {
public: public:
void play(const Ts &...x) { this->parent_->reset_hardware_frontend(); } void play(Ts... x) { this->parent_->reset_hardware_frontend(); }
}; };
template<typename... Ts> class AT581XSettingsAction : public Action<Ts...>, public Parented<AT581XComponent> { template<typename... Ts> class AT581XSettingsAction : public Action<Ts...>, public Parented<AT581XComponent> {
@@ -25,7 +25,7 @@ template<typename... Ts> class AT581XSettingsAction : public Action<Ts...>, publ
TEMPLATABLE_VALUE(int, trigger_keep) TEMPLATABLE_VALUE(int, trigger_keep)
TEMPLATABLE_VALUE(int, stage_gain) TEMPLATABLE_VALUE(int, stage_gain)
void play(const Ts &...x) { void play(Ts... x) {
if (this->frequency_.has_value()) { if (this->frequency_.has_value()) {
int v = this->frequency_.value(x...); int v = this->frequency_.value(x...);
this->parent_->set_frequency(v); this->parent_->set_frequency(v);

View File

@@ -13,7 +13,7 @@ template<typename... Ts> class SetMicGainAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, mic_gain) TEMPLATABLE_VALUE(float, mic_gain)
void play(const Ts &...x) override { this->audio_adc_->set_mic_gain(this->mic_gain_.value(x...)); } void play(Ts... x) override { this->audio_adc_->set_mic_gain(this->mic_gain_.value(x...)); }
protected: protected:
AudioAdc *audio_adc_; AudioAdc *audio_adc_;

View File

@@ -11,7 +11,7 @@ template<typename... Ts> class MuteOffAction : public Action<Ts...> {
public: public:
explicit MuteOffAction(AudioDac *audio_dac) : audio_dac_(audio_dac) {} explicit MuteOffAction(AudioDac *audio_dac) : audio_dac_(audio_dac) {}
void play(const Ts &...x) override { this->audio_dac_->set_mute_off(); } void play(Ts... x) override { this->audio_dac_->set_mute_off(); }
protected: protected:
AudioDac *audio_dac_; AudioDac *audio_dac_;
@@ -21,7 +21,7 @@ template<typename... Ts> class MuteOnAction : public Action<Ts...> {
public: public:
explicit MuteOnAction(AudioDac *audio_dac) : audio_dac_(audio_dac) {} explicit MuteOnAction(AudioDac *audio_dac) : audio_dac_(audio_dac) {}
void play(const Ts &...x) override { this->audio_dac_->set_mute_on(); } void play(Ts... x) override { this->audio_dac_->set_mute_on(); }
protected: protected:
AudioDac *audio_dac_; AudioDac *audio_dac_;
@@ -33,7 +33,7 @@ template<typename... Ts> class SetVolumeAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, volume) TEMPLATABLE_VALUE(float, volume)
void play(const Ts &...x) override { this->audio_dac_->set_volume(this->volume_.value(x...)); } void play(Ts... x) override { this->audio_dac_->set_volume(this->volume_.value(x...)); }
protected: protected:
AudioDac *audio_dac_; AudioDac *audio_dac_;

View File

@@ -141,7 +141,7 @@ class StateChangeTrigger : public Trigger<optional<bool>, optional<bool> > {
template<typename... Ts> class BinarySensorCondition : public Condition<Ts...> { template<typename... Ts> class BinarySensorCondition : public Condition<Ts...> {
public: public:
BinarySensorCondition(BinarySensor *parent, bool state) : parent_(parent), state_(state) {} BinarySensorCondition(BinarySensor *parent, bool state) : parent_(parent), state_(state) {}
bool check(const Ts &...x) override { return this->parent_->state == this->state_; } bool check(Ts... x) override { return this->parent_->state == this->state_; }
protected: protected:
BinarySensor *parent_; BinarySensor *parent_;
@@ -153,7 +153,7 @@ template<typename... Ts> class BinarySensorPublishAction : public Action<Ts...>
explicit BinarySensorPublishAction(BinarySensor *sensor) : sensor_(sensor) {} explicit BinarySensorPublishAction(BinarySensor *sensor) : sensor_(sensor) {}
TEMPLATABLE_VALUE(bool, state) TEMPLATABLE_VALUE(bool, state)
void play(const Ts &...x) override { void play(Ts... x) override {
auto val = this->state_.value(x...); auto val = this->state_.value(x...);
this->sensor_->publish_state(val); this->sensor_->publish_state(val);
} }
@@ -166,7 +166,7 @@ template<typename... Ts> class BinarySensorInvalidateAction : public Action<Ts..
public: public:
explicit BinarySensorInvalidateAction(BinarySensor *sensor) : sensor_(sensor) {} explicit BinarySensorInvalidateAction(BinarySensor *sensor) : sensor_(sensor) {}
void play(const Ts &...x) override { this->sensor_->invalidate_state(); } void play(Ts... x) override { this->sensor_->invalidate_state(); }
protected: protected:
BinarySensor *sensor_; BinarySensor *sensor_;

View File

@@ -89,7 +89,7 @@ class BL0906 : public PollingComponent, public uart::UARTDevice {
template<typename... Ts> class ResetEnergyAction : public Action<Ts...>, public Parented<BL0906> { template<typename... Ts> class ResetEnergyAction : public Action<Ts...>, public Parented<BL0906> {
public: public:
void play(const Ts &...x) override { this->parent_->enqueue_action_(&BL0906::reset_energy_); } void play(Ts... x) override { this->parent_->enqueue_action_(&BL0906::reset_energy_); }
}; };
} // namespace bl0906 } // namespace bl0906

View File

@@ -123,9 +123,9 @@ template<typename... Ts> class BLEClientWriteAction : public Action<Ts...>, publ
this->has_simple_value_ = true; this->has_simple_value_ = true;
} }
void play(const Ts &...x) override {} void play(Ts... x) override {}
void play_complex(const Ts &...x) override { void play_complex(Ts... x) override {
this->num_running_++; this->num_running_++;
this->var_ = std::make_tuple(x...); this->var_ = std::make_tuple(x...);
auto value = this->has_simple_value_ ? this->value_.simple : this->value_.template_func(x...); auto value = this->has_simple_value_ ? this->value_.simple : this->value_.template_func(x...);
@@ -229,7 +229,7 @@ template<typename... Ts> class BLEClientPasskeyReplyAction : public Action<Ts...
public: public:
BLEClientPasskeyReplyAction(BLEClient *ble_client) { parent_ = ble_client; } BLEClientPasskeyReplyAction(BLEClient *ble_client) { parent_ = ble_client; }
void play(const Ts &...x) override { void play(Ts... x) override {
uint32_t passkey; uint32_t passkey;
if (has_simple_value_) { if (has_simple_value_) {
passkey = this->value_.simple; passkey = this->value_.simple;
@@ -266,7 +266,7 @@ template<typename... Ts> class BLEClientNumericComparisonReplyAction : public Ac
public: public:
BLEClientNumericComparisonReplyAction(BLEClient *ble_client) { parent_ = ble_client; } BLEClientNumericComparisonReplyAction(BLEClient *ble_client) { parent_ = ble_client; }
void play(const Ts &...x) override { void play(Ts... x) override {
esp_bd_addr_t remote_bda; esp_bd_addr_t remote_bda;
memcpy(remote_bda, parent_->get_remote_bda(), sizeof(esp_bd_addr_t)); memcpy(remote_bda, parent_->get_remote_bda(), sizeof(esp_bd_addr_t));
if (has_simple_value_) { if (has_simple_value_) {
@@ -299,7 +299,7 @@ template<typename... Ts> class BLEClientRemoveBondAction : public Action<Ts...>
public: public:
BLEClientRemoveBondAction(BLEClient *ble_client) { parent_ = ble_client; } BLEClientRemoveBondAction(BLEClient *ble_client) { parent_ = ble_client; }
void play(const Ts &...x) override { void play(Ts... x) override {
esp_bd_addr_t remote_bda; esp_bd_addr_t remote_bda;
memcpy(remote_bda, parent_->get_remote_bda(), sizeof(esp_bd_addr_t)); memcpy(remote_bda, parent_->get_remote_bda(), sizeof(esp_bd_addr_t));
esp_ble_remove_bond_device(remote_bda); esp_ble_remove_bond_device(remote_bda);
@@ -334,9 +334,9 @@ template<typename... Ts> class BLEClientConnectAction : public Action<Ts...>, pu
} }
// not used since we override play_complex_ // not used since we override play_complex_
void play(const Ts &...x) override {} void play(Ts... x) override {}
void play_complex(const Ts &...x) override { void play_complex(Ts... x) override {
// it makes no sense to have multiple instances of this running at the same time. // it makes no sense to have multiple instances of this running at the same time.
// this would occur only if the same automation was re-triggered while still // this would occur only if the same automation was re-triggered while still
// running. So just cancel the second chain if this is detected. // running. So just cancel the second chain if this is detected.
@@ -379,9 +379,9 @@ template<typename... Ts> class BLEClientDisconnectAction : public Action<Ts...>,
} }
// not used since we override play_complex_ // not used since we override play_complex_
void play(const Ts &...x) override {} void play(Ts... x) override {}
void play_complex(const Ts &...x) override { void play_complex(Ts... x) override {
this->num_running_++; this->num_running_++;
if (this->node_state == espbt::ClientState::IDLE) { if (this->node_state == espbt::ClientState::IDLE) {
this->play_next_(x...); this->play_next_(x...);

View File

@@ -11,7 +11,7 @@ template<typename... Ts> class PressAction : public Action<Ts...> {
public: public:
explicit PressAction(Button *button) : button_(button) {} explicit PressAction(Button *button) : button_(button) {}
void play(const Ts &...x) override { this->button_->press(); } void play(Ts... x) override { this->button_->press(); }
protected: protected:
Button *button_; Button *button_;

View File

@@ -129,7 +129,7 @@ template<typename... Ts> class CanbusSendAction : public Action<Ts...>, public P
this->remote_transmission_request_ = remote_transmission_request; this->remote_transmission_request_ = remote_transmission_request;
} }
void play(const Ts &...x) override { void play(Ts... x) override {
auto can_id = this->can_id_.has_value() ? *this->can_id_ : this->parent_->can_id_; auto can_id = this->can_id_.has_value() ? *this->can_id_ : this->parent_->can_id_;
auto use_extended_id = auto use_extended_id =
this->use_extended_id_.has_value() ? *this->use_extended_id_ : this->parent_->use_extended_id_; this->use_extended_id_.has_value() ? *this->use_extended_id_ : this->parent_->use_extended_id_;

View File

@@ -22,7 +22,7 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
TEMPLATABLE_VALUE(std::string, custom_preset) TEMPLATABLE_VALUE(std::string, custom_preset)
TEMPLATABLE_VALUE(ClimateSwingMode, swing_mode) TEMPLATABLE_VALUE(ClimateSwingMode, swing_mode)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->climate_->make_call(); auto call = this->climate_->make_call();
call.set_mode(this->mode_.optional_value(x...)); call.set_mode(this->mode_.optional_value(x...));
call.set_target_temperature(this->target_temperature_.optional_value(x...)); call.set_target_temperature(this->target_temperature_.optional_value(x...));

View File

@@ -30,7 +30,7 @@ template<typename... Ts> class CM1106CalibrateZeroAction : public Action<Ts...>
public: public:
CM1106CalibrateZeroAction(CM1106Component *cm1106) : cm1106_(cm1106) {} CM1106CalibrateZeroAction(CM1106Component *cm1106) : cm1106_(cm1106) {}
void play(const Ts &...x) override { this->cm1106_->calibrate_zero(400); } void play(Ts... x) override { this->cm1106_->calibrate_zero(400); }
protected: protected:
CM1106Component *cm1106_; CM1106Component *cm1106_;

View File

@@ -11,7 +11,7 @@ template<typename... Ts> class OpenAction : public Action<Ts...> {
public: public:
explicit OpenAction(Cover *cover) : cover_(cover) {} explicit OpenAction(Cover *cover) : cover_(cover) {}
void play(const Ts &...x) override { this->cover_->make_call().set_command_open().perform(); } void play(Ts... x) override { this->cover_->make_call().set_command_open().perform(); }
protected: protected:
Cover *cover_; Cover *cover_;
@@ -21,7 +21,7 @@ template<typename... Ts> class CloseAction : public Action<Ts...> {
public: public:
explicit CloseAction(Cover *cover) : cover_(cover) {} explicit CloseAction(Cover *cover) : cover_(cover) {}
void play(const Ts &...x) override { this->cover_->make_call().set_command_close().perform(); } void play(Ts... x) override { this->cover_->make_call().set_command_close().perform(); }
protected: protected:
Cover *cover_; Cover *cover_;
@@ -31,7 +31,7 @@ template<typename... Ts> class StopAction : public Action<Ts...> {
public: public:
explicit StopAction(Cover *cover) : cover_(cover) {} explicit StopAction(Cover *cover) : cover_(cover) {}
void play(const Ts &...x) override { this->cover_->make_call().set_command_stop().perform(); } void play(Ts... x) override { this->cover_->make_call().set_command_stop().perform(); }
protected: protected:
Cover *cover_; Cover *cover_;
@@ -41,7 +41,7 @@ template<typename... Ts> class ToggleAction : public Action<Ts...> {
public: public:
explicit ToggleAction(Cover *cover) : cover_(cover) {} explicit ToggleAction(Cover *cover) : cover_(cover) {}
void play(const Ts &...x) override { this->cover_->make_call().set_command_toggle().perform(); } void play(Ts... x) override { this->cover_->make_call().set_command_toggle().perform(); }
protected: protected:
Cover *cover_; Cover *cover_;
@@ -55,7 +55,7 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, position) TEMPLATABLE_VALUE(float, position)
TEMPLATABLE_VALUE(float, tilt) TEMPLATABLE_VALUE(float, tilt)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->cover_->make_call(); auto call = this->cover_->make_call();
if (this->stop_.has_value()) if (this->stop_.has_value())
call.set_stop(this->stop_.value(x...)); call.set_stop(this->stop_.value(x...));
@@ -77,7 +77,7 @@ template<typename... Ts> class CoverPublishAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, tilt) TEMPLATABLE_VALUE(float, tilt)
TEMPLATABLE_VALUE(CoverOperation, current_operation) TEMPLATABLE_VALUE(CoverOperation, current_operation)
void play(const Ts &...x) override { void play(Ts... x) override {
if (this->position_.has_value()) if (this->position_.has_value())
this->cover_->position = this->position_.value(x...); this->cover_->position = this->position_.value(x...);
if (this->tilt_.has_value()) if (this->tilt_.has_value())
@@ -94,7 +94,7 @@ template<typename... Ts> class CoverPublishAction : public Action<Ts...> {
template<typename... Ts> class CoverIsOpenCondition : public Condition<Ts...> { template<typename... Ts> class CoverIsOpenCondition : public Condition<Ts...> {
public: public:
CoverIsOpenCondition(Cover *cover) : cover_(cover) {} CoverIsOpenCondition(Cover *cover) : cover_(cover) {}
bool check(const Ts &...x) override { return this->cover_->is_fully_open(); } bool check(Ts... x) override { return this->cover_->is_fully_open(); }
protected: protected:
Cover *cover_; Cover *cover_;
@@ -103,7 +103,7 @@ template<typename... Ts> class CoverIsOpenCondition : public Condition<Ts...> {
template<typename... Ts> class CoverIsClosedCondition : public Condition<Ts...> { template<typename... Ts> class CoverIsClosedCondition : public Condition<Ts...> {
public: public:
CoverIsClosedCondition(Cover *cover) : cover_(cover) {} CoverIsClosedCondition(Cover *cover) : cover_(cover) {}
bool check(const Ts &...x) override { return this->cover_->is_fully_closed(); } bool check(Ts... x) override { return this->cover_->is_fully_closed(); }
protected: protected:
Cover *cover_; Cover *cover_;

View File

@@ -114,7 +114,7 @@ template<typename... Ts> class CS5460ARestartAction : public Action<Ts...> {
public: public:
CS5460ARestartAction(CS5460AComponent *cs5460a) : cs5460a_(cs5460a) {} CS5460ARestartAction(CS5460AComponent *cs5460a) : cs5460a_(cs5460a) {}
void play(const Ts &...x) override { cs5460a_->restart(); } void play(Ts... x) override { cs5460a_->restart(); }
protected: protected:
CS5460AComponent *cs5460a_; CS5460AComponent *cs5460a_;

View File

@@ -101,7 +101,7 @@ template<typename... Ts> class DateSetAction : public Action<Ts...>, public Pare
public: public:
TEMPLATABLE_VALUE(ESPTime, date) TEMPLATABLE_VALUE(ESPTime, date)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->parent_->make_call(); auto call = this->parent_->make_call();
if (this->date_.has_value()) { if (this->date_.has_value()) {

View File

@@ -124,7 +124,7 @@ template<typename... Ts> class DateTimeSetAction : public Action<Ts...>, public
public: public:
TEMPLATABLE_VALUE(ESPTime, datetime) TEMPLATABLE_VALUE(ESPTime, datetime)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->parent_->make_call(); auto call = this->parent_->make_call();
if (this->datetime_.has_value()) { if (this->datetime_.has_value()) {

View File

@@ -103,7 +103,7 @@ template<typename... Ts> class TimeSetAction : public Action<Ts...>, public Pare
public: public:
TEMPLATABLE_VALUE(ESPTime, time) TEMPLATABLE_VALUE(ESPTime, time)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->parent_->make_call(); auto call = this->parent_->make_call();
if (this->time_.has_value()) { if (this->time_.has_value()) {

View File

@@ -148,7 +148,7 @@ template<typename... Ts> class EnterDeepSleepAction : public Action<Ts...> {
void set_time(time::RealTimeClock *time) { this->time_ = time; } void set_time(time::RealTimeClock *time) { this->time_ = time; }
#endif #endif
void play(const Ts &...x) override { void play(Ts... x) override {
if (this->sleep_duration_.has_value()) { if (this->sleep_duration_.has_value()) {
this->deep_sleep_->set_sleep_duration(this->sleep_duration_.value(x...)); this->deep_sleep_->set_sleep_duration(this->sleep_duration_.value(x...));
} }
@@ -207,12 +207,12 @@ template<typename... Ts> class EnterDeepSleepAction : public Action<Ts...> {
template<typename... Ts> class PreventDeepSleepAction : public Action<Ts...>, public Parented<DeepSleepComponent> { template<typename... Ts> class PreventDeepSleepAction : public Action<Ts...>, public Parented<DeepSleepComponent> {
public: public:
void play(const Ts &...x) override { this->parent_->prevent_deep_sleep(); } void play(Ts... x) override { this->parent_->prevent_deep_sleep(); }
}; };
template<typename... Ts> class AllowDeepSleepAction : public Action<Ts...>, public Parented<DeepSleepComponent> { template<typename... Ts> class AllowDeepSleepAction : public Action<Ts...>, public Parented<DeepSleepComponent> {
public: public:
void play(const Ts &...x) override { this->parent_->allow_deep_sleep(); } void play(Ts... x) override { this->parent_->allow_deep_sleep(); }
}; };
} // namespace deep_sleep } // namespace deep_sleep

View File

@@ -8,7 +8,7 @@ namespace demo {
class DemoSelect : public select::Select, public Component { class DemoSelect : public select::Select, public Component {
protected: protected:
void control(size_t index) override { this->publish_state(index); } void control(const std::string &value) override { this->publish_state(value); }
}; };
} // namespace demo } // namespace demo

View File

@@ -77,7 +77,7 @@ class DFPlayer : public uart::UARTDevice, public Component {
class ACTION_CLASS : /* NOLINT */ \ class ACTION_CLASS : /* NOLINT */ \
public Action<Ts...>, \ public Action<Ts...>, \
public Parented<DFPlayer> { \ public Parented<DFPlayer> { \
void play(const Ts &...x) override { this->parent_->ACTION_METHOD(); } \ void play(Ts... x) override { this->parent_->ACTION_METHOD(); } \
}; };
DFPLAYER_SIMPLE_ACTION(NextAction, next) DFPLAYER_SIMPLE_ACTION(NextAction, next)
@@ -87,7 +87,7 @@ template<typename... Ts> class PlayMp3Action : public Action<Ts...>, public Pare
public: public:
TEMPLATABLE_VALUE(uint16_t, file) TEMPLATABLE_VALUE(uint16_t, file)
void play(const Ts &...x) override { void play(Ts... x) override {
auto file = this->file_.value(x...); auto file = this->file_.value(x...);
this->parent_->play_mp3(file); this->parent_->play_mp3(file);
} }
@@ -98,7 +98,7 @@ template<typename... Ts> class PlayFileAction : public Action<Ts...>, public Par
TEMPLATABLE_VALUE(uint16_t, file) TEMPLATABLE_VALUE(uint16_t, file)
TEMPLATABLE_VALUE(bool, loop) TEMPLATABLE_VALUE(bool, loop)
void play(const Ts &...x) override { void play(Ts... x) override {
auto file = this->file_.value(x...); auto file = this->file_.value(x...);
auto loop = this->loop_.value(x...); auto loop = this->loop_.value(x...);
if (loop) { if (loop) {
@@ -115,7 +115,7 @@ template<typename... Ts> class PlayFolderAction : public Action<Ts...>, public P
TEMPLATABLE_VALUE(uint16_t, file) TEMPLATABLE_VALUE(uint16_t, file)
TEMPLATABLE_VALUE(bool, loop) TEMPLATABLE_VALUE(bool, loop)
void play(const Ts &...x) override { void play(Ts... x) override {
auto folder = this->folder_.value(x...); auto folder = this->folder_.value(x...);
auto file = this->file_.value(x...); auto file = this->file_.value(x...);
auto loop = this->loop_.value(x...); auto loop = this->loop_.value(x...);
@@ -131,7 +131,7 @@ template<typename... Ts> class SetDeviceAction : public Action<Ts...>, public Pa
public: public:
TEMPLATABLE_VALUE(Device, device) TEMPLATABLE_VALUE(Device, device)
void play(const Ts &...x) override { void play(Ts... x) override {
auto device = this->device_.value(x...); auto device = this->device_.value(x...);
this->parent_->set_device(device); this->parent_->set_device(device);
} }
@@ -141,7 +141,7 @@ template<typename... Ts> class SetVolumeAction : public Action<Ts...>, public Pa
public: public:
TEMPLATABLE_VALUE(uint8_t, volume) TEMPLATABLE_VALUE(uint8_t, volume)
void play(const Ts &...x) override { void play(Ts... x) override {
auto volume = this->volume_.value(x...); auto volume = this->volume_.value(x...);
this->parent_->set_volume(volume); this->parent_->set_volume(volume);
} }
@@ -151,7 +151,7 @@ template<typename... Ts> class SetEqAction : public Action<Ts...>, public Parent
public: public:
TEMPLATABLE_VALUE(EqPreset, eq) TEMPLATABLE_VALUE(EqPreset, eq)
void play(const Ts &...x) override { void play(Ts... x) override {
auto eq = this->eq_.value(x...); auto eq = this->eq_.value(x...);
this->parent_->set_eq(eq); this->parent_->set_eq(eq);
} }
@@ -168,7 +168,7 @@ DFPLAYER_SIMPLE_ACTION(VolumeDownAction, volume_down)
template<typename... Ts> class DFPlayerIsPlayingCondition : public Condition<Ts...>, public Parented<DFPlayer> { template<typename... Ts> class DFPlayerIsPlayingCondition : public Condition<Ts...>, public Parented<DFPlayer> {
public: public:
bool check(const Ts &...x) override { return this->parent_->is_playing(); } bool check(Ts... x) override { return this->parent_->is_playing(); }
}; };
class DFPlayerFinishedPlaybackTrigger : public Trigger<> { class DFPlayerFinishedPlaybackTrigger : public Trigger<> {

View File

@@ -11,7 +11,7 @@ namespace dfrobot_sen0395 {
template<typename... Ts> template<typename... Ts>
class DfrobotSen0395ResetAction : public Action<Ts...>, public Parented<DfrobotSen0395Component> { class DfrobotSen0395ResetAction : public Action<Ts...>, public Parented<DfrobotSen0395Component> {
public: public:
void play(const Ts &...x) { this->parent_->enqueue(make_unique<ResetSystemCommand>()); } void play(Ts... x) { this->parent_->enqueue(make_unique<ResetSystemCommand>()); }
}; };
template<typename... Ts> template<typename... Ts>
@@ -33,7 +33,7 @@ class DfrobotSen0395SettingsAction : public Action<Ts...>, public Parented<Dfrob
TEMPLATABLE_VALUE(float, det_min4) TEMPLATABLE_VALUE(float, det_min4)
TEMPLATABLE_VALUE(float, det_max4) TEMPLATABLE_VALUE(float, det_max4)
void play(const Ts &...x) { void play(Ts... x) {
this->parent_->enqueue(make_unique<PowerCommand>(0)); this->parent_->enqueue(make_unique<PowerCommand>(0));
if (this->factory_reset_.has_value() && this->factory_reset_.value(x...) == true) { if (this->factory_reset_.has_value() && this->factory_reset_.value(x...) == true) {
this->parent_->enqueue(make_unique<FactoryResetCommand>()); this->parent_->enqueue(make_unique<FactoryResetCommand>());

View File

@@ -819,7 +819,7 @@ template<typename... Ts> class DisplayPageShowAction : public Action<Ts...> {
public: public:
TEMPLATABLE_VALUE(DisplayPage *, page) TEMPLATABLE_VALUE(DisplayPage *, page)
void play(const Ts &...x) override { void play(Ts... x) override {
auto *page = this->page_.value(x...); auto *page = this->page_.value(x...);
if (page != nullptr) { if (page != nullptr) {
page->show(); page->show();
@@ -831,7 +831,7 @@ template<typename... Ts> class DisplayPageShowNextAction : public Action<Ts...>
public: public:
DisplayPageShowNextAction(Display *buffer) : buffer_(buffer) {} DisplayPageShowNextAction(Display *buffer) : buffer_(buffer) {}
void play(const Ts &...x) override { this->buffer_->show_next_page(); } void play(Ts... x) override { this->buffer_->show_next_page(); }
Display *buffer_; Display *buffer_;
}; };
@@ -840,7 +840,7 @@ template<typename... Ts> class DisplayPageShowPrevAction : public Action<Ts...>
public: public:
DisplayPageShowPrevAction(Display *buffer) : buffer_(buffer) {} DisplayPageShowPrevAction(Display *buffer) : buffer_(buffer) {}
void play(const Ts &...x) override { this->buffer_->show_prev_page(); } void play(Ts... x) override { this->buffer_->show_prev_page(); }
Display *buffer_; Display *buffer_;
}; };
@@ -850,7 +850,7 @@ template<typename... Ts> class DisplayIsDisplayingPageCondition : public Conditi
DisplayIsDisplayingPageCondition(Display *parent) : parent_(parent) {} DisplayIsDisplayingPageCondition(Display *parent) : parent_(parent) {}
void set_page(DisplayPage *page) { this->page_ = page; } void set_page(DisplayPage *page) { this->page_ = page; }
bool check(const Ts &...x) override { return this->parent_->get_active_page() == this->page_; } bool check(Ts... x) override { return this->parent_->get_active_page() == this->page_; }
protected: protected:
Display *parent_; Display *parent_;

View File

@@ -10,7 +10,7 @@ template<typename... Ts> class UpAction : public Action<Ts...> {
public: public:
explicit UpAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit UpAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->up(); } void play(Ts... x) override { this->menu_->up(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -20,7 +20,7 @@ template<typename... Ts> class DownAction : public Action<Ts...> {
public: public:
explicit DownAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit DownAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->down(); } void play(Ts... x) override { this->menu_->down(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -30,7 +30,7 @@ template<typename... Ts> class LeftAction : public Action<Ts...> {
public: public:
explicit LeftAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit LeftAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->left(); } void play(Ts... x) override { this->menu_->left(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -40,7 +40,7 @@ template<typename... Ts> class RightAction : public Action<Ts...> {
public: public:
explicit RightAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit RightAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->right(); } void play(Ts... x) override { this->menu_->right(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -50,7 +50,7 @@ template<typename... Ts> class EnterAction : public Action<Ts...> {
public: public:
explicit EnterAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit EnterAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->enter(); } void play(Ts... x) override { this->menu_->enter(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -60,7 +60,7 @@ template<typename... Ts> class ShowAction : public Action<Ts...> {
public: public:
explicit ShowAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit ShowAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->show(); } void play(Ts... x) override { this->menu_->show(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -70,7 +70,7 @@ template<typename... Ts> class HideAction : public Action<Ts...> {
public: public:
explicit HideAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit HideAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->hide(); } void play(Ts... x) override { this->menu_->hide(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -80,7 +80,7 @@ template<typename... Ts> class ShowMainAction : public Action<Ts...> {
public: public:
explicit ShowMainAction(DisplayMenuComponent *menu) : menu_(menu) {} explicit ShowMainAction(DisplayMenuComponent *menu) : menu_(menu) {}
void play(const Ts &...x) override { this->menu_->show_main(); } void play(Ts... x) override { this->menu_->show_main(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;
@@ -88,7 +88,7 @@ template<typename... Ts> class ShowMainAction : public Action<Ts...> {
template<typename... Ts> class IsActiveCondition : public Condition<Ts...> { template<typename... Ts> class IsActiveCondition : public Condition<Ts...> {
public: public:
explicit IsActiveCondition(DisplayMenuComponent *menu) : menu_(menu) {} explicit IsActiveCondition(DisplayMenuComponent *menu) : menu_(menu) {}
bool check(const Ts &...x) override { return this->menu_->is_active(); } bool check(Ts... x) override { return this->menu_->is_active(); }
protected: protected:
DisplayMenuComponent *menu_; DisplayMenuComponent *menu_;

View File

@@ -59,12 +59,12 @@ class DS1307Component : public time::RealTimeClock, public i2c::I2CDevice {
template<typename... Ts> class WriteAction : public Action<Ts...>, public Parented<DS1307Component> { template<typename... Ts> class WriteAction : public Action<Ts...>, public Parented<DS1307Component> {
public: public:
void play(const Ts &...x) override { this->parent_->write_time(); } void play(Ts... x) override { this->parent_->write_time(); }
}; };
template<typename... Ts> class ReadAction : public Action<Ts...>, public Parented<DS1307Component> { template<typename... Ts> class ReadAction : public Action<Ts...>, public Parented<DS1307Component> {
public: public:
void play(const Ts &...x) override { this->parent_->read_time(); } void play(Ts... x) override { this->parent_->read_time(); }
}; };
} // namespace ds1307 } // namespace ds1307
} // namespace esphome } // namespace esphome

View File

@@ -51,15 +51,15 @@ class DutyTimeSensor : public sensor::Sensor, public PollingComponent {
template<typename... Ts> class BaseAction : public Action<Ts...>, public Parented<DutyTimeSensor> {}; template<typename... Ts> class BaseAction : public Action<Ts...>, public Parented<DutyTimeSensor> {};
template<typename... Ts> class StartAction : public BaseAction<Ts...> { template<typename... Ts> class StartAction : public BaseAction<Ts...> {
void play(const Ts &...x) override { this->parent_->start(); } void play(Ts... x) override { this->parent_->start(); }
}; };
template<typename... Ts> class StopAction : public BaseAction<Ts...> { template<typename... Ts> class StopAction : public BaseAction<Ts...> {
void play(const Ts &...x) override { this->parent_->stop(); } void play(Ts... x) override { this->parent_->stop(); }
}; };
template<typename... Ts> class ResetAction : public BaseAction<Ts...> { template<typename... Ts> class ResetAction : public BaseAction<Ts...> {
void play(const Ts &...x) override { this->parent_->reset(); } void play(Ts... x) override { this->parent_->reset(); }
}; };
template<typename... Ts> class RunningCondition : public Condition<Ts...>, public Parented<DutyTimeSensor> { template<typename... Ts> class RunningCondition : public Condition<Ts...>, public Parented<DutyTimeSensor> {
@@ -67,7 +67,7 @@ template<typename... Ts> class RunningCondition : public Condition<Ts...>, publi
explicit RunningCondition(DutyTimeSensor *parent, bool state) : Parented(parent), state_(state) {} explicit RunningCondition(DutyTimeSensor *parent, bool state) : Parented(parent), state_(state) {}
protected: protected:
bool check(const Ts &...x) override { return this->parent_->is_running() == this->state_; } bool check(Ts... x) override { return this->parent_->is_running() == this->state_; }
bool state_; bool state_;
}; };

View File

@@ -3,9 +3,9 @@
namespace esphome { namespace esphome {
namespace es8388 { namespace es8388 {
void ADCInputMicSelect::control(size_t index) { void ADCInputMicSelect::control(const std::string &value) {
this->publish_state(index); this->publish_state(value);
this->parent_->set_adc_input_mic(static_cast<AdcInputMicLine>(index)); this->parent_->set_adc_input_mic(static_cast<AdcInputMicLine>(this->index_of(value).value()));
} }
} // namespace es8388 } // namespace es8388

View File

@@ -8,7 +8,7 @@ namespace es8388 {
class ADCInputMicSelect : public select::Select, public Parented<ES8388> { class ADCInputMicSelect : public select::Select, public Parented<ES8388> {
protected: protected:
void control(size_t index) override; void control(const std::string &value) override;
}; };
} // namespace es8388 } // namespace es8388

View File

@@ -3,9 +3,9 @@
namespace esphome { namespace esphome {
namespace es8388 { namespace es8388 {
void DacOutputSelect::control(size_t index) { void DacOutputSelect::control(const std::string &value) {
this->publish_state(index); this->publish_state(value);
this->parent_->set_dac_output(static_cast<DacOutputLine>(index)); this->parent_->set_dac_output(static_cast<DacOutputLine>(this->index_of(value).value()));
} }
} // namespace es8388 } // namespace es8388

View File

@@ -8,7 +8,7 @@ namespace es8388 {
class DacOutputSelect : public select::Select, public Parented<ES8388> { class DacOutputSelect : public select::Select, public Parented<ES8388> {
protected: protected:
void control(size_t index) override; void control(const std::string &value) override;
}; };
} // namespace es8388 } // namespace es8388

View File

@@ -214,17 +214,17 @@ extern ESP32BLE *global_ble;
template<typename... Ts> class BLEEnabledCondition : public Condition<Ts...> { template<typename... Ts> class BLEEnabledCondition : public Condition<Ts...> {
public: public:
bool check(const Ts &...x) override { return global_ble->is_active(); } bool check(Ts... x) override { return global_ble->is_active(); }
}; };
template<typename... Ts> class BLEEnableAction : public Action<Ts...> { template<typename... Ts> class BLEEnableAction : public Action<Ts...> {
public: public:
void play(const Ts &...x) override { global_ble->enable(); } void play(Ts... x) override { global_ble->enable(); }
}; };
template<typename... Ts> class BLEDisableAction : public Action<Ts...> { template<typename... Ts> class BLEDisableAction : public Action<Ts...> {
public: public:
void play(const Ts &...x) override { global_ble->disable(); } void play(Ts... x) override { global_ble->disable(); }
}; };
} // namespace esphome::esp32_ble } // namespace esphome::esp32_ble

View File

@@ -71,7 +71,7 @@ template<typename... Ts> class BLECharacteristicSetValueAction : public Action<T
BLECharacteristicSetValueAction(BLECharacteristic *characteristic) : parent_(characteristic) {} BLECharacteristicSetValueAction(BLECharacteristic *characteristic) : parent_(characteristic) {}
TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer) TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer)
void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); } void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); }
void play(const Ts &...x) override { void play(Ts... x) override {
// If the listener is already set, do nothing // If the listener is already set, do nothing
if (BLECharacteristicSetValueActionManager::get_instance()->has_listener(this->parent_)) if (BLECharacteristicSetValueActionManager::get_instance()->has_listener(this->parent_))
return; return;
@@ -96,7 +96,7 @@ template<typename... Ts> class BLECharacteristicSetValueAction : public Action<T
template<typename... Ts> class BLECharacteristicNotifyAction : public Action<Ts...> { template<typename... Ts> class BLECharacteristicNotifyAction : public Action<Ts...> {
public: public:
BLECharacteristicNotifyAction(BLECharacteristic *characteristic) : parent_(characteristic) {} BLECharacteristicNotifyAction(BLECharacteristic *characteristic) : parent_(characteristic) {}
void play(const Ts &...x) override { void play(Ts... x) override {
#ifdef USE_ESP32_BLE_SERVER_SET_VALUE_ACTION #ifdef USE_ESP32_BLE_SERVER_SET_VALUE_ACTION
// Call the pre-notify event // Call the pre-notify event
BLECharacteristicSetValueActionManager::get_instance()->emit_pre_notify(this->parent_); BLECharacteristicSetValueActionManager::get_instance()->emit_pre_notify(this->parent_);
@@ -116,7 +116,7 @@ template<typename... Ts> class BLEDescriptorSetValueAction : public Action<Ts...
BLEDescriptorSetValueAction(BLEDescriptor *descriptor) : parent_(descriptor) {} BLEDescriptorSetValueAction(BLEDescriptor *descriptor) : parent_(descriptor) {}
TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer) TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer)
void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); } void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); }
void play(const Ts &...x) override { this->parent_->set_value(this->buffer_.value(x...)); } void play(Ts... x) override { this->parent_->set_value(this->buffer_.value(x...)); }
protected: protected:
BLEDescriptor *parent_; BLEDescriptor *parent_;

View File

@@ -96,7 +96,7 @@ template<typename... Ts> class ESP32BLEStartScanAction : public Action<Ts...> {
public: public:
ESP32BLEStartScanAction(ESP32BLETracker *parent) : parent_(parent) {} ESP32BLEStartScanAction(ESP32BLETracker *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(bool, continuous) TEMPLATABLE_VALUE(bool, continuous)
void play(const Ts &...x) override { void play(Ts... x) override {
this->parent_->set_scan_continuous(this->continuous_.value(x...)); this->parent_->set_scan_continuous(this->continuous_.value(x...));
this->parent_->start_scan(); this->parent_->start_scan();
} }
@@ -107,7 +107,7 @@ template<typename... Ts> class ESP32BLEStartScanAction : public Action<Ts...> {
template<typename... Ts> class ESP32BLEStopScanAction : public Action<Ts...>, public Parented<ESP32BLETracker> { template<typename... Ts> class ESP32BLEStopScanAction : public Action<Ts...>, public Parented<ESP32BLETracker> {
public: public:
void play(const Ts &...x) override { this->parent_->stop_scan(); } void play(Ts... x) override { this->parent_->stop_scan(); }
}; };
} // namespace esphome::esp32_ble_tracker } // namespace esphome::esp32_ble_tracker

View File

@@ -40,7 +40,7 @@ template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
SetFrequencyAction(ESP8266PWM *parent) : parent_(parent) {} SetFrequencyAction(ESP8266PWM *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(float, frequency); TEMPLATABLE_VALUE(float, frequency);
void play(const Ts &...x) { void play(Ts... x) {
float freq = this->frequency_.value(x...); float freq = this->frequency_.value(x...);
this->parent_->update_frequency(freq); this->parent_->update_frequency(freq);
} }

View File

@@ -34,7 +34,7 @@ template<typename... Ts> class AdjustAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, voltage) TEMPLATABLE_VALUE(float, voltage)
void play(const Ts &...x) override { this->ldo_->adjust_voltage(this->voltage_.value(x...)); } void play(Ts... x) override { this->ldo_->adjust_voltage(this->voltage_.value(x...)); }
protected: protected:
EspLdo *ldo_; EspLdo *ldo_;

View File

@@ -36,7 +36,7 @@ template<typename... Ts> class SendAction : public Action<Ts...>, public Parente
void set_wait_for_sent(bool wait_for_sent) { this->flags_.wait_for_sent = wait_for_sent; } void set_wait_for_sent(bool wait_for_sent) { this->flags_.wait_for_sent = wait_for_sent; }
void set_continue_on_error(bool continue_on_error) { this->flags_.continue_on_error = continue_on_error; } void set_continue_on_error(bool continue_on_error) { this->flags_.continue_on_error = continue_on_error; }
void play_complex(const Ts &...x) override { void play_complex(Ts... x) override {
this->num_running_++; this->num_running_++;
send_callback_t send_callback = [this, x...](esp_err_t status) { send_callback_t send_callback = [this, x...](esp_err_t status) {
if (status == ESP_OK) { if (status == ESP_OK) {
@@ -67,7 +67,7 @@ template<typename... Ts> class SendAction : public Action<Ts...>, public Parente
} }
} }
void play(const Ts &...x) override { /* ignore - see play_complex */ void play(Ts... x) override { /* ignore - see play_complex */
} }
void stop() override { void stop() override {
@@ -90,7 +90,7 @@ template<typename... Ts> class AddPeerAction : public Action<Ts...>, public Pare
TEMPLATABLE_VALUE(peer_address_t, address); TEMPLATABLE_VALUE(peer_address_t, address);
public: public:
void play(const Ts &...x) override { void play(Ts... x) override {
peer_address_t address = this->address_.value(x...); peer_address_t address = this->address_.value(x...);
this->parent_->add_peer(address.data()); this->parent_->add_peer(address.data());
} }
@@ -100,7 +100,7 @@ template<typename... Ts> class DeletePeerAction : public Action<Ts...>, public P
TEMPLATABLE_VALUE(peer_address_t, address); TEMPLATABLE_VALUE(peer_address_t, address);
public: public:
void play(const Ts &...x) override { void play(Ts... x) override {
peer_address_t address = this->address_.value(x...); peer_address_t address = this->address_.value(x...);
this->parent_->del_peer(address.data()); this->parent_->del_peer(address.data());
} }
@@ -109,7 +109,7 @@ template<typename... Ts> class DeletePeerAction : public Action<Ts...>, public P
template<typename... Ts> class SetChannelAction : public Action<Ts...>, public Parented<ESPNowComponent> { template<typename... Ts> class SetChannelAction : public Action<Ts...>, public Parented<ESPNowComponent> {
public: public:
TEMPLATABLE_VALUE(uint8_t, channel) TEMPLATABLE_VALUE(uint8_t, channel)
void play(const Ts &...x) override { void play(Ts... x) override {
if (this->parent_->is_wifi_enabled()) { if (this->parent_->is_wifi_enabled()) {
return; return;
} }

View File

@@ -11,7 +11,7 @@ template<typename... Ts> class TriggerEventAction : public Action<Ts...>, public
public: public:
TEMPLATABLE_VALUE(std::string, event_type) TEMPLATABLE_VALUE(std::string, event_type)
void play(const Ts &...x) override { this->parent_->trigger(this->event_type_.value(x...)); } void play(Ts... x) override { this->parent_->trigger(this->event_type_.value(x...)); }
}; };
class EventTrigger : public Trigger<std::string> { class EventTrigger : public Trigger<std::string> {

View File

@@ -17,35 +17,35 @@ class LedTrigger : public Trigger<bool> {
class CustomTrigger : public Trigger<std::string> { class CustomTrigger : public Trigger<std::string> {
public: public:
explicit CustomTrigger(EZOSensor *ezo) { explicit CustomTrigger(EZOSensor *ezo) {
ezo->add_custom_callback([this](const std::string &value) { this->trigger(value); }); ezo->add_custom_callback([this](std::string value) { this->trigger(std::move(value)); });
} }
}; };
class TTrigger : public Trigger<std::string> { class TTrigger : public Trigger<std::string> {
public: public:
explicit TTrigger(EZOSensor *ezo) { explicit TTrigger(EZOSensor *ezo) {
ezo->add_t_callback([this](const std::string &value) { this->trigger(value); }); ezo->add_t_callback([this](std::string value) { this->trigger(std::move(value)); });
} }
}; };
class CalibrationTrigger : public Trigger<std::string> { class CalibrationTrigger : public Trigger<std::string> {
public: public:
explicit CalibrationTrigger(EZOSensor *ezo) { explicit CalibrationTrigger(EZOSensor *ezo) {
ezo->add_calibration_callback([this](const std::string &value) { this->trigger(value); }); ezo->add_calibration_callback([this](std::string value) { this->trigger(std::move(value)); });
} }
}; };
class SlopeTrigger : public Trigger<std::string> { class SlopeTrigger : public Trigger<std::string> {
public: public:
explicit SlopeTrigger(EZOSensor *ezo) { explicit SlopeTrigger(EZOSensor *ezo) {
ezo->add_slope_callback([this](const std::string &value) { this->trigger(value); }); ezo->add_slope_callback([this](std::string value) { this->trigger(std::move(value)); });
} }
}; };
class DeviceInformationTrigger : public Trigger<std::string> { class DeviceInformationTrigger : public Trigger<std::string> {
public: public:
explicit DeviceInformationTrigger(EZOSensor *ezo) { explicit DeviceInformationTrigger(EZOSensor *ezo) {
ezo->add_device_infomation_callback([this](const std::string &value) { this->trigger(value); }); ezo->add_device_infomation_callback([this](std::string value) { this->trigger(std::move(value)); });
} }
}; };

View File

@@ -119,7 +119,7 @@ template<typename... Ts> class EzoPMPFindAction : public Action<Ts...> {
public: public:
EzoPMPFindAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPFindAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->find(); } void play(Ts... x) override { this->ezopmp_->find(); }
protected: protected:
EzoPMP *ezopmp_; EzoPMP *ezopmp_;
@@ -129,7 +129,7 @@ template<typename... Ts> class EzoPMPDoseContinuouslyAction : public Action<Ts..
public: public:
EzoPMPDoseContinuouslyAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPDoseContinuouslyAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->dose_continuously(); } void play(Ts... x) override { this->ezopmp_->dose_continuously(); }
protected: protected:
EzoPMP *ezopmp_; EzoPMP *ezopmp_;
@@ -139,7 +139,7 @@ template<typename... Ts> class EzoPMPDoseVolumeAction : public Action<Ts...> {
public: public:
EzoPMPDoseVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPDoseVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->dose_volume(this->volume_.value(x...)); } void play(Ts... x) override { this->ezopmp_->dose_volume(this->volume_.value(x...)); }
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(double, volume)
protected: protected:
@@ -150,7 +150,7 @@ template<typename... Ts> class EzoPMPDoseVolumeOverTimeAction : public Action<Ts
public: public:
EzoPMPDoseVolumeOverTimeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPDoseVolumeOverTimeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { void play(Ts... x) override {
this->ezopmp_->dose_volume_over_time(this->volume_.value(x...), this->duration_.value(x...)); this->ezopmp_->dose_volume_over_time(this->volume_.value(x...), this->duration_.value(x...));
} }
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(double, volume)
@@ -164,7 +164,7 @@ template<typename... Ts> class EzoPMPDoseWithConstantFlowRateAction : public Act
public: public:
EzoPMPDoseWithConstantFlowRateAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPDoseWithConstantFlowRateAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { void play(Ts... x) override {
this->ezopmp_->dose_with_constant_flow_rate(this->volume_.value(x...), this->duration_.value(x...)); this->ezopmp_->dose_with_constant_flow_rate(this->volume_.value(x...), this->duration_.value(x...));
} }
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(double, volume)
@@ -178,7 +178,7 @@ template<typename... Ts> class EzoPMPSetCalibrationVolumeAction : public Action<
public: public:
EzoPMPSetCalibrationVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPSetCalibrationVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->set_calibration_volume(this->volume_.value(x...)); } void play(Ts... x) override { this->ezopmp_->set_calibration_volume(this->volume_.value(x...)); }
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(double, volume)
protected: protected:
@@ -189,7 +189,7 @@ template<typename... Ts> class EzoPMPClearTotalVolumeDispensedAction : public Ac
public: public:
EzoPMPClearTotalVolumeDispensedAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPClearTotalVolumeDispensedAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->clear_total_volume_dosed(); } void play(Ts... x) override { this->ezopmp_->clear_total_volume_dosed(); }
protected: protected:
EzoPMP *ezopmp_; EzoPMP *ezopmp_;
@@ -199,7 +199,7 @@ template<typename... Ts> class EzoPMPClearCalibrationAction : public Action<Ts..
public: public:
EzoPMPClearCalibrationAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPClearCalibrationAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->clear_calibration(); } void play(Ts... x) override { this->ezopmp_->clear_calibration(); }
protected: protected:
EzoPMP *ezopmp_; EzoPMP *ezopmp_;
@@ -209,7 +209,7 @@ template<typename... Ts> class EzoPMPPauseDosingAction : public Action<Ts...> {
public: public:
EzoPMPPauseDosingAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPPauseDosingAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->pause_dosing(); } void play(Ts... x) override { this->ezopmp_->pause_dosing(); }
protected: protected:
EzoPMP *ezopmp_; EzoPMP *ezopmp_;
@@ -219,7 +219,7 @@ template<typename... Ts> class EzoPMPStopDosingAction : public Action<Ts...> {
public: public:
EzoPMPStopDosingAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPStopDosingAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->stop_dosing(); } void play(Ts... x) override { this->ezopmp_->stop_dosing(); }
protected: protected:
EzoPMP *ezopmp_; EzoPMP *ezopmp_;
@@ -229,7 +229,7 @@ template<typename... Ts> class EzoPMPChangeI2CAddressAction : public Action<Ts..
public: public:
EzoPMPChangeI2CAddressAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPChangeI2CAddressAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->change_i2c_address(this->address_.value(x...)); } void play(Ts... x) override { this->ezopmp_->change_i2c_address(this->address_.value(x...)); }
TEMPLATABLE_VALUE(int, address) TEMPLATABLE_VALUE(int, address)
protected: protected:
@@ -240,7 +240,7 @@ template<typename... Ts> class EzoPMPArbitraryCommandAction : public Action<Ts..
public: public:
EzoPMPArbitraryCommandAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {} EzoPMPArbitraryCommandAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
void play(const Ts &...x) override { this->ezopmp_->exec_arbitrary_command(this->command_.value(x...)); } void play(Ts... x) override { this->ezopmp_->exec_arbitrary_command(this->command_.value(x...)); }
TEMPLATABLE_VALUE(std::string, command) TEMPLATABLE_VALUE(std::string, command)
protected: protected:

View File

@@ -15,7 +15,7 @@ template<typename... Ts> class TurnOnAction : public Action<Ts...> {
TEMPLATABLE_VALUE(int, speed) TEMPLATABLE_VALUE(int, speed)
TEMPLATABLE_VALUE(FanDirection, direction) TEMPLATABLE_VALUE(FanDirection, direction)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->state_->turn_on(); auto call = this->state_->turn_on();
if (this->oscillating_.has_value()) { if (this->oscillating_.has_value()) {
call.set_oscillating(this->oscillating_.value(x...)); call.set_oscillating(this->oscillating_.value(x...));
@@ -36,7 +36,7 @@ template<typename... Ts> class TurnOffAction : public Action<Ts...> {
public: public:
explicit TurnOffAction(Fan *state) : state_(state) {} explicit TurnOffAction(Fan *state) : state_(state) {}
void play(const Ts &...x) override { this->state_->turn_off().perform(); } void play(Ts... x) override { this->state_->turn_off().perform(); }
Fan *state_; Fan *state_;
}; };
@@ -45,7 +45,7 @@ template<typename... Ts> class ToggleAction : public Action<Ts...> {
public: public:
explicit ToggleAction(Fan *state) : state_(state) {} explicit ToggleAction(Fan *state) : state_(state) {}
void play(const Ts &...x) override { this->state_->toggle().perform(); } void play(Ts... x) override { this->state_->toggle().perform(); }
Fan *state_; Fan *state_;
}; };
@@ -56,7 +56,7 @@ template<typename... Ts> class CycleSpeedAction : public Action<Ts...> {
TEMPLATABLE_VALUE(bool, no_off_cycle) TEMPLATABLE_VALUE(bool, no_off_cycle)
void play(const Ts &...x) override { void play(Ts... x) override {
// check to see if fan supports speeds and is on // check to see if fan supports speeds and is on
if (this->state_->get_traits().supported_speed_count()) { if (this->state_->get_traits().supported_speed_count()) {
if (this->state_->state) { if (this->state_->state) {
@@ -97,7 +97,7 @@ template<typename... Ts> class CycleSpeedAction : public Action<Ts...> {
template<typename... Ts> class FanIsOnCondition : public Condition<Ts...> { template<typename... Ts> class FanIsOnCondition : public Condition<Ts...> {
public: public:
explicit FanIsOnCondition(Fan *state) : state_(state) {} explicit FanIsOnCondition(Fan *state) : state_(state) {}
bool check(const Ts &...x) override { return this->state_->state; } bool check(Ts... x) override { return this->state_->state; }
protected: protected:
Fan *state_; Fan *state_;
@@ -105,7 +105,7 @@ template<typename... Ts> class FanIsOnCondition : public Condition<Ts...> {
template<typename... Ts> class FanIsOffCondition : public Condition<Ts...> { template<typename... Ts> class FanIsOffCondition : public Condition<Ts...> {
public: public:
explicit FanIsOffCondition(Fan *state) : state_(state) {} explicit FanIsOffCondition(Fan *state) : state_(state) {}
bool check(const Ts &...x) override { return !this->state_->state; } bool check(Ts... x) override { return !this->state_->state; }
protected: protected:
Fan *state_; Fan *state_;

View File

@@ -273,7 +273,7 @@ template<typename... Ts> class EnrollmentAction : public Action<Ts...>, public P
TEMPLATABLE_VALUE(uint16_t, finger_id) TEMPLATABLE_VALUE(uint16_t, finger_id)
TEMPLATABLE_VALUE(uint8_t, num_scans) TEMPLATABLE_VALUE(uint8_t, num_scans)
void play(const Ts &...x) override { void play(Ts... x) override {
auto finger_id = this->finger_id_.value(x...); auto finger_id = this->finger_id_.value(x...);
auto num_scans = this->num_scans_.value(x...); auto num_scans = this->num_scans_.value(x...);
if (num_scans) { if (num_scans) {
@@ -287,14 +287,14 @@ template<typename... Ts> class EnrollmentAction : public Action<Ts...>, public P
template<typename... Ts> template<typename... Ts>
class CancelEnrollmentAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> { class CancelEnrollmentAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
public: public:
void play(const Ts &...x) override { this->parent_->finish_enrollment(1); } void play(Ts... x) override { this->parent_->finish_enrollment(1); }
}; };
template<typename... Ts> class DeleteAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> { template<typename... Ts> class DeleteAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
public: public:
TEMPLATABLE_VALUE(uint16_t, finger_id) TEMPLATABLE_VALUE(uint16_t, finger_id)
void play(const Ts &...x) override { void play(Ts... x) override {
auto finger_id = this->finger_id_.value(x...); auto finger_id = this->finger_id_.value(x...);
this->parent_->delete_fingerprint(finger_id); this->parent_->delete_fingerprint(finger_id);
} }
@@ -302,14 +302,14 @@ template<typename... Ts> class DeleteAction : public Action<Ts...>, public Paren
template<typename... Ts> class DeleteAllAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> { template<typename... Ts> class DeleteAllAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
public: public:
void play(const Ts &...x) override { this->parent_->delete_all_fingerprints(); } void play(Ts... x) override { this->parent_->delete_all_fingerprints(); }
}; };
template<typename... Ts> class LEDControlAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> { template<typename... Ts> class LEDControlAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
public: public:
TEMPLATABLE_VALUE(bool, state) TEMPLATABLE_VALUE(bool, state)
void play(const Ts &...x) override { void play(Ts... x) override {
auto state = this->state_.value(x...); auto state = this->state_.value(x...);
this->parent_->led_control(state); this->parent_->led_control(state);
} }
@@ -322,7 +322,7 @@ template<typename... Ts> class AuraLEDControlAction : public Action<Ts...>, publ
TEMPLATABLE_VALUE(uint8_t, color) TEMPLATABLE_VALUE(uint8_t, color)
TEMPLATABLE_VALUE(uint8_t, count) TEMPLATABLE_VALUE(uint8_t, count)
void play(const Ts &...x) override { void play(Ts... x) override {
auto state = this->state_.value(x...); auto state = this->state_.value(x...);
auto speed = this->speed_.value(x...); auto speed = this->speed_.value(x...);
auto color = this->color_.value(x...); auto color = this->color_.value(x...);

View File

@@ -62,6 +62,7 @@ void GDK101Component::dump_config() {
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
} }
#ifdef USE_SENSOR #ifdef USE_SENSOR
LOG_SENSOR(" ", "Firmware Version", this->fw_version_sensor_);
LOG_SENSOR(" ", "Average Radaition Dose per 1 minute", this->rad_1m_sensor_); LOG_SENSOR(" ", "Average Radaition Dose per 1 minute", this->rad_1m_sensor_);
LOG_SENSOR(" ", "Average Radaition Dose per 10 minutes", this->rad_10m_sensor_); LOG_SENSOR(" ", "Average Radaition Dose per 10 minutes", this->rad_10m_sensor_);
LOG_SENSOR(" ", "Status", this->status_sensor_); LOG_SENSOR(" ", "Status", this->status_sensor_);
@@ -71,10 +72,6 @@ void GDK101Component::dump_config() {
#ifdef USE_BINARY_SENSOR #ifdef USE_BINARY_SENSOR
LOG_BINARY_SENSOR(" ", "Vibration Status", this->vibration_binary_sensor_); LOG_BINARY_SENSOR(" ", "Vibration Status", this->vibration_binary_sensor_);
#endif // USE_BINARY_SENSOR #endif // USE_BINARY_SENSOR
#ifdef USE_TEXT_SENSOR
LOG_TEXT_SENSOR(" ", "Firmware Version", this->fw_version_text_sensor_);
#endif // USE_TEXT_SENSOR
} }
float GDK101Component::get_setup_priority() const { return setup_priority::DATA; } float GDK101Component::get_setup_priority() const { return setup_priority::DATA; }
@@ -156,18 +153,18 @@ bool GDK101Component::read_status_(uint8_t *data) {
} }
bool GDK101Component::read_fw_version_(uint8_t *data) { bool GDK101Component::read_fw_version_(uint8_t *data) {
#ifdef USE_TEXT_SENSOR #ifdef USE_SENSOR
if (this->fw_version_text_sensor_ != nullptr) { if (this->fw_version_sensor_ != nullptr) {
if (!this->read_bytes(GDK101_REG_READ_FIRMWARE, data, 2)) { if (!this->read_bytes(GDK101_REG_READ_FIRMWARE, data, 2)) {
ESP_LOGE(TAG, "Updating GDK101 failed!"); ESP_LOGE(TAG, "Updating GDK101 failed!");
return false; return false;
} }
const std::string fw_version_str = str_sprintf("%d.%d", data[0], data[1]); const float fw_version = data[0] + (data[1] / 10.0f);
this->fw_version_text_sensor_->publish_state(fw_version_str); this->fw_version_sensor_->publish_state(fw_version);
} }
#endif // USE_TEXT_SENSOR #endif // USE_SENSOR
return true; return true;
} }

View File

@@ -8,9 +8,6 @@
#ifdef USE_BINARY_SENSOR #ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
#endif // USE_BINARY_SENSOR #endif // USE_BINARY_SENSOR
#ifdef USE_TEXT_SENSOR
#include "esphome/components/text_sensor/text_sensor.h"
#endif // USE_TEXT_SENSOR
#include "esphome/components/i2c/i2c.h" #include "esphome/components/i2c/i2c.h"
namespace esphome { namespace esphome {
@@ -28,14 +25,12 @@ class GDK101Component : public PollingComponent, public i2c::I2CDevice {
SUB_SENSOR(rad_1m) SUB_SENSOR(rad_1m)
SUB_SENSOR(rad_10m) SUB_SENSOR(rad_10m)
SUB_SENSOR(status) SUB_SENSOR(status)
SUB_SENSOR(fw_version)
SUB_SENSOR(measurement_duration) SUB_SENSOR(measurement_duration)
#endif // USE_SENSOR #endif // USE_SENSOR
#ifdef USE_BINARY_SENSOR #ifdef USE_BINARY_SENSOR
SUB_BINARY_SENSOR(vibration) SUB_BINARY_SENSOR(vibration)
#endif // USE_BINARY_SENSOR #endif // USE_BINARY_SENSOR
#ifdef USE_TEXT_SENSOR
SUB_TEXT_SENSOR(fw_version)
#endif // USE_TEXT_SENSOR
public: public:
void setup() override; void setup() override;

View File

@@ -40,8 +40,9 @@ CONFIG_SCHEMA = cv.Schema(
device_class=DEVICE_CLASS_EMPTY, device_class=DEVICE_CLASS_EMPTY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_VERSION): cv.invalid( cv.Optional(CONF_VERSION): sensor.sensor_schema(
"The 'version' option has been moved to the `text_sensor` component." entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
accuracy_decimals=1,
), ),
cv.Optional(CONF_STATUS): sensor.sensor_schema( cv.Optional(CONF_STATUS): sensor.sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
@@ -70,6 +71,10 @@ async def to_code(config):
sens = await sensor.new_sensor(radiation_dose_per_10m) sens = await sensor.new_sensor(radiation_dose_per_10m)
cg.add(hub.set_rad_10m_sensor(sens)) cg.add(hub.set_rad_10m_sensor(sens))
if version_config := config.get(CONF_VERSION):
sens = await sensor.new_sensor(version_config)
cg.add(hub.set_fw_version_sensor(sens))
if status_config := config.get(CONF_STATUS): if status_config := config.get(CONF_STATUS):
sens = await sensor.new_sensor(status_config) sens = await sensor.new_sensor(status_config)
cg.add(hub.set_status_sensor(sens)) cg.add(hub.set_status_sensor(sens))

View File

@@ -1,23 +0,0 @@
import esphome.codegen as cg
from esphome.components import text_sensor
import esphome.config_validation as cv
from esphome.const import CONF_VERSION, ENTITY_CATEGORY_DIAGNOSTIC, ICON_CHIP
from . import CONF_GDK101_ID, GDK101Component
DEPENDENCIES = ["gdk101"]
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_GDK101_ID): cv.use_id(GDK101Component),
cv.Required(CONF_VERSION): text_sensor.text_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, icon=ICON_CHIP
),
}
)
async def to_code(config):
hub = await cg.get_variable(config[CONF_GDK101_ID])
var = await text_sensor.new_text_sensor(config[CONF_VERSION])
cg.add(hub.set_fw_version_text_sensor(var))

View File

@@ -134,7 +134,7 @@ template<class C, typename... Ts> class GlobalVarSetAction : public Action<Ts...
TEMPLATABLE_VALUE(T, value); TEMPLATABLE_VALUE(T, value);
void play(const Ts &...x) override { this->parent_->value() = this->value_.value(x...); } void play(Ts... x) override { this->parent_->value() = this->value_.value(x...); }
protected: protected:
C *parent_; C *parent_;

View File

@@ -235,7 +235,7 @@ void GraphLegend::init(Graph *g) {
std::string valstr = std::string valstr =
value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals()); value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals());
if (this->units_) { if (this->units_) {
valstr += trace->sensor_->get_unit_of_measurement_ref(); valstr += trace->sensor_->get_unit_of_measurement();
} }
this->font_value_->measure(valstr.c_str(), &fw, &fos, &fbl, &fh); this->font_value_->measure(valstr.c_str(), &fw, &fos, &fbl, &fh);
if (fw > valw) if (fw > valw)
@@ -371,7 +371,7 @@ void Graph::draw_legend(display::Display *buff, uint16_t x_offset, uint16_t y_of
std::string valstr = std::string valstr =
value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals()); value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals());
if (legend_->units_) { if (legend_->units_) {
valstr += trace->sensor_->get_unit_of_measurement_ref(); valstr += trace->sensor_->get_unit_of_measurement();
} }
buff->printf(xv, yv, legend_->font_value_, trace->get_line_color(), TextAlign::TOP_CENTER, "%s", valstr.c_str()); buff->printf(xv, yv, legend_->font_value_, trace->get_line_color(), TextAlign::TOP_CENTER, "%s", valstr.c_str());
ESP_LOGV(TAG, " value: %s", valstr.c_str()); ESP_LOGV(TAG, " value: %s", valstr.c_str());

View File

@@ -168,7 +168,7 @@ class GROVETB6612FNGMotorRunAction : public Action<Ts...>, public Parented<Grove
TEMPLATABLE_VALUE(uint8_t, channel) TEMPLATABLE_VALUE(uint8_t, channel)
TEMPLATABLE_VALUE(uint16_t, speed) TEMPLATABLE_VALUE(uint16_t, speed)
void play(const Ts &...x) override { void play(Ts... x) override {
auto channel = this->channel_.value(x...); auto channel = this->channel_.value(x...);
auto speed = this->speed_.value(x...); auto speed = this->speed_.value(x...);
this->parent_->dc_motor_run(channel, speed); this->parent_->dc_motor_run(channel, speed);
@@ -180,7 +180,7 @@ class GROVETB6612FNGMotorBrakeAction : public Action<Ts...>, public Parented<Gro
public: public:
TEMPLATABLE_VALUE(uint8_t, channel) TEMPLATABLE_VALUE(uint8_t, channel)
void play(const Ts &...x) override { this->parent_->dc_motor_brake(this->channel_.value(x...)); } void play(Ts... x) override { this->parent_->dc_motor_brake(this->channel_.value(x...)); }
}; };
template<typename... Ts> template<typename... Ts>
@@ -188,19 +188,19 @@ class GROVETB6612FNGMotorStopAction : public Action<Ts...>, public Parented<Grov
public: public:
TEMPLATABLE_VALUE(uint8_t, channel) TEMPLATABLE_VALUE(uint8_t, channel)
void play(const Ts &...x) override { this->parent_->dc_motor_stop(this->channel_.value(x...)); } void play(Ts... x) override { this->parent_->dc_motor_stop(this->channel_.value(x...)); }
}; };
template<typename... Ts> template<typename... Ts>
class GROVETB6612FNGMotorStandbyAction : public Action<Ts...>, public Parented<GroveMotorDriveTB6612FNG> { class GROVETB6612FNGMotorStandbyAction : public Action<Ts...>, public Parented<GroveMotorDriveTB6612FNG> {
public: public:
void play(const Ts &...x) override { this->parent_->standby(); } void play(Ts... x) override { this->parent_->standby(); }
}; };
template<typename... Ts> template<typename... Ts>
class GROVETB6612FNGMotorNoStandbyAction : public Action<Ts...>, public Parented<GroveMotorDriveTB6612FNG> { class GROVETB6612FNGMotorNoStandbyAction : public Action<Ts...>, public Parented<GroveMotorDriveTB6612FNG> {
public: public:
void play(const Ts &...x) override { this->parent_->not_standby(); } void play(Ts... x) override { this->parent_->not_standby(); }
}; };
template<typename... Ts> template<typename... Ts>
@@ -208,7 +208,7 @@ class GROVETB6612FNGMotorChangeAddressAction : public Action<Ts...>, public Pare
public: public:
TEMPLATABLE_VALUE(uint8_t, address) TEMPLATABLE_VALUE(uint8_t, address)
void play(const Ts &...x) override { this->parent_->set_i2c_addr(this->address_.value(x...)); } void play(Ts... x) override { this->parent_->set_i2c_addr(this->address_.value(x...)); }
}; };
} // namespace grove_tb6612fng } // namespace grove_tb6612fng

View File

@@ -10,7 +10,7 @@ namespace haier {
template<typename... Ts> class DisplayOnAction : public Action<Ts...> { template<typename... Ts> class DisplayOnAction : public Action<Ts...> {
public: public:
DisplayOnAction(HaierClimateBase *parent) : parent_(parent) {} DisplayOnAction(HaierClimateBase *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->set_display_state(true); } void play(Ts... x) { this->parent_->set_display_state(true); }
protected: protected:
HaierClimateBase *parent_; HaierClimateBase *parent_;
@@ -19,7 +19,7 @@ template<typename... Ts> class DisplayOnAction : public Action<Ts...> {
template<typename... Ts> class DisplayOffAction : public Action<Ts...> { template<typename... Ts> class DisplayOffAction : public Action<Ts...> {
public: public:
DisplayOffAction(HaierClimateBase *parent) : parent_(parent) {} DisplayOffAction(HaierClimateBase *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->set_display_state(false); } void play(Ts... x) { this->parent_->set_display_state(false); }
protected: protected:
HaierClimateBase *parent_; HaierClimateBase *parent_;
@@ -28,7 +28,7 @@ template<typename... Ts> class DisplayOffAction : public Action<Ts...> {
template<typename... Ts> class BeeperOnAction : public Action<Ts...> { template<typename... Ts> class BeeperOnAction : public Action<Ts...> {
public: public:
BeeperOnAction(HonClimate *parent) : parent_(parent) {} BeeperOnAction(HonClimate *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->set_beeper_state(true); } void play(Ts... x) { this->parent_->set_beeper_state(true); }
protected: protected:
HonClimate *parent_; HonClimate *parent_;
@@ -37,7 +37,7 @@ template<typename... Ts> class BeeperOnAction : public Action<Ts...> {
template<typename... Ts> class BeeperOffAction : public Action<Ts...> { template<typename... Ts> class BeeperOffAction : public Action<Ts...> {
public: public:
BeeperOffAction(HonClimate *parent) : parent_(parent) {} BeeperOffAction(HonClimate *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->set_beeper_state(false); } void play(Ts... x) { this->parent_->set_beeper_state(false); }
protected: protected:
HonClimate *parent_; HonClimate *parent_;
@@ -47,7 +47,7 @@ template<typename... Ts> class VerticalAirflowAction : public Action<Ts...> {
public: public:
VerticalAirflowAction(HonClimate *parent) : parent_(parent) {} VerticalAirflowAction(HonClimate *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(hon_protocol::VerticalSwingMode, direction) TEMPLATABLE_VALUE(hon_protocol::VerticalSwingMode, direction)
void play(const Ts &...x) { this->parent_->set_vertical_airflow(this->direction_.value(x...)); } void play(Ts... x) { this->parent_->set_vertical_airflow(this->direction_.value(x...)); }
protected: protected:
HonClimate *parent_; HonClimate *parent_;
@@ -57,7 +57,7 @@ template<typename... Ts> class HorizontalAirflowAction : public Action<Ts...> {
public: public:
HorizontalAirflowAction(HonClimate *parent) : parent_(parent) {} HorizontalAirflowAction(HonClimate *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(hon_protocol::HorizontalSwingMode, direction) TEMPLATABLE_VALUE(hon_protocol::HorizontalSwingMode, direction)
void play(const Ts &...x) { this->parent_->set_horizontal_airflow(this->direction_.value(x...)); } void play(Ts... x) { this->parent_->set_horizontal_airflow(this->direction_.value(x...)); }
protected: protected:
HonClimate *parent_; HonClimate *parent_;
@@ -66,7 +66,7 @@ template<typename... Ts> class HorizontalAirflowAction : public Action<Ts...> {
template<typename... Ts> class HealthOnAction : public Action<Ts...> { template<typename... Ts> class HealthOnAction : public Action<Ts...> {
public: public:
HealthOnAction(HaierClimateBase *parent) : parent_(parent) {} HealthOnAction(HaierClimateBase *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->set_health_mode(true); } void play(Ts... x) { this->parent_->set_health_mode(true); }
protected: protected:
HaierClimateBase *parent_; HaierClimateBase *parent_;
@@ -75,7 +75,7 @@ template<typename... Ts> class HealthOnAction : public Action<Ts...> {
template<typename... Ts> class HealthOffAction : public Action<Ts...> { template<typename... Ts> class HealthOffAction : public Action<Ts...> {
public: public:
HealthOffAction(HaierClimateBase *parent) : parent_(parent) {} HealthOffAction(HaierClimateBase *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->set_health_mode(false); } void play(Ts... x) { this->parent_->set_health_mode(false); }
protected: protected:
HaierClimateBase *parent_; HaierClimateBase *parent_;
@@ -84,7 +84,7 @@ template<typename... Ts> class HealthOffAction : public Action<Ts...> {
template<typename... Ts> class StartSelfCleaningAction : public Action<Ts...> { template<typename... Ts> class StartSelfCleaningAction : public Action<Ts...> {
public: public:
StartSelfCleaningAction(HonClimate *parent) : parent_(parent) {} StartSelfCleaningAction(HonClimate *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->start_self_cleaning(); } void play(Ts... x) { this->parent_->start_self_cleaning(); }
protected: protected:
HonClimate *parent_; HonClimate *parent_;
@@ -93,7 +93,7 @@ template<typename... Ts> class StartSelfCleaningAction : public Action<Ts...> {
template<typename... Ts> class StartSteriCleaningAction : public Action<Ts...> { template<typename... Ts> class StartSteriCleaningAction : public Action<Ts...> {
public: public:
StartSteriCleaningAction(HonClimate *parent) : parent_(parent) {} StartSteriCleaningAction(HonClimate *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->start_steri_cleaning(); } void play(Ts... x) { this->parent_->start_steri_cleaning(); }
protected: protected:
HonClimate *parent_; HonClimate *parent_;
@@ -102,7 +102,7 @@ template<typename... Ts> class StartSteriCleaningAction : public Action<Ts...> {
template<typename... Ts> class PowerOnAction : public Action<Ts...> { template<typename... Ts> class PowerOnAction : public Action<Ts...> {
public: public:
PowerOnAction(HaierClimateBase *parent) : parent_(parent) {} PowerOnAction(HaierClimateBase *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->send_power_on_command(); } void play(Ts... x) { this->parent_->send_power_on_command(); }
protected: protected:
HaierClimateBase *parent_; HaierClimateBase *parent_;
@@ -111,7 +111,7 @@ template<typename... Ts> class PowerOnAction : public Action<Ts...> {
template<typename... Ts> class PowerOffAction : public Action<Ts...> { template<typename... Ts> class PowerOffAction : public Action<Ts...> {
public: public:
PowerOffAction(HaierClimateBase *parent) : parent_(parent) {} PowerOffAction(HaierClimateBase *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->send_power_off_command(); } void play(Ts... x) { this->parent_->send_power_off_command(); }
protected: protected:
HaierClimateBase *parent_; HaierClimateBase *parent_;
@@ -120,7 +120,7 @@ template<typename... Ts> class PowerOffAction : public Action<Ts...> {
template<typename... Ts> class PowerToggleAction : public Action<Ts...> { template<typename... Ts> class PowerToggleAction : public Action<Ts...> {
public: public:
PowerToggleAction(HaierClimateBase *parent) : parent_(parent) {} PowerToggleAction(HaierClimateBase *parent) : parent_(parent) {}
void play(const Ts &...x) { this->parent_->toggle_power(); } void play(Ts... x) { this->parent_->toggle_power(); }
protected: protected:
HaierClimateBase *parent_; HaierClimateBase *parent_;

View File

@@ -49,7 +49,7 @@ template<typename... Ts> class BrakeAction : public Action<Ts...> {
public: public:
explicit BrakeAction(HBridgeFan *parent) : parent_(parent) {} explicit BrakeAction(HBridgeFan *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->brake(); } void play(Ts... x) override { this->parent_->brake(); }
HBridgeFan *parent_; HBridgeFan *parent_;
}; };

View File

@@ -113,8 +113,8 @@ class HttpContainer : public Parented<HttpRequestComponent> {
class HttpRequestResponseTrigger : public Trigger<std::shared_ptr<HttpContainer>, std::string &> { class HttpRequestResponseTrigger : public Trigger<std::shared_ptr<HttpContainer>, std::string &> {
public: public:
void process(const std::shared_ptr<HttpContainer> &container, std::string &response_body) { void process(std::shared_ptr<HttpContainer> container, std::string &response_body) {
this->trigger(container, response_body); this->trigger(std::move(container), response_body);
} }
}; };
@@ -210,7 +210,7 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
this->max_response_buffer_size_ = max_response_buffer_size; this->max_response_buffer_size_ = max_response_buffer_size;
} }
void play(const Ts &...x) override { void play(Ts... x) override {
std::string body; std::string body;
if (this->body_.has_value()) { if (this->body_.has_value()) {
body = this->body_.value(x...); body = this->body_.value(x...);

View File

@@ -15,7 +15,7 @@ template<typename... Ts> class OtaHttpRequestComponentFlashAction : public Actio
TEMPLATABLE_VALUE(std::string, url) TEMPLATABLE_VALUE(std::string, url)
TEMPLATABLE_VALUE(std::string, username) TEMPLATABLE_VALUE(std::string, username)
void play(const Ts &...x) override { void play(Ts... x) override {
if (this->md5_url_.has_value()) { if (this->md5_url_.has_value()) {
this->parent_->set_md5_url(this->md5_url_.value(x...)); this->parent_->set_md5_url(this->md5_url_.value(x...));
} }

View File

@@ -41,7 +41,7 @@ template<typename... Ts> class SetHeaterLevelAction : public Action<Ts...>, publ
public: public:
TEMPLATABLE_VALUE(uint8_t, level) TEMPLATABLE_VALUE(uint8_t, level)
void play(const Ts &...x) override { void play(Ts... x) override {
auto level = this->level_.value(x...); auto level = this->level_.value(x...);
this->parent_->set_heater_level(level); this->parent_->set_heater_level(level);
@@ -52,7 +52,7 @@ template<typename... Ts> class SetHeaterAction : public Action<Ts...>, public Pa
public: public:
TEMPLATABLE_VALUE(bool, status) TEMPLATABLE_VALUE(bool, status)
void play(const Ts &...x) override { void play(Ts... x) override {
auto status = this->status_.value(x...); auto status = this->status_.value(x...);
this->parent_->set_heater(status); this->parent_->set_heater(status);

View File

@@ -75,7 +75,7 @@ template<typename... Ts> class ResetAction : public Action<Ts...> {
public: public:
explicit ResetAction(IntegrationSensor *parent) : parent_(parent) {} explicit ResetAction(IntegrationSensor *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->reset(); } void play(Ts... x) override { this->parent_->reset(); }
protected: protected:
IntegrationSensor *parent_; IntegrationSensor *parent_;

View File

@@ -52,11 +52,11 @@ class KeyCollector : public Component {
}; };
template<typename... Ts> class EnableAction : public Action<Ts...>, public Parented<KeyCollector> { template<typename... Ts> class EnableAction : public Action<Ts...>, public Parented<KeyCollector> {
void play(const Ts &...x) override { this->parent_->set_enabled(true); } void play(Ts... x) override { this->parent_->set_enabled(true); }
}; };
template<typename... Ts> class DisableAction : public Action<Ts...>, public Parented<KeyCollector> { template<typename... Ts> class DisableAction : public Action<Ts...>, public Parented<KeyCollector> {
void play(const Ts &...x) override { this->parent_->set_enabled(false); } void play(Ts... x) override { this->parent_->set_enabled(false); }
}; };
} // namespace key_collector } // namespace key_collector

View File

@@ -12,7 +12,7 @@ template<typename... Ts> class BluetoothPasswordSetAction : public Action<Ts...>
explicit BluetoothPasswordSetAction(LD2410Component *ld2410_comp) : ld2410_comp_(ld2410_comp) {} explicit BluetoothPasswordSetAction(LD2410Component *ld2410_comp) : ld2410_comp_(ld2410_comp) {}
TEMPLATABLE_VALUE(std::string, password) TEMPLATABLE_VALUE(std::string, password)
void play(const Ts &...x) override { this->ld2410_comp_->set_bluetooth_password(this->password_.value(x...)); } void play(Ts... x) override { this->ld2410_comp_->set_bluetooth_password(this->password_.value(x...)); }
protected: protected:
LD2410Component *ld2410_comp_; LD2410Component *ld2410_comp_;

View File

@@ -174,7 +174,7 @@ static uint8_t calc_checksum(void *data, size_t size) {
static int get_firmware_int(const char *version_string) { static int get_firmware_int(const char *version_string) {
std::string version_str = version_string; std::string version_str = version_string;
if (version_str[0] == 'v') { if (version_str[0] == 'v') {
version_str.erase(0, 1); version_str = version_str.substr(1);
} }
version_str.erase(remove(version_str.begin(), version_str.end(), '.'), version_str.end()); version_str.erase(remove(version_str.begin(), version_str.end(), '.'), version_str.end());
int version_integer = stoi(version_str); int version_integer = stoi(version_str);

View File

@@ -47,7 +47,7 @@ template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
SetFrequencyAction(LEDCOutput *parent) : parent_(parent) {} SetFrequencyAction(LEDCOutput *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(float, frequency); TEMPLATABLE_VALUE(float, frequency);
void play(const Ts &...x) { void play(Ts... x) {
float freq = this->frequency_.value(x...); float freq = this->frequency_.value(x...);
this->parent_->update_frequency(freq); this->parent_->update_frequency(freq);
} }

View File

@@ -40,7 +40,7 @@ template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
SetFrequencyAction(LibreTinyPWM *parent) : parent_(parent) {} SetFrequencyAction(LibreTinyPWM *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(float, frequency); TEMPLATABLE_VALUE(float, frequency);
void play(const Ts &...x) { void play(Ts... x) {
float freq = this->frequency_.value(x...); float freq = this->frequency_.value(x...);
this->parent_->update_frequency(freq); this->parent_->update_frequency(freq);
} }

View File

@@ -15,7 +15,7 @@ template<typename... Ts> class ToggleAction : public Action<Ts...> {
TEMPLATABLE_VALUE(uint32_t, transition_length) TEMPLATABLE_VALUE(uint32_t, transition_length)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->state_->toggle(); auto call = this->state_->toggle();
call.set_transition_length(this->transition_length_.optional_value(x...)); call.set_transition_length(this->transition_length_.optional_value(x...));
call.perform(); call.perform();
@@ -44,7 +44,7 @@ template<typename... Ts> class LightControlAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, warm_white) TEMPLATABLE_VALUE(float, warm_white)
TEMPLATABLE_VALUE(std::string, effect) TEMPLATABLE_VALUE(std::string, effect)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->parent_->make_call(); auto call = this->parent_->make_call();
call.set_color_mode(this->color_mode_.optional_value(x...)); call.set_color_mode(this->color_mode_.optional_value(x...));
call.set_state(this->state_.optional_value(x...)); call.set_state(this->state_.optional_value(x...));
@@ -74,7 +74,7 @@ template<typename... Ts> class DimRelativeAction : public Action<Ts...> {
TEMPLATABLE_VALUE(float, relative_brightness) TEMPLATABLE_VALUE(float, relative_brightness)
TEMPLATABLE_VALUE(uint32_t, transition_length) TEMPLATABLE_VALUE(uint32_t, transition_length)
void play(const Ts &...x) override { void play(Ts... x) override {
auto call = this->parent_->make_call(); auto call = this->parent_->make_call();
float rel = this->relative_brightness_.value(x...); float rel = this->relative_brightness_.value(x...);
float cur; float cur;
@@ -107,7 +107,7 @@ template<typename... Ts> class DimRelativeAction : public Action<Ts...> {
template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> { template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> {
public: public:
explicit LightIsOnCondition(LightState *state) : state_(state) {} explicit LightIsOnCondition(LightState *state) : state_(state) {}
bool check(const Ts &...x) override { return this->state_->current_values.is_on(); } bool check(Ts... x) override { return this->state_->current_values.is_on(); }
protected: protected:
LightState *state_; LightState *state_;
@@ -115,7 +115,7 @@ template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> {
template<typename... Ts> class LightIsOffCondition : public Condition<Ts...> { template<typename... Ts> class LightIsOffCondition : public Condition<Ts...> {
public: public:
explicit LightIsOffCondition(LightState *state) : state_(state) {} explicit LightIsOffCondition(LightState *state) : state_(state) {}
bool check(const Ts &...x) override { return !this->state_->current_values.is_on(); } bool check(Ts... x) override { return !this->state_->current_values.is_on(); }
protected: protected:
LightState *state_; LightState *state_;
@@ -179,7 +179,7 @@ template<typename... Ts> class AddressableSet : public Action<Ts...> {
TEMPLATABLE_VALUE(float, blue) TEMPLATABLE_VALUE(float, blue)
TEMPLATABLE_VALUE(float, white) TEMPLATABLE_VALUE(float, white)
void play(const Ts &...x) override { void play(Ts... x) override {
auto *out = (AddressableLight *) this->parent_->get_output(); auto *out = (AddressableLight *) this->parent_->get_output();
int32_t range_from = interpret_index(this->range_from_.value_or(x..., 0), out->size()); int32_t range_from = interpret_index(this->range_from_.value_or(x..., 0), out->size());
if (range_from < 0 || range_from >= out->size()) if (range_from < 0 || range_from >= out->size())

View File

@@ -51,7 +51,7 @@ template<typename... Ts> class SendRawAction : public Action<Ts...> {
void set_pulse_length(const int &data) { pulse_length_ = data; } void set_pulse_length(const int &data) { pulse_length_ = data; }
void set_data(const std::vector<uint8_t> &data) { code_ = data; } void set_data(const std::vector<uint8_t> &data) { code_ = data; }
void play(const Ts &...x) { void play(Ts... x) {
int repeats = this->repeat_.value(x...); int repeats = this->repeat_.value(x...);
int inverted = this->inverted_.value(x...); int inverted = this->inverted_.value(x...);
int pulse_length = this->pulse_length_.value(x...); int pulse_length = this->pulse_length_.value(x...);

View File

@@ -11,7 +11,7 @@ template<typename... Ts> class LockAction : public Action<Ts...> {
public: public:
explicit LockAction(Lock *a_lock) : lock_(a_lock) {} explicit LockAction(Lock *a_lock) : lock_(a_lock) {}
void play(const Ts &...x) override { this->lock_->lock(); } void play(Ts... x) override { this->lock_->lock(); }
protected: protected:
Lock *lock_; Lock *lock_;
@@ -21,7 +21,7 @@ template<typename... Ts> class UnlockAction : public Action<Ts...> {
public: public:
explicit UnlockAction(Lock *a_lock) : lock_(a_lock) {} explicit UnlockAction(Lock *a_lock) : lock_(a_lock) {}
void play(const Ts &...x) override { this->lock_->unlock(); } void play(Ts... x) override { this->lock_->unlock(); }
protected: protected:
Lock *lock_; Lock *lock_;
@@ -31,7 +31,7 @@ template<typename... Ts> class OpenAction : public Action<Ts...> {
public: public:
explicit OpenAction(Lock *a_lock) : lock_(a_lock) {} explicit OpenAction(Lock *a_lock) : lock_(a_lock) {}
void play(const Ts &...x) override { this->lock_->open(); } void play(Ts... x) override { this->lock_->open(); }
protected: protected:
Lock *lock_; Lock *lock_;
@@ -40,7 +40,7 @@ template<typename... Ts> class OpenAction : public Action<Ts...> {
template<typename... Ts> class LockCondition : public Condition<Ts...> { template<typename... Ts> class LockCondition : public Condition<Ts...> {
public: public:
LockCondition(Lock *parent, bool state) : parent_(parent), state_(state) {} LockCondition(Lock *parent, bool state) : parent_(parent), state_(state) {}
bool check(const Ts &...x) override { bool check(Ts... x) override {
auto check_state = this->state_ ? LockState::LOCK_STATE_LOCKED : LockState::LOCK_STATE_UNLOCKED; auto check_state = this->state_ ? LockState::LOCK_STATE_LOCKED : LockState::LOCK_STATE_UNLOCKED;
return this->parent_->state == check_state; return this->parent_->state == check_state;
} }

View File

@@ -3,8 +3,6 @@ import re
from esphome import config_validation as cv from esphome import config_validation as cv
from esphome.const import CONF_ARGS, CONF_FORMAT from esphome.const import CONF_ARGS, CONF_FORMAT
CONF_IF_NAN = "if_nan"
lv_uses = { lv_uses = {
"USER_DATA", "USER_DATA",
"LOG", "LOG",
@@ -23,48 +21,23 @@ lv_fonts_used = set()
esphome_fonts_used = set() esphome_fonts_used = set()
lvgl_components_required = set() lvgl_components_required = set()
# noqa
f_regex = re.compile( def validate_printf(value):
r""" cfmt = r"""
( # start of capture group 1 ( # start of capture group 1
% # literal "%" % # literal "%"
[-+0 #]{0,5} # optional flags (?:[-+0 #]{0,5}) # optional flags
(?:\d+|\*)? # width
(?:\.(?:\d+|\*))? # precision
(?:h|l|ll|w|I|I32|I64)? # size
f # type
)
""",
flags=re.VERBOSE,
)
# noqa
c_regex = re.compile(
r"""
( # start of capture group 1
% # literal "%"
[-+0 #]{0,5} # optional flags
(?:\d+|\*)? # width (?:\d+|\*)? # width
(?:\.(?:\d+|\*))? # precision (?:\.(?:\d+|\*))? # precision
(?:h|l|ll|w|I|I32|I64)? # size (?:h|l|ll|w|I|I32|I64)? # size
[cCdiouxXeEfgGaAnpsSZ] # type [cCdiouxXeEfgGaAnpsSZ] # type
) )
""", """ # noqa
flags=re.VERBOSE, matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.VERBOSE)
)
def validate_printf(value):
format_string = value[CONF_FORMAT]
matches = c_regex.findall(format_string)
if len(matches) != len(value[CONF_ARGS]): if len(matches) != len(value[CONF_ARGS]):
raise cv.Invalid( raise cv.Invalid(
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!" f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"
) )
if value.get(CONF_IF_NAN) and len(f_regex.findall(format_string)) != 1:
raise cv.Invalid(
"Use of 'if_nan' requires a single valid printf-pattern of type %f"
)
return value return value

View File

@@ -33,13 +33,7 @@ from .defines import (
call_lambda, call_lambda,
literal, literal,
) )
from .helpers import ( from .helpers import add_lv_use, esphome_fonts_used, lv_fonts_used, requires_component
CONF_IF_NAN,
add_lv_use,
esphome_fonts_used,
lv_fonts_used,
requires_component,
)
from .types import lv_font_t, lv_gradient_t from .types import lv_font_t, lv_gradient_t
opacity_consts = LvConstant("LV_OPA_", "TRANSP", "COVER") opacity_consts = LvConstant("LV_OPA_", "TRANSP", "COVER")
@@ -418,13 +412,7 @@ class TextValidator(LValidator):
str_args = [str(x) for x in value[CONF_ARGS]] str_args = [str(x) for x in value[CONF_ARGS]]
arg_expr = cg.RawExpression(",".join(str_args)) arg_expr = cg.RawExpression(",".join(str_args))
format_str = cpp_string_escape(format_str) format_str = cpp_string_escape(format_str)
sprintf_str = f"str_sprintf({format_str}, {arg_expr}).c_str()" return literal(f"str_sprintf({format_str}, {arg_expr}).c_str()")
if nanval := value.get(CONF_IF_NAN):
nanval = cpp_string_escape(nanval)
return literal(
f"(std::isfinite({arg_expr}) ? {sprintf_str} : {nanval})"
)
return literal(sprintf_str)
if time_format := value.get(CONF_TIME_FORMAT): if time_format := value.get(CONF_TIME_FORMAT):
source = value[CONF_TIME] source = value[CONF_TIME]
if isinstance(source, Lambda): if isinstance(source, Lambda):

View File

@@ -129,7 +129,7 @@ template<typename... Ts> class ObjUpdateAction : public Action<Ts...> {
public: public:
explicit ObjUpdateAction(std::function<void(Ts...)> &&lamb) : lamb_(std::move(lamb)) {} explicit ObjUpdateAction(std::function<void(Ts...)> &&lamb) : lamb_(std::move(lamb)) {}
void play(const Ts &...x) override { this->lamb_(x...); } void play(Ts... x) override { this->lamb_(x...); }
protected: protected:
std::function<void(Ts...)> lamb_; std::function<void(Ts...)> lamb_;
@@ -263,7 +263,7 @@ class IdleTrigger : public Trigger<> {
template<typename... Ts> class LvglAction : public Action<Ts...>, public Parented<LvglComponent> { template<typename... Ts> class LvglAction : public Action<Ts...>, public Parented<LvglComponent> {
public: public:
explicit LvglAction(std::function<void(LvglComponent *)> &&lamb) : action_(std::move(lamb)) {} explicit LvglAction(std::function<void(LvglComponent *)> &&lamb) : action_(std::move(lamb)) {}
void play(const Ts &...x) override { this->action_(this->parent_); } void play(Ts... x) override { this->action_(this->parent_); }
protected: protected:
std::function<void(LvglComponent *)> action_{}; std::function<void(LvglComponent *)> action_{};
@@ -272,7 +272,7 @@ template<typename... Ts> class LvglAction : public Action<Ts...>, public Parente
template<typename Tc, typename... Ts> class LvglCondition : public Condition<Ts...>, public Parented<Tc> { template<typename Tc, typename... Ts> class LvglCondition : public Condition<Ts...>, public Parented<Tc> {
public: public:
LvglCondition(std::function<bool(Tc *)> &&condition_lambda) : condition_lambda_(std::move(condition_lambda)) {} LvglCondition(std::function<bool(Tc *)> &&condition_lambda) : condition_lambda_(std::move(condition_lambda)) {}
bool check(const Ts &...x) override { return this->condition_lambda_(this->parent_); } bool check(Ts... x) override { return this->condition_lambda_(this->parent_); }
protected: protected:
std::function<bool(Tc *)> condition_lambda_{}; std::function<bool(Tc *)> condition_lambda_{};

View File

@@ -20,7 +20,7 @@ from esphome.core.config import StartupTrigger
from . import defines as df, lv_validation as lvalid from . import defines as df, lv_validation as lvalid
from .defines import CONF_TIME_FORMAT, LV_GRAD_DIR from .defines import CONF_TIME_FORMAT, LV_GRAD_DIR
from .helpers import CONF_IF_NAN, requires_component, validate_printf from .helpers import requires_component, validate_printf
from .layout import ( from .layout import (
FLEX_OBJ_SCHEMA, FLEX_OBJ_SCHEMA,
GRID_CELL_SCHEMA, GRID_CELL_SCHEMA,
@@ -54,7 +54,6 @@ PRINTF_TEXT_SCHEMA = cv.All(
{ {
cv.Required(CONF_FORMAT): cv.string, cv.Required(CONF_FORMAT): cv.string,
cv.Optional(CONF_ARGS, default=list): cv.ensure_list(cv.lambda_), cv.Optional(CONF_ARGS, default=list): cv.ensure_list(cv.lambda_),
cv.Optional(CONF_IF_NAN): cv.string,
}, },
), ),
validate_printf, validate_printf,

View File

@@ -41,16 +41,16 @@ class LVGLSelect : public select::Select, public Component {
} }
void publish() { void publish() {
auto index = this->widget_->get_selected_index(); this->publish_state(this->widget_->get_selected_text());
this->publish_state(index);
if (this->restore_) { if (this->restore_) {
auto index = this->widget_->get_selected_index();
this->pref_.save(&index); this->pref_.save(&index);
} }
} }
protected: protected:
void control(size_t index) override { void control(const std::string &value) override {
this->widget_->set_selected_index(index, this->anim_); this->widget_->set_selected_text(value, this->anim_);
this->publish(); this->publish();
} }
void set_options_() { void set_options_() {
@@ -59,8 +59,8 @@ class LVGLSelect : public select::Select, public Component {
const auto &opts = this->widget_->get_options(); const auto &opts = this->widget_->get_options();
FixedVector<const char *> opt_ptrs; FixedVector<const char *> opt_ptrs;
opt_ptrs.init(opts.size()); opt_ptrs.init(opts.size());
for (const auto &opt : opts) { for (size_t i = 0; i < opts.size(); i++) {
opt_ptrs.push_back(opt.c_str()); opt_ptrs[i] = opts[i].c_str();
} }
this->traits.set_options(opt_ptrs); this->traits.set_options(opt_ptrs);
} }

View File

@@ -10,7 +10,7 @@ template<typename... Ts> class SleepAction : public Action<Ts...> {
public: public:
explicit SleepAction(MAX17043Component *max17043) : max17043_(max17043) {} explicit SleepAction(MAX17043Component *max17043) : max17043_(max17043) {}
void play(const Ts &...x) override { this->max17043_->sleep_mode(); } void play(Ts... x) override { this->max17043_->sleep_mode(); }
protected: protected:
MAX17043Component *max17043_; MAX17043Component *max17043_;

View File

@@ -13,7 +13,7 @@ template<typename... Ts> class SetCurrentGlobalAction : public Action<Ts...> {
TEMPLATABLE_VALUE(uint8_t, brightness_global) TEMPLATABLE_VALUE(uint8_t, brightness_global)
void play(const Ts &...x) override { void play(Ts... x) override {
this->max6956_->set_brightness_global(this->brightness_global_.value(x...)); this->max6956_->set_brightness_global(this->brightness_global_.value(x...));
this->max6956_->write_brightness_global(); this->max6956_->write_brightness_global();
} }
@@ -28,7 +28,7 @@ template<typename... Ts> class SetCurrentModeAction : public Action<Ts...> {
TEMPLATABLE_VALUE(max6956::MAX6956CURRENTMODE, brightness_mode) TEMPLATABLE_VALUE(max6956::MAX6956CURRENTMODE, brightness_mode)
void play(const Ts &...x) override { void play(Ts... x) override {
this->max6956_->set_brightness_mode(this->brightness_mode_.value(x...)); this->max6956_->set_brightness_mode(this->brightness_mode_.value(x...));
this->max6956_->write_brightness_mode(); this->max6956_->write_brightness_mode();
} }

View File

@@ -12,7 +12,7 @@ template<typename... Ts> class DisplayInvertAction : public Action<Ts...>, publi
public: public:
TEMPLATABLE_VALUE(bool, state) TEMPLATABLE_VALUE(bool, state)
void play(const Ts &...x) override { void play(Ts... x) override {
bool state = this->state_.value(x...); bool state = this->state_.value(x...);
this->parent_->invert_on_off(state); this->parent_->invert_on_off(state);
} }
@@ -22,7 +22,7 @@ template<typename... Ts> class DisplayVisibilityAction : public Action<Ts...>, p
public: public:
TEMPLATABLE_VALUE(bool, state) TEMPLATABLE_VALUE(bool, state)
void play(const Ts &...x) override { void play(Ts... x) override {
bool state = this->state_.value(x...); bool state = this->state_.value(x...);
this->parent_->turn_on_off(state); this->parent_->turn_on_off(state);
} }
@@ -32,7 +32,7 @@ template<typename... Ts> class DisplayReverseAction : public Action<Ts...>, publ
public: public:
TEMPLATABLE_VALUE(bool, state) TEMPLATABLE_VALUE(bool, state)
void play(const Ts &...x) override { void play(Ts... x) override {
bool state = this->state_.value(x...); bool state = this->state_.value(x...);
this->parent_->set_reverse(state); this->parent_->set_reverse(state);
} }
@@ -42,7 +42,7 @@ template<typename... Ts> class DisplayIntensityAction : public Action<Ts...>, pu
public: public:
TEMPLATABLE_VALUE(uint8_t, state) TEMPLATABLE_VALUE(uint8_t, state)
void play(const Ts &...x) override { void play(Ts... x) override {
uint8_t state = this->state_.value(x...); uint8_t state = this->state_.value(x...);
this->parent_->set_intensity(state); this->parent_->set_intensity(state);
} }

View File

@@ -37,6 +37,8 @@ MDNS_STATIC_CONST_CHAR(SERVICE_TCP, "_tcp");
MDNS_STATIC_CONST_CHAR(VALUE_VERSION, ESPHOME_VERSION); MDNS_STATIC_CONST_CHAR(VALUE_VERSION, ESPHOME_VERSION);
void MDNSComponent::compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services) { void MDNSComponent::compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services) {
this->hostname_ = App.get_name();
// IMPORTANT: The #ifdef blocks below must match COMPONENTS_WITH_MDNS_SERVICES // IMPORTANT: The #ifdef blocks below must match COMPONENTS_WITH_MDNS_SERVICES
// in mdns/__init__.py. If you add a new service here, update both locations. // in mdns/__init__.py. If you add a new service here, update both locations.
@@ -177,7 +179,7 @@ void MDNSComponent::dump_config() {
ESP_LOGCONFIG(TAG, ESP_LOGCONFIG(TAG,
"mDNS:\n" "mDNS:\n"
" Hostname: %s", " Hostname: %s",
App.get_name().c_str()); this->hostname_.c_str());
#ifdef USE_MDNS_STORE_SERVICES #ifdef USE_MDNS_STORE_SERVICES
ESP_LOGV(TAG, " Services:"); ESP_LOGV(TAG, " Services:");
for (const auto &service : this->services_) { for (const auto &service : this->services_) {

View File

@@ -76,6 +76,7 @@ class MDNSComponent : public Component {
#ifdef USE_MDNS_STORE_SERVICES #ifdef USE_MDNS_STORE_SERVICES
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services_{}; StaticVector<MDNSService, MDNS_SERVICE_COUNT> services_{};
#endif #endif
std::string hostname_;
void compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services); void compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services);
}; };

View File

@@ -2,7 +2,6 @@
#if defined(USE_ESP32) && defined(USE_MDNS) #if defined(USE_ESP32) && defined(USE_MDNS)
#include <mdns.h> #include <mdns.h>
#include "esphome/core/application.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "mdns_component.h" #include "mdns_component.h"
@@ -28,9 +27,8 @@ void MDNSComponent::setup() {
return; return;
} }
const char *hostname = App.get_name().c_str(); mdns_hostname_set(this->hostname_.c_str());
mdns_hostname_set(hostname); mdns_instance_name_set(this->hostname_.c_str());
mdns_instance_name_set(hostname);
for (const auto &service : services) { for (const auto &service : services) {
auto txt_records = std::make_unique<mdns_txt_item_t[]>(service.txt_records.size()); auto txt_records = std::make_unique<mdns_txt_item_t[]>(service.txt_records.size());

View File

@@ -4,7 +4,6 @@
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#include "esphome/components/network/ip_address.h" #include "esphome/components/network/ip_address.h"
#include "esphome/components/network/util.h" #include "esphome/components/network/util.h"
#include "esphome/core/application.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "mdns_component.h" #include "mdns_component.h"
@@ -21,7 +20,7 @@ void MDNSComponent::setup() {
this->compile_records_(services); this->compile_records_(services);
#endif #endif
MDNS.begin(App.get_name().c_str()); MDNS.begin(this->hostname_.c_str());
for (const auto &service : services) { for (const auto &service : services) {
// Strip the leading underscore from the proto and service_type. While it is // Strip the leading underscore from the proto and service_type. While it is

View File

@@ -3,7 +3,6 @@
#include "esphome/components/network/ip_address.h" #include "esphome/components/network/ip_address.h"
#include "esphome/components/network/util.h" #include "esphome/components/network/util.h"
#include "esphome/core/application.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "mdns_component.h" #include "mdns_component.h"
@@ -21,7 +20,7 @@ void MDNSComponent::setup() {
this->compile_records_(services); this->compile_records_(services);
#endif #endif
MDNS.begin(App.get_name().c_str()); MDNS.begin(this->hostname_.c_str());
for (const auto &service : services) { for (const auto &service : services) {
// Strip the leading underscore from the proto and service_type. While it is // Strip the leading underscore from the proto and service_type. While it is

View File

@@ -3,7 +3,6 @@
#include "esphome/components/network/ip_address.h" #include "esphome/components/network/ip_address.h"
#include "esphome/components/network/util.h" #include "esphome/components/network/util.h"
#include "esphome/core/application.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "mdns_component.h" #include "mdns_component.h"
@@ -21,7 +20,7 @@ void MDNSComponent::setup() {
this->compile_records_(services); this->compile_records_(services);
#endif #endif
MDNS.begin(App.get_name().c_str()); MDNS.begin(this->hostname_.c_str());
for (const auto &service : services) { for (const auto &service : services) {
// Strip the leading underscore from the proto and service_type. While it is // Strip the leading underscore from the proto and service_type. While it is

View File

@@ -11,7 +11,7 @@ template<MediaPlayerCommand Command, typename... Ts>
class MediaPlayerCommandAction : public Action<Ts...>, public Parented<MediaPlayer> { class MediaPlayerCommandAction : public Action<Ts...>, public Parented<MediaPlayer> {
public: public:
TEMPLATABLE_VALUE(bool, announcement); TEMPLATABLE_VALUE(bool, announcement);
void play(const Ts &...x) override { void play(Ts... x) override {
this->parent_->make_call().set_command(Command).set_announcement(this->announcement_.value(x...)).perform(); this->parent_->make_call().set_command(Command).set_announcement(this->announcement_.value(x...)).perform();
} }
}; };
@@ -36,7 +36,7 @@ using TurnOffAction = MediaPlayerCommandAction<MediaPlayerCommand::MEDIA_PLAYER_
template<typename... Ts> class PlayMediaAction : public Action<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class PlayMediaAction : public Action<Ts...>, public Parented<MediaPlayer> {
TEMPLATABLE_VALUE(std::string, media_url) TEMPLATABLE_VALUE(std::string, media_url)
TEMPLATABLE_VALUE(bool, announcement) TEMPLATABLE_VALUE(bool, announcement)
void play(const Ts &...x) override { void play(Ts... x) override {
this->parent_->make_call() this->parent_->make_call()
.set_media_url(this->media_url_.value(x...)) .set_media_url(this->media_url_.value(x...))
.set_announcement(this->announcement_.value(x...)) .set_announcement(this->announcement_.value(x...))
@@ -46,7 +46,7 @@ template<typename... Ts> class PlayMediaAction : public Action<Ts...>, public Pa
template<typename... Ts> class VolumeSetAction : public Action<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class VolumeSetAction : public Action<Ts...>, public Parented<MediaPlayer> {
TEMPLATABLE_VALUE(float, volume) TEMPLATABLE_VALUE(float, volume)
void play(const Ts &...x) override { this->parent_->make_call().set_volume(this->volume_.value(x...)).perform(); } void play(Ts... x) override { this->parent_->make_call().set_volume(this->volume_.value(x...)).perform(); }
}; };
class StateTrigger : public Trigger<> { class StateTrigger : public Trigger<> {
@@ -75,34 +75,32 @@ using OffTrigger = MediaPlayerStateTrigger<MediaPlayerState::MEDIA_PLAYER_STATE_
template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
public: public:
bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_IDLE; } bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_IDLE; }
}; };
template<typename... Ts> class IsPlayingCondition : public Condition<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class IsPlayingCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
public: public:
bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PLAYING; } bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PLAYING; }
}; };
template<typename... Ts> class IsPausedCondition : public Condition<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class IsPausedCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
public: public:
bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PAUSED; } bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PAUSED; }
}; };
template<typename... Ts> class IsAnnouncingCondition : public Condition<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class IsAnnouncingCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
public: public:
bool check(const Ts &...x) override { bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_ANNOUNCING; }
return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_ANNOUNCING;
}
}; };
template<typename... Ts> class IsOnCondition : public Condition<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class IsOnCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
public: public:
bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_ON; } bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_ON; }
}; };
template<typename... Ts> class IsOffCondition : public Condition<Ts...>, public Parented<MediaPlayer> { template<typename... Ts> class IsOffCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
public: public:
bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_OFF; } bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_OFF; }
}; };
} // namespace media_player } // namespace media_player

View File

@@ -40,7 +40,7 @@ template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> {
public: public:
MHZ19CalibrateZeroAction(MHZ19Component *mhz19) : mhz19_(mhz19) {} MHZ19CalibrateZeroAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
void play(const Ts &...x) override { this->mhz19_->calibrate_zero(); } void play(Ts... x) override { this->mhz19_->calibrate_zero(); }
protected: protected:
MHZ19Component *mhz19_; MHZ19Component *mhz19_;
@@ -50,7 +50,7 @@ template<typename... Ts> class MHZ19ABCEnableAction : public Action<Ts...> {
public: public:
MHZ19ABCEnableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {} MHZ19ABCEnableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
void play(const Ts &...x) override { this->mhz19_->abc_enable(); } void play(Ts... x) override { this->mhz19_->abc_enable(); }
protected: protected:
MHZ19Component *mhz19_; MHZ19Component *mhz19_;
@@ -60,7 +60,7 @@ template<typename... Ts> class MHZ19ABCDisableAction : public Action<Ts...> {
public: public:
MHZ19ABCDisableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {} MHZ19ABCDisableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
void play(const Ts &...x) override { this->mhz19_->abc_disable(); } void play(Ts... x) override { this->mhz19_->abc_disable(); }
protected: protected:
MHZ19Component *mhz19_; MHZ19Component *mhz19_;

View File

@@ -9,23 +9,23 @@ namespace micro_wake_word {
template<typename... Ts> class StartAction : public Action<Ts...>, public Parented<MicroWakeWord> { template<typename... Ts> class StartAction : public Action<Ts...>, public Parented<MicroWakeWord> {
public: public:
void play(const Ts &...x) override { this->parent_->start(); } void play(Ts... x) override { this->parent_->start(); }
}; };
template<typename... Ts> class StopAction : public Action<Ts...>, public Parented<MicroWakeWord> { template<typename... Ts> class StopAction : public Action<Ts...>, public Parented<MicroWakeWord> {
public: public:
void play(const Ts &...x) override { this->parent_->stop(); } void play(Ts... x) override { this->parent_->stop(); }
}; };
template<typename... Ts> class IsRunningCondition : public Condition<Ts...>, public Parented<MicroWakeWord> { template<typename... Ts> class IsRunningCondition : public Condition<Ts...>, public Parented<MicroWakeWord> {
public: public:
bool check(const Ts &...x) override { return this->parent_->is_running(); } bool check(Ts... x) override { return this->parent_->is_running(); }
}; };
template<typename... Ts> class EnableModelAction : public Action<Ts...> { template<typename... Ts> class EnableModelAction : public Action<Ts...> {
public: public:
explicit EnableModelAction(WakeWordModel *wake_word_model) : wake_word_model_(wake_word_model) {} explicit EnableModelAction(WakeWordModel *wake_word_model) : wake_word_model_(wake_word_model) {}
void play(const Ts &...x) override { this->wake_word_model_->enable(); } void play(Ts... x) override { this->wake_word_model_->enable(); }
protected: protected:
WakeWordModel *wake_word_model_; WakeWordModel *wake_word_model_;
@@ -34,7 +34,7 @@ template<typename... Ts> class EnableModelAction : public Action<Ts...> {
template<typename... Ts> class DisableModelAction : public Action<Ts...> { template<typename... Ts> class DisableModelAction : public Action<Ts...> {
public: public:
explicit DisableModelAction(WakeWordModel *wake_word_model) : wake_word_model_(wake_word_model) {} explicit DisableModelAction(WakeWordModel *wake_word_model) : wake_word_model_(wake_word_model) {}
void play(const Ts &...x) override { this->wake_word_model_->disable(); } void play(Ts... x) override { this->wake_word_model_->disable(); }
protected: protected:
WakeWordModel *wake_word_model_; WakeWordModel *wake_word_model_;
@@ -43,7 +43,7 @@ template<typename... Ts> class DisableModelAction : public Action<Ts...> {
template<typename... Ts> class ModelIsEnabledCondition : public Condition<Ts...> { template<typename... Ts> class ModelIsEnabledCondition : public Condition<Ts...> {
public: public:
explicit ModelIsEnabledCondition(WakeWordModel *wake_word_model) : wake_word_model_(wake_word_model) {} explicit ModelIsEnabledCondition(WakeWordModel *wake_word_model) : wake_word_model_(wake_word_model) {}
bool check(const Ts &...x) override { return this->wake_word_model_->is_enabled(); } bool check(Ts... x) override { return this->wake_word_model_->is_enabled(); }
protected: protected:
WakeWordModel *wake_word_model_; WakeWordModel *wake_word_model_;

View File

@@ -9,18 +9,18 @@ namespace esphome {
namespace microphone { namespace microphone {
template<typename... Ts> class CaptureAction : public Action<Ts...>, public Parented<Microphone> { template<typename... Ts> class CaptureAction : public Action<Ts...>, public Parented<Microphone> {
void play(const Ts &...x) override { this->parent_->start(); } void play(Ts... x) override { this->parent_->start(); }
}; };
template<typename... Ts> class StopCaptureAction : public Action<Ts...>, public Parented<Microphone> { template<typename... Ts> class StopCaptureAction : public Action<Ts...>, public Parented<Microphone> {
void play(const Ts &...x) override { this->parent_->stop(); } void play(Ts... x) override { this->parent_->stop(); }
}; };
template<typename... Ts> class MuteAction : public Action<Ts...>, public Parented<Microphone> { template<typename... Ts> class MuteAction : public Action<Ts...>, public Parented<Microphone> {
void play(const Ts &...x) override { this->parent_->set_mute_state(true); } void play(Ts... x) override { this->parent_->set_mute_state(true); }
}; };
template<typename... Ts> class UnmuteAction : public Action<Ts...>, public Parented<Microphone> { template<typename... Ts> class UnmuteAction : public Action<Ts...>, public Parented<Microphone> {
void play(const Ts &...x) override { this->parent_->set_mute_state(false); } void play(Ts... x) override { this->parent_->set_mute_state(false); }
}; };
class DataTrigger : public Trigger<const std::vector<uint8_t> &> { class DataTrigger : public Trigger<const std::vector<uint8_t> &> {
@@ -32,12 +32,12 @@ class DataTrigger : public Trigger<const std::vector<uint8_t> &> {
template<typename... Ts> class IsCapturingCondition : public Condition<Ts...>, public Parented<Microphone> { template<typename... Ts> class IsCapturingCondition : public Condition<Ts...>, public Parented<Microphone> {
public: public:
bool check(const Ts &...x) override { return this->parent_->is_running(); } bool check(Ts... x) override { return this->parent_->is_running(); }
}; };
template<typename... Ts> class IsMutedCondition : public Condition<Ts...>, public Parented<Microphone> { template<typename... Ts> class IsMutedCondition : public Condition<Ts...>, public Parented<Microphone> {
public: public:
bool check(const Ts &...x) override { return this->parent_->get_mute_state(); } bool check(Ts... x) override { return this->parent_->get_mute_state(); }
}; };
} // namespace microphone } // namespace microphone

View File

@@ -22,7 +22,7 @@ template<typename... Ts> class FollowMeAction : public MideaActionBase<Ts...> {
TEMPLATABLE_VALUE(bool, use_fahrenheit) TEMPLATABLE_VALUE(bool, use_fahrenheit)
TEMPLATABLE_VALUE(bool, beeper) TEMPLATABLE_VALUE(bool, beeper)
void play(const Ts &...x) override { void play(Ts... x) override {
this->parent_->do_follow_me(this->temperature_.value(x...), this->use_fahrenheit_.value(x...), this->parent_->do_follow_me(this->temperature_.value(x...), this->use_fahrenheit_.value(x...),
this->beeper_.value(x...)); this->beeper_.value(x...));
} }
@@ -30,37 +30,37 @@ template<typename... Ts> class FollowMeAction : public MideaActionBase<Ts...> {
template<typename... Ts> class SwingStepAction : public MideaActionBase<Ts...> { template<typename... Ts> class SwingStepAction : public MideaActionBase<Ts...> {
public: public:
void play(const Ts &...x) override { this->parent_->do_swing_step(); } void play(Ts... x) override { this->parent_->do_swing_step(); }
}; };
template<typename... Ts> class DisplayToggleAction : public MideaActionBase<Ts...> { template<typename... Ts> class DisplayToggleAction : public MideaActionBase<Ts...> {
public: public:
void play(const Ts &...x) override { this->parent_->do_display_toggle(); } void play(Ts... x) override { this->parent_->do_display_toggle(); }
}; };
template<typename... Ts> class BeeperOnAction : public MideaActionBase<Ts...> { template<typename... Ts> class BeeperOnAction : public MideaActionBase<Ts...> {
public: public:
void play(const Ts &...x) override { this->parent_->do_beeper_on(); } void play(Ts... x) override { this->parent_->do_beeper_on(); }
}; };
template<typename... Ts> class BeeperOffAction : public MideaActionBase<Ts...> { template<typename... Ts> class BeeperOffAction : public MideaActionBase<Ts...> {
public: public:
void play(const Ts &...x) override { this->parent_->do_beeper_off(); } void play(Ts... x) override { this->parent_->do_beeper_off(); }
}; };
template<typename... Ts> class PowerOnAction : public MideaActionBase<Ts...> { template<typename... Ts> class PowerOnAction : public MideaActionBase<Ts...> {
public: public:
void play(const Ts &...x) override { this->parent_->do_power_on(); } void play(Ts... x) override { this->parent_->do_power_on(); }
}; };
template<typename... Ts> class PowerOffAction : public MideaActionBase<Ts...> { template<typename... Ts> class PowerOffAction : public MideaActionBase<Ts...> {
public: public:
void play(const Ts &...x) override { this->parent_->do_power_off(); } void play(Ts... x) override { this->parent_->do_power_off(); }
}; };
template<typename... Ts> class PowerToggleAction : public MideaActionBase<Ts...> { template<typename... Ts> class PowerToggleAction : public MideaActionBase<Ts...> {
public: public:
void play(const Ts &...x) override { this->parent_->do_power_toggle(); } void play(Ts... x) override { this->parent_->do_power_toggle(); }
}; };
} // namespace ac } // namespace ac

View File

@@ -9,7 +9,7 @@ namespace mixer_speaker {
template<typename... Ts> class DuckingApplyAction : public Action<Ts...>, public Parented<SourceSpeaker> { template<typename... Ts> class DuckingApplyAction : public Action<Ts...>, public Parented<SourceSpeaker> {
TEMPLATABLE_VALUE(uint8_t, decibel_reduction) TEMPLATABLE_VALUE(uint8_t, decibel_reduction)
TEMPLATABLE_VALUE(uint32_t, duration) TEMPLATABLE_VALUE(uint32_t, duration)
void play(const Ts &...x) override { void play(Ts... x) override {
this->parent_->apply_ducking(this->decibel_reduction_.value(x...), this->duration_.value(x...)); this->parent_->apply_ducking(this->decibel_reduction_.value(x...), this->duration_.value(x...));
} }
}; };

View File

@@ -28,9 +28,8 @@ void ModbusSelect::parse_and_publish(const std::vector<uint8_t> &data) {
if (map_it != this->mapping_.cend()) { if (map_it != this->mapping_.cend()) {
size_t idx = std::distance(this->mapping_.cbegin(), map_it); size_t idx = std::distance(this->mapping_.cbegin(), map_it);
ESP_LOGV(TAG, "Found option %s for value %lld", this->option_at(idx), value); new_state = std::string(this->option_at(idx));
this->publish_state(idx); ESP_LOGV(TAG, "Found option %s for value %lld", new_state->c_str(), value);
return;
} else { } else {
ESP_LOGE(TAG, "No option found for mapping %lld", value); ESP_LOGE(TAG, "No option found for mapping %lld", value);
} }
@@ -41,16 +40,19 @@ void ModbusSelect::parse_and_publish(const std::vector<uint8_t> &data) {
} }
} }
void ModbusSelect::control(size_t index) { void ModbusSelect::control(const std::string &value) {
optional<int64_t> mapval = this->mapping_[index]; auto idx = this->index_of(value);
const char *option = this->option_at(index); if (!idx.has_value()) {
ESP_LOGD(TAG, "Found value %lld for option '%s'", *mapval, option); ESP_LOGW(TAG, "Invalid option '%s'", value.c_str());
return;
}
optional<int64_t> mapval = this->mapping_[idx.value()];
ESP_LOGD(TAG, "Found value %lld for option '%s'", *mapval, value.c_str());
std::vector<uint16_t> data; std::vector<uint16_t> data;
if (this->write_transform_func_.has_value()) { if (this->write_transform_func_.has_value()) {
// Transform func requires string parameter for backward compatibility auto val = (*this->write_transform_func_)(this, value, *mapval, data);
auto val = (*this->write_transform_func_)(this, std::string(option), *mapval, data);
if (val.has_value()) { if (val.has_value()) {
mapval = *val; mapval = *val;
ESP_LOGV(TAG, "write_lambda returned mapping value %lld", *mapval); ESP_LOGV(TAG, "write_lambda returned mapping value %lld", *mapval);
@@ -83,7 +85,7 @@ void ModbusSelect::control(size_t index) {
this->parent_->queue_command(write_cmd); this->parent_->queue_command(write_cmd);
if (this->optimistic_) if (this->optimistic_)
this->publish_state(index); this->publish_state(value);
} }
} // namespace modbus_controller } // namespace modbus_controller

View File

@@ -38,7 +38,7 @@ class ModbusSelect : public Component, public select::Select, public SensorItem
void dump_config() override; void dump_config() override;
void parse_and_publish(const std::vector<uint8_t> &data) override; void parse_and_publish(const std::vector<uint8_t> &data) override;
void control(size_t index) override; void control(const std::string &value) override;
protected: protected:
std::vector<int64_t> mapping_{}; std::vector<int64_t> mapping_{};

View File

@@ -36,7 +36,7 @@ void MQTTAlarmControlPanelComponent::setup() {
} else if (strcasecmp(payload.c_str(), "TRIGGERED") == 0) { } else if (strcasecmp(payload.c_str(), "TRIGGERED") == 0) {
call.triggered(); call.triggered();
} else { } else {
ESP_LOGW(TAG, "'%s': Received unknown command payload %s", this->friendly_name_().c_str(), payload.c_str()); ESP_LOGW(TAG, "'%s': Received unknown command payload %s", this->friendly_name().c_str(), payload.c_str());
} }
call.perform(); call.perform();
}); });

View File

@@ -30,12 +30,9 @@ MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor
} }
void MQTTBinarySensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) { void MQTTBinarySensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
const auto device_class = this->binary_sensor_->get_device_class_ref(); if (!this->binary_sensor_->get_device_class().empty())
if (!device_class.empty()) { root[MQTT_DEVICE_CLASS] = this->binary_sensor_->get_device_class();
root[MQTT_DEVICE_CLASS] = device_class;
}
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
if (this->binary_sensor_->is_status_binary_sensor()) if (this->binary_sensor_->is_status_binary_sensor())
root[MQTT_PAYLOAD_ON] = mqtt::global_mqtt_client->get_availability().payload_available; root[MQTT_PAYLOAD_ON] = mqtt::global_mqtt_client->get_availability().payload_available;
if (this->binary_sensor_->is_status_binary_sensor()) if (this->binary_sensor_->is_status_binary_sensor())

View File

@@ -20,7 +20,7 @@ void MQTTButtonComponent::setup() {
if (payload == "PRESS") { if (payload == "PRESS") {
this->button_->press(); this->button_->press();
} else { } else {
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name_().c_str(), payload.c_str()); ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name().c_str(), payload.c_str());
this->status_momentary_warning("state", 5000); this->status_momentary_warning("state", 5000);
} }
}); });
@@ -33,9 +33,8 @@ void MQTTButtonComponent::dump_config() {
void MQTTButtonComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) { void MQTTButtonComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
config.state_topic = false; config.state_topic = false;
const auto device_class = this->button_->get_device_class_ref(); if (!this->button_->get_device_class().empty()) {
if (!device_class.empty()) { root[MQTT_DEVICE_CLASS] = this->button_->get_device_class();
root[MQTT_DEVICE_CLASS] = device_class;
} }
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks) // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }

View File

@@ -389,7 +389,7 @@ template<typename... Ts> class MQTTPublishAction : public Action<Ts...> {
TEMPLATABLE_VALUE(uint8_t, qos) TEMPLATABLE_VALUE(uint8_t, qos)
TEMPLATABLE_VALUE(bool, retain) TEMPLATABLE_VALUE(bool, retain)
void play(const Ts &...x) override { void play(Ts... x) override {
this->parent_->publish(this->topic_.value(x...), this->payload_.value(x...), this->qos_.value(x...), this->parent_->publish(this->topic_.value(x...), this->payload_.value(x...), this->qos_.value(x...),
this->retain_.value(x...)); this->retain_.value(x...));
} }
@@ -407,7 +407,7 @@ template<typename... Ts> class MQTTPublishJsonAction : public Action<Ts...> {
void set_payload(std::function<void(Ts..., JsonObject)> payload) { this->payload_ = payload; } void set_payload(std::function<void(Ts..., JsonObject)> payload) { this->payload_ = payload; }
void play(const Ts &...x) override { void play(Ts... x) override {
auto f = std::bind(&MQTTPublishJsonAction<Ts...>::encode_, this, x..., std::placeholders::_1); auto f = std::bind(&MQTTPublishJsonAction<Ts...>::encode_, this, x..., std::placeholders::_1);
auto topic = this->topic_.value(x...); auto topic = this->topic_.value(x...);
auto qos = this->qos_.value(x...); auto qos = this->qos_.value(x...);
@@ -424,7 +424,7 @@ template<typename... Ts> class MQTTPublishJsonAction : public Action<Ts...> {
template<typename... Ts> class MQTTConnectedCondition : public Condition<Ts...> { template<typename... Ts> class MQTTConnectedCondition : public Condition<Ts...> {
public: public:
MQTTConnectedCondition(MQTTClientComponent *parent) : parent_(parent) {} MQTTConnectedCondition(MQTTClientComponent *parent) : parent_(parent) {}
bool check(const Ts &...x) override { return this->parent_->is_connected(); } bool check(Ts... x) override { return this->parent_->is_connected(); }
protected: protected:
MQTTClientComponent *parent_; MQTTClientComponent *parent_;
@@ -434,7 +434,7 @@ template<typename... Ts> class MQTTEnableAction : public Action<Ts...> {
public: public:
MQTTEnableAction(MQTTClientComponent *parent) : parent_(parent) {} MQTTEnableAction(MQTTClientComponent *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->enable(); } void play(Ts... x) override { this->parent_->enable(); }
protected: protected:
MQTTClientComponent *parent_; MQTTClientComponent *parent_;
@@ -444,7 +444,7 @@ template<typename... Ts> class MQTTDisableAction : public Action<Ts...> {
public: public:
MQTTDisableAction(MQTTClientComponent *parent) : parent_(parent) {} MQTTDisableAction(MQTTClientComponent *parent) : parent_(parent) {}
void play(const Ts &...x) override { this->parent_->disable(); } void play(Ts... x) override { this->parent_->disable(); }
protected: protected:
MQTTClientComponent *parent_; MQTTClientComponent *parent_;

View File

@@ -64,11 +64,11 @@ bool MQTTComponent::send_discovery_() {
const MQTTDiscoveryInfo &discovery_info = global_mqtt_client->get_discovery_info(); const MQTTDiscoveryInfo &discovery_info = global_mqtt_client->get_discovery_info();
if (discovery_info.clean) { if (discovery_info.clean) {
ESP_LOGV(TAG, "'%s': Cleaning discovery", this->friendly_name_().c_str()); ESP_LOGV(TAG, "'%s': Cleaning discovery", this->friendly_name().c_str());
return global_mqtt_client->publish(this->get_discovery_topic_(discovery_info), "", 0, this->qos_, true); return global_mqtt_client->publish(this->get_discovery_topic_(discovery_info), "", 0, this->qos_, true);
} }
ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name_().c_str()); ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name().c_str());
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
return global_mqtt_client->publish_json( return global_mqtt_client->publish_json(
@@ -85,16 +85,12 @@ bool MQTTComponent::send_discovery_() {
} }
// Fields from EntityBase // Fields from EntityBase
root[MQTT_NAME] = this->get_entity()->has_own_name() ? this->friendly_name_() : ""; root[MQTT_NAME] = this->get_entity()->has_own_name() ? this->friendly_name() : "";
if (this->is_disabled_by_default_()) if (this->is_disabled_by_default())
root[MQTT_ENABLED_BY_DEFAULT] = false; root[MQTT_ENABLED_BY_DEFAULT] = false;
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson if (!this->get_icon().empty())
const auto icon_ref = this->get_icon_ref_(); root[MQTT_ICON] = this->get_icon();
if (!icon_ref.empty()) {
root[MQTT_ICON] = icon_ref;
}
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
const auto entity_category = this->get_entity()->get_entity_category(); const auto entity_category = this->get_entity()->get_entity_category();
switch (entity_category) { switch (entity_category) {
@@ -126,7 +122,7 @@ bool MQTTComponent::send_discovery_() {
const MQTTDiscoveryInfo &discovery_info = global_mqtt_client->get_discovery_info(); const MQTTDiscoveryInfo &discovery_info = global_mqtt_client->get_discovery_info();
if (discovery_info.unique_id_generator == MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR) { if (discovery_info.unique_id_generator == MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR) {
char friendly_name_hash[9]; char friendly_name_hash[9];
sprintf(friendly_name_hash, "%08" PRIx32, fnv1_hash(this->friendly_name_())); sprintf(friendly_name_hash, "%08" PRIx32, fnv1_hash(this->friendly_name()));
friendly_name_hash[8] = 0; // ensure the hash-string ends with null friendly_name_hash[8] = 0; // ensure the hash-string ends with null
root[MQTT_UNIQUE_ID] = get_mac_address() + "-" + this->component_type() + "-" + friendly_name_hash; root[MQTT_UNIQUE_ID] = get_mac_address() + "-" + this->component_type() + "-" + friendly_name_hash;
} else { } else {
@@ -188,7 +184,7 @@ bool MQTTComponent::is_discovery_enabled() const {
} }
std::string MQTTComponent::get_default_object_id_() const { std::string MQTTComponent::get_default_object_id_() const {
return str_sanitize(str_snake_case(this->friendly_name_())); return str_sanitize(str_snake_case(this->friendly_name()));
} }
void MQTTComponent::subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos) { void MQTTComponent::subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos) {
@@ -272,9 +268,9 @@ void MQTTComponent::schedule_resend_state() { this->resend_state_ = true; }
bool MQTTComponent::is_connected_() const { return global_mqtt_client->is_connected(); } bool MQTTComponent::is_connected_() const { return global_mqtt_client->is_connected(); }
// Pull these properties from EntityBase if not overridden // Pull these properties from EntityBase if not overridden
std::string MQTTComponent::friendly_name_() const { return this->get_entity()->get_name(); } std::string MQTTComponent::friendly_name() const { return this->get_entity()->get_name(); }
StringRef MQTTComponent::get_icon_ref_() const { return this->get_entity()->get_icon_ref(); } std::string MQTTComponent::get_icon() const { return this->get_entity()->get_icon(); }
bool MQTTComponent::is_disabled_by_default_() const { return this->get_entity()->is_disabled_by_default(); } bool MQTTComponent::is_disabled_by_default() const { return this->get_entity()->is_disabled_by_default(); }
bool MQTTComponent::is_internal() { bool MQTTComponent::is_internal() {
if (this->has_custom_state_topic_) { if (this->has_custom_state_topic_) {
// If the custom state_topic is null, return true as it is internal and should not publish // If the custom state_topic is null, return true as it is internal and should not publish

View File

@@ -165,13 +165,13 @@ class MQTTComponent : public Component {
virtual const EntityBase *get_entity() const = 0; virtual const EntityBase *get_entity() const = 0;
/// Get the friendly name of this MQTT component. /// Get the friendly name of this MQTT component.
std::string friendly_name_() const; virtual std::string friendly_name() const;
/// Get the icon field of this component as StringRef /// Get the icon field of this component
StringRef get_icon_ref_() const; virtual std::string get_icon() const;
/// Get whether the underlying Entity is disabled by default /// Get whether the underlying Entity is disabled by default
bool is_disabled_by_default_() const; virtual bool is_disabled_by_default() const;
/// Get the MQTT topic that new states will be shared to. /// Get the MQTT topic that new states will be shared to.
std::string get_state_topic_() const; std::string get_state_topic_() const;

View File

@@ -67,12 +67,9 @@ void MQTTCoverComponent::dump_config() {
} }
} }
void MQTTCoverComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) { void MQTTCoverComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
const auto device_class = this->cover_->get_device_class_ref(); if (!this->cover_->get_device_class().empty())
if (!device_class.empty()) { root[MQTT_DEVICE_CLASS] = this->cover_->get_device_class();
root[MQTT_DEVICE_CLASS] = device_class;
}
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
auto traits = this->cover_->get_traits(); auto traits = this->cover_->get_traits();
if (traits.get_is_assumed_state()) { if (traits.get_is_assumed_state()) {

View File

@@ -21,12 +21,8 @@ void MQTTEventComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConf
for (const auto &event_type : this->event_->get_event_types()) for (const auto &event_type : this->event_->get_event_types())
event_types.add(event_type); event_types.add(event_type);
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson if (!this->event_->get_device_class().empty())
const auto device_class = this->event_->get_device_class_ref(); root[MQTT_DEVICE_CLASS] = this->event_->get_device_class();
if (!device_class.empty()) {
root[MQTT_DEVICE_CLASS] = device_class;
}
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
config.command_topic = false; config.command_topic = false;
} }

View File

@@ -24,15 +24,15 @@ void MQTTFanComponent::setup() {
auto val = parse_on_off(payload.c_str()); auto val = parse_on_off(payload.c_str());
switch (val) { switch (val) {
case PARSE_ON: case PARSE_ON:
ESP_LOGD(TAG, "'%s' Turning Fan ON.", this->friendly_name_().c_str()); ESP_LOGD(TAG, "'%s' Turning Fan ON.", this->friendly_name().c_str());
this->state_->turn_on().perform(); this->state_->turn_on().perform();
break; break;
case PARSE_OFF: case PARSE_OFF:
ESP_LOGD(TAG, "'%s' Turning Fan OFF.", this->friendly_name_().c_str()); ESP_LOGD(TAG, "'%s' Turning Fan OFF.", this->friendly_name().c_str());
this->state_->turn_off().perform(); this->state_->turn_off().perform();
break; break;
case PARSE_TOGGLE: case PARSE_TOGGLE:
ESP_LOGD(TAG, "'%s' Toggling Fan.", this->friendly_name_().c_str()); ESP_LOGD(TAG, "'%s' Toggling Fan.", this->friendly_name().c_str());
this->state_->toggle().perform(); this->state_->toggle().perform();
break; break;
case PARSE_NONE: case PARSE_NONE:
@@ -48,11 +48,11 @@ void MQTTFanComponent::setup() {
auto val = parse_on_off(payload.c_str(), "forward", "reverse"); auto val = parse_on_off(payload.c_str(), "forward", "reverse");
switch (val) { switch (val) {
case PARSE_ON: case PARSE_ON:
ESP_LOGD(TAG, "'%s': Setting direction FORWARD", this->friendly_name_().c_str()); ESP_LOGD(TAG, "'%s': Setting direction FORWARD", this->friendly_name().c_str());
this->state_->make_call().set_direction(fan::FanDirection::FORWARD).perform(); this->state_->make_call().set_direction(fan::FanDirection::FORWARD).perform();
break; break;
case PARSE_OFF: case PARSE_OFF:
ESP_LOGD(TAG, "'%s': Setting direction REVERSE", this->friendly_name_().c_str()); ESP_LOGD(TAG, "'%s': Setting direction REVERSE", this->friendly_name().c_str());
this->state_->make_call().set_direction(fan::FanDirection::REVERSE).perform(); this->state_->make_call().set_direction(fan::FanDirection::REVERSE).perform();
break; break;
case PARSE_TOGGLE: case PARSE_TOGGLE:
@@ -75,11 +75,11 @@ void MQTTFanComponent::setup() {
auto val = parse_on_off(payload.c_str(), "oscillate_on", "oscillate_off"); auto val = parse_on_off(payload.c_str(), "oscillate_on", "oscillate_off");
switch (val) { switch (val) {
case PARSE_ON: case PARSE_ON:
ESP_LOGD(TAG, "'%s': Setting oscillating ON", this->friendly_name_().c_str()); ESP_LOGD(TAG, "'%s': Setting oscillating ON", this->friendly_name().c_str());
this->state_->make_call().set_oscillating(true).perform(); this->state_->make_call().set_oscillating(true).perform();
break; break;
case PARSE_OFF: case PARSE_OFF:
ESP_LOGD(TAG, "'%s': Setting oscillating OFF", this->friendly_name_().c_str()); ESP_LOGD(TAG, "'%s': Setting oscillating OFF", this->friendly_name().c_str());
this->state_->make_call().set_oscillating(false).perform(); this->state_->make_call().set_oscillating(false).perform();
break; break;
case PARSE_TOGGLE: case PARSE_TOGGLE:

View File

@@ -24,7 +24,7 @@ void MQTTLockComponent::setup() {
} else if (strcasecmp(payload.c_str(), "OPEN") == 0) { } else if (strcasecmp(payload.c_str(), "OPEN") == 0) {
this->lock_->open(); this->lock_->open();
} else { } else {
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name_().c_str(), payload.c_str()); ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name().c_str(), payload.c_str());
this->status_momentary_warning("state", 5000); this->status_momentary_warning("state", 5000);
} }
}); });

Some files were not shown because too many files have changed in this diff Show More