mirror of
https://github.com/esphome/esphome.git
synced 2025-10-26 12:43:48 +00:00
Add select entities and implement template select (#2067)
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
33
esphome/components/select/automation.h
Normal file
33
esphome/components/select/automation.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace select {
|
||||
|
||||
class SelectStateTrigger : public Trigger<std::string> {
|
||||
public:
|
||||
explicit SelectStateTrigger(Select *parent) {
|
||||
parent->add_on_state_callback([this](std::string value) { this->trigger(std::move(value)); });
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class SelectSetAction : public Action<Ts...> {
|
||||
public:
|
||||
SelectSetAction(Select *select) : select_(select) {}
|
||||
TEMPLATABLE_VALUE(std::string, option)
|
||||
|
||||
void play(Ts... x) override {
|
||||
auto call = this->select_->make_call();
|
||||
call.set_option(this->option_.value(x...));
|
||||
call.perform();
|
||||
}
|
||||
|
||||
protected:
|
||||
Select *select_;
|
||||
};
|
||||
|
||||
} // namespace select
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user