Compare commits

...

3 Commits

Author SHA1 Message Date
Jesse Hills
8558d3bbb4 Add to tests 2021-12-20 08:18:14 +13:00
Jesse Hills
f135ff285a Add codeowner 2021-12-20 08:14:52 +13:00
Jesse Hills
0ab8f2be2e Create safe mode button platform 2021-12-20 08:04:40 +13:00
5 changed files with 75 additions and 0 deletions

View File

@@ -133,6 +133,7 @@ esphome/components/rf_bridge/* @jesserockz
esphome/components/rgbct/* @jesserockz
esphome/components/rtttl/* @glmnet
esphome/components/safe_mode/* @paulmonigatti
esphome/components/safe_mode/button/* @jesserockz
esphome/components/scd4x/* @sjtrny
esphome/components/script/* @esphome/core
esphome/components/sdm_meter/* @jesserockz @polyfaces

View File

@@ -0,0 +1,27 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import button
from esphome.const import (
CONF_ID,
ENTITY_CATEGORY_CONFIG,
ICON_RESTART_ALERT,
)
from .. import safe_mode_ns
CODEOWNERS = ["@jesserockz"]
SafeModeButton = safe_mode_ns.class_("SafeModeButton", button.Button, cg.Component)
CONFIG_SCHEMA = (
button.button_schema(
entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_RESTART_ALERT
)
.extend({cv.GenerateID(): cv.declare_id(SafeModeButton)})
.extend(cv.COMPONENT_SCHEMA)
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await button.register_button(var, config)

View File

@@ -0,0 +1,24 @@
#include "safe_mode_button.h"
#include "esphome/core/application.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
namespace esphome {
namespace safe_mode {
static const char *const TAG = "safe_mode.button";
void SafeModeButton::set_ota(ota::OTAComponent *ota) { this->ota_ = ota; }
void SafeModeButton::press_action() {
ESP_LOGI(TAG, "Restarting device in safe mode...");
this->ota_->set_safe_mode_pending(true);
// Let MQTT settle a bit
delay(100); // NOLINT
App.safe_reboot();
}
void SafeModeButton::dump_config() { LOG_BUTTON("", "Safe Mode Button", this); }
} // namespace safe_mode
} // namespace esphome

View File

@@ -0,0 +1,21 @@
#pragma once
#include "esphome/components/button/button.h"
#include "esphome/components/ota/ota_component.h"
#include "esphome/core/component.h"
namespace esphome {
namespace safe_mode {
class SafeModeButton : public button::Button, public Component {
public:
void dump_config() override;
void set_ota(ota::OTAComponent *ota);
protected:
ota::OTAComponent *ota_;
void press_action() override;
};
} // namespace safe_mode
} // namespace esphome

View File

@@ -525,3 +525,5 @@ xpt2046:
button:
- platform: restart
name: Restart Button
- platform: safe_mode
name: Safe Mode Button