ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
power_supply.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
5
6#include <cinttypes>
7
8namespace esphome::power_supply {
9
10class PowerSupply : public Component {
11 public:
12 void set_pin(GPIOPin *pin) { pin_ = pin; }
13 void set_enable_time(uint32_t enable_time) { enable_time_ = enable_time; }
14 void set_keep_on_time(uint32_t keep_on_time) { keep_on_time_ = keep_on_time; }
15 void set_enable_on_boot(bool enable_on_boot) { enable_on_boot_ = enable_on_boot; }
16
18 bool is_enabled() const;
19
21 void request_high_power();
22
25
26 // ========== INTERNAL METHODS ==========
27 // (In most use cases you won't need these)
29 void setup() override;
30 void dump_config() override;
32 float get_setup_priority() const override;
33
34 void on_powerdown() override;
35
36 protected:
40 int16_t active_requests_{0}; // use signed integer to make catching negative requests easier.
41 bool enable_on_boot_{false};
42};
43
45 public:
46 void set_parent(PowerSupply *parent) { parent_ = parent; }
47 void request() {
48 if (!this->requested_ && this->parent_ != nullptr) {
50 this->requested_ = true;
51 }
52 }
53 void unrequest() {
54 if (this->requested_ && this->parent_ != nullptr) {
56 this->requested_ = false;
57 }
58 }
59
60 protected:
62 bool requested_{false};
63};
64
65} // namespace esphome::power_supply
void request_high_power()
Request high power mode. Use unrequest_high_power() to remove this request.
void set_enable_time(uint32_t enable_time)
void set_enable_on_boot(bool enable_on_boot)
bool is_enabled() const
Is this power supply currently on?
void unrequest_high_power()
Un-request high power mode.
void set_keep_on_time(uint32_t keep_on_time)
void setup() override
Register callbacks.
float get_setup_priority() const override
Hardware setup priority (+1).
static void uint32_t