1
0
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:
Jesse Hills
2025-05-29 08:23:45 +12:00
committed by GitHub
parent 3fb9577ad9
commit c4cb694d77
10 changed files with 500 additions and 0 deletions

View 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