mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Configurable OTA Safe Mode (#1393)
This commit is contained in:
parent
7ff3f752e2
commit
3afb564a48
5 changed files with 12 additions and 3 deletions
|
@ -1,6 +1,9 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID, CONF_PASSWORD, CONF_PORT, CONF_SAFE_MODE
|
||||
from esphome.const import (
|
||||
CONF_ID, CONF_NUM_ATTEMPTS, CONF_PASSWORD,
|
||||
CONF_PORT, CONF_REBOOT_TIMEOUT, CONF_SAFE_MODE
|
||||
)
|
||||
from esphome.core import CORE, coroutine_with_priority
|
||||
|
||||
CODEOWNERS = ['@esphome/core']
|
||||
|
@ -14,6 +17,8 @@ CONFIG_SCHEMA = cv.Schema({
|
|||
cv.Optional(CONF_SAFE_MODE, default=True): cv.boolean,
|
||||
cv.SplitDefault(CONF_PORT, esp8266=8266, esp32=3232): cv.port,
|
||||
cv.Optional(CONF_PASSWORD, default=''): cv.string,
|
||||
cv.Optional(CONF_REBOOT_TIMEOUT, default='5min'): cv.positive_time_period_milliseconds,
|
||||
cv.Optional(CONF_NUM_ATTEMPTS, default='10'): cv.positive_not_null_int
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
|
@ -26,7 +31,7 @@ def to_code(config):
|
|||
yield cg.register_component(var, config)
|
||||
|
||||
if config[CONF_SAFE_MODE]:
|
||||
cg.add(var.start_safe_mode())
|
||||
cg.add(var.start_safe_mode(config[CONF_NUM_ATTEMPTS], config[CONF_REBOOT_TIMEOUT]))
|
||||
|
||||
if CORE.is_esp8266:
|
||||
cg.add_library('Update', None)
|
||||
|
|
|
@ -47,7 +47,7 @@ class OTAComponent : public Component {
|
|||
/// Manually set the port OTA should listen on.
|
||||
void set_port(uint16_t port);
|
||||
|
||||
void start_safe_mode(uint8_t num_attempts = 10, uint32_t enable_time = 120000);
|
||||
void start_safe_mode(uint8_t num_attempts, uint32_t enable_time);
|
||||
|
||||
// ========== INTERNAL METHODS ==========
|
||||
// (In most use cases you won't need these)
|
||||
|
|
|
@ -154,6 +154,8 @@ ota:
|
|||
safe_mode: True
|
||||
password: 'superlongpasswordthatnoonewillknow'
|
||||
port: 3286
|
||||
reboot_timeout: 2min
|
||||
num_attempts: 5
|
||||
|
||||
logger:
|
||||
baud_rate: 0
|
||||
|
|
|
@ -40,6 +40,7 @@ uart:
|
|||
ota:
|
||||
safe_mode: True
|
||||
port: 3286
|
||||
num_attempts: 15
|
||||
|
||||
logger:
|
||||
level: DEBUG
|
||||
|
|
|
@ -204,6 +204,7 @@ uart:
|
|||
ota:
|
||||
safe_mode: True
|
||||
port: 3286
|
||||
reboot_timeout: 15min
|
||||
|
||||
logger:
|
||||
hardware_uart: UART1
|
||||
|
|
Loading…
Reference in a new issue