ESPHome 2025.5.0
Loading...
Searching...
No Matches
binary_output.h
Go to the documentation of this file.
1#pragma once
2
5
6#ifdef USE_POWER_SUPPLY
8#endif
9
10namespace esphome {
11namespace output {
12
13#define LOG_BINARY_OUTPUT(this) \
14 if (this->inverted_) { \
15 ESP_LOGCONFIG(TAG, " Inverted: YES"); \
16 }
17
19 public:
21 void set_inverted(bool inverted) { this->inverted_ = inverted; }
22
23#ifdef USE_POWER_SUPPLY
30 void set_power_supply(power_supply::PowerSupply *power_supply) { this->power_.set_parent(power_supply); }
31#endif
32
34 virtual void set_state(bool state) {
35 if (state) {
36 this->turn_on();
37 } else {
38 this->turn_off();
39 }
40 }
41
43 virtual void turn_on() {
44#ifdef USE_POWER_SUPPLY
45 this->power_.request();
46#endif
47 this->write_state(!this->inverted_);
48 }
49
51 virtual void turn_off() {
52#ifdef USE_POWER_SUPPLY
53 this->power_.unrequest();
54#endif
55 this->write_state(this->inverted_);
56 }
57
58 // ========== INTERNAL METHODS ==========
59 // (In most use cases you won't need these)
61 bool is_inverted() const { return this->inverted_; }
62
63 protected:
64 virtual void write_state(bool state) = 0;
65
66 bool inverted_{false};
67#ifdef USE_POWER_SUPPLY
69#endif
70};
71
72} // namespace output
73} // namespace esphome
virtual void write_state(bool state)=0
power_supply::PowerSupplyRequester power_
void set_power_supply(power_supply::PowerSupply *power_supply)
Use this to connect up a power supply to this output.
virtual void set_state(bool state)
Enable or disable this binary output.
virtual void turn_off()
Disable this binary output.
virtual void turn_on()
Enable this binary output.
void set_inverted(bool inverted)
Set the inversion state of this binary output.
bool is_inverted() const
Return whether this binary output is inverted.
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7