ESPHome 2025.6.2
Loading...
Searching...
No Matches
demo_valve.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace esphome {
6namespace demo {
7
8enum class DemoValveType {
9 TYPE_1,
10 TYPE_2,
11};
12
13class DemoValve : public valve::Valve {
14 public:
16 valve::ValveTraits traits;
17 if (this->type_ == DemoValveType::TYPE_2) {
18 traits.set_supports_position(true);
19 traits.set_supports_toggle(true);
20 traits.set_supports_stop(true);
21 }
22 return traits;
23 }
24
26
27 protected:
28 void control(const valve::ValveCall &call) override {
29 if (call.get_position().has_value()) {
30 this->position = *call.get_position();
31 this->publish_state();
32 return;
33 } else if (call.get_toggle().has_value()) {
34 if (call.get_toggle().value()) {
35 if (this->position == valve::VALVE_OPEN) {
37 this->publish_state();
38 } else {
40 this->publish_state();
41 }
42 }
43 return;
44 } else if (call.get_stop()) {
46 this->publish_state(); // Keep the current position
47 return;
48 }
49 }
51};
52
53} // namespace demo
54} // namespace esphome
void control(const valve::ValveCall &call) override
Definition demo_valve.h:28
valve::ValveTraits get_traits() override
Definition demo_valve.h:15
void set_type(DemoValveType type)
Definition demo_valve.h:25
bool has_value() const
Definition optional.h:87
value_type const & value() const
Definition optional.h:89
const optional< bool > & get_toggle() const
Definition valve.cpp:91
const optional< float > & get_position() const
Definition valve.cpp:90
bool get_stop() const
Definition valve.cpp:125
Base class for all valve devices.
Definition valve.h:105
void publish_state(bool save=true)
Publish the current state of the valve.
Definition valve.cpp:130
float position
The position of the valve from 0.0 (fully closed) to 1.0 (fully open).
Definition valve.h:116
ValveOperation current_operation
The current operation of the valve (idle, opening, closing).
Definition valve.h:110
void set_supports_position(bool supports_position)
void set_supports_stop(bool supports_stop)
void set_supports_toggle(bool supports_toggle)
uint8_t type
const float VALVE_OPEN
Definition valve.cpp:9
const float VALVE_CLOSED
Definition valve.cpp:10
@ VALVE_OPERATION_IDLE
The valve is currently idle (not moving)
Definition valve.h:77
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7