mirror of
https://github.com/esphome/esphome.git
synced 2025-09-19 03:32:20 +01:00
Add more demo platforms (#8903)
This commit is contained in:
50
esphome/components/demo/demo_valve.h
Normal file
50
esphome/components/demo/demo_valve.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/valve/valve.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
enum class DemoValveType {
|
||||
TYPE_1,
|
||||
TYPE_2,
|
||||
};
|
||||
|
||||
class DemoValve : public valve::Valve {
|
||||
public:
|
||||
valve::ValveTraits get_traits() override {
|
||||
valve::ValveTraits traits;
|
||||
if (this->type_ == DemoValveType::TYPE_2) {
|
||||
traits.set_supports_position(true);
|
||||
traits.set_supports_toggle(true);
|
||||
traits.set_supports_stop(true);
|
||||
}
|
||||
return traits;
|
||||
}
|
||||
|
||||
void set_type(DemoValveType type) { this->type_ = type; }
|
||||
|
||||
protected:
|
||||
void control(const valve::ValveCall &call) override {
|
||||
if (call.get_position().has_value()) {
|
||||
this->publish_state(*call.get_position());
|
||||
return;
|
||||
} else if (call.get_toggle().has_value()) {
|
||||
if (call.get_toggle().value()) {
|
||||
if (this->position == valve::VALVE_OPEN) {
|
||||
this->publish_state(valve::VALVE_CLOSED);
|
||||
} else {
|
||||
this->publish_state(valve::VALVE_OPEN);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (call.get_stop()) {
|
||||
this->publish_state(this->position); // Keep the current position
|
||||
return;
|
||||
}
|
||||
}
|
||||
DemoValveType type_{};
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
Reference in New Issue
Block a user