esphome/esphome/components/template/switch/template_switch.h
Otto Winter 8e75980ebd
Cleanup dashboard JS (#491)
* Cleanup dashboard JS

* Add vscode

* Save start_mark/end_mark

* Updates

* Updates

* Remove need for cv.nameable

It's a bit hacky but removes so much bloat from integrations

* Add enum helper

* Document APIs, and Improvements

* Fixes

* Fixes

* Update PULL_REQUEST_TEMPLATE.md

* Updates

* Updates

* Updates
2019-04-22 21:56:30 +02:00

42 lines
1 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/switch/switch.h"
namespace esphome {
namespace template_ {
class TemplateSwitch : public switch_::Switch, public Component {
public:
TemplateSwitch();
void setup() override;
void dump_config() override;
void set_state_lambda(std::function<optional<bool>()> &&f);
void set_restore_state(bool restore_state);
Trigger<> *get_turn_on_trigger() const;
Trigger<> *get_turn_off_trigger() const;
void set_optimistic(bool optimistic);
void set_assumed_state(bool assumed_state);
void loop() override;
float get_setup_priority() const override;
protected:
bool assumed_state() override;
void write_state(bool state) override;
optional<std::function<optional<bool>()>> f_;
bool optimistic_{false};
bool assumed_state_{false};
Trigger<> *turn_on_trigger_;
Trigger<> *turn_off_trigger_;
Trigger<> *prev_trigger_{nullptr};
bool restore_state_{false};
};
} // namespace template_
} // namespace esphome