mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 21:09:53 +02:00
add template fan (#6310)
This commit is contained in:
@@ -111,6 +111,13 @@ template<typename... Ts> class FanIsOffCondition : public Condition<Ts...> {
|
||||
Fan *state_;
|
||||
};
|
||||
|
||||
class FanStateTrigger : public Trigger<Fan *> {
|
||||
public:
|
||||
FanStateTrigger(Fan *state) {
|
||||
state->add_on_state_callback([this, state]() { this->trigger(state); });
|
||||
}
|
||||
};
|
||||
|
||||
class FanTurnOnTrigger : public Trigger<> {
|
||||
public:
|
||||
FanTurnOnTrigger(Fan *state) {
|
||||
@@ -147,15 +154,51 @@ class FanTurnOffTrigger : public Trigger<> {
|
||||
bool last_on_;
|
||||
};
|
||||
|
||||
class FanSpeedSetTrigger : public Trigger<> {
|
||||
class FanDirectionSetTrigger : public Trigger<FanDirection> {
|
||||
public:
|
||||
FanDirectionSetTrigger(Fan *state) {
|
||||
state->add_on_state_callback([this, state]() {
|
||||
auto direction = state->direction;
|
||||
auto should_trigger = direction != this->last_direction_;
|
||||
this->last_direction_ = direction;
|
||||
if (should_trigger) {
|
||||
this->trigger(direction);
|
||||
}
|
||||
});
|
||||
this->last_direction_ = state->direction;
|
||||
}
|
||||
|
||||
protected:
|
||||
FanDirection last_direction_;
|
||||
};
|
||||
|
||||
class FanOscillatingSetTrigger : public Trigger<bool> {
|
||||
public:
|
||||
FanOscillatingSetTrigger(Fan *state) {
|
||||
state->add_on_state_callback([this, state]() {
|
||||
auto oscillating = state->oscillating;
|
||||
auto should_trigger = oscillating != this->last_oscillating_;
|
||||
this->last_oscillating_ = oscillating;
|
||||
if (should_trigger) {
|
||||
this->trigger(oscillating);
|
||||
}
|
||||
});
|
||||
this->last_oscillating_ = state->oscillating;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool last_oscillating_;
|
||||
};
|
||||
|
||||
class FanSpeedSetTrigger : public Trigger<int> {
|
||||
public:
|
||||
FanSpeedSetTrigger(Fan *state) {
|
||||
state->add_on_state_callback([this, state]() {
|
||||
auto speed = state->speed;
|
||||
auto should_trigger = speed != !this->last_speed_;
|
||||
auto should_trigger = speed != this->last_speed_;
|
||||
this->last_speed_ = speed;
|
||||
if (should_trigger) {
|
||||
this->trigger();
|
||||
this->trigger(speed);
|
||||
}
|
||||
});
|
||||
this->last_speed_ = state->speed;
|
||||
@@ -165,7 +208,7 @@ class FanSpeedSetTrigger : public Trigger<> {
|
||||
int last_speed_;
|
||||
};
|
||||
|
||||
class FanPresetSetTrigger : public Trigger<> {
|
||||
class FanPresetSetTrigger : public Trigger<std::string> {
|
||||
public:
|
||||
FanPresetSetTrigger(Fan *state) {
|
||||
state->add_on_state_callback([this, state]() {
|
||||
@@ -173,7 +216,7 @@ class FanPresetSetTrigger : public Trigger<> {
|
||||
auto should_trigger = preset_mode != this->last_preset_mode_;
|
||||
this->last_preset_mode_ = preset_mode;
|
||||
if (should_trigger) {
|
||||
this->trigger();
|
||||
this->trigger(preset_mode);
|
||||
}
|
||||
});
|
||||
this->last_preset_mode_ = state->preset_mode;
|
||||
|
||||
Reference in New Issue
Block a user