ESPHome
2026.5.1
Loading...
Searching...
No Matches
esphome
components
restart
switch
restart_switch.cpp
Go to the documentation of this file.
1
#include "
restart_switch.h
"
2
#include "
esphome/core/hal.h
"
3
#include "
esphome/core/log.h
"
4
#include "
esphome/core/application.h
"
5
6
namespace
esphome::restart
{
7
8
static
const
char
*
const
TAG =
"restart"
;
9
10
void
RestartSwitch::write_state
(
bool
state
) {
11
// Acknowledge
12
this->
publish_state
(
false
);
13
14
if
(state) {
15
ESP_LOGI(TAG,
"Restarting device"
);
16
// Let MQTT settle a bit
17
delay
(100);
// NOLINT
18
App
.
safe_reboot
();
19
}
20
}
21
void
RestartSwitch::dump_config
() { LOG_SWITCH(
""
,
"Restart Switch"
,
this
); }
22
23
}
// namespace esphome::restart
application.h
esphome::Application::safe_reboot
void safe_reboot()
Definition
application.cpp:270
esphome::restart::RestartSwitch::write_state
void write_state(bool state) override
Definition
restart_switch.cpp:10
esphome::restart::RestartSwitch::dump_config
void dump_config() override
Definition
restart_switch.cpp:21
esphome::switch_::Switch::publish_state
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition
switch.cpp:56
hal.h
state
bool state
Definition
fan.h:2
log.h
esphome::restart
Definition
restart_button.cpp:6
esphome::delay
void HOT delay(uint32_t ms)
Definition
hal.cpp:85
esphome::App
Application App
Global storage of Application pointer - only one Application can exist.
restart_switch.h
Generated by
1.12.0