mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 23:18:10 +01:00
[safe_mode] Set safe mode core data in disabled cases (#6983)
This commit is contained in:
parent
c9a0daf4b6
commit
481cf7384a
1 changed files with 12 additions and 13 deletions
|
@ -56,21 +56,20 @@ CONFIG_SCHEMA = cv.All(
|
||||||
|
|
||||||
@coroutine_with_priority(50.0)
|
@coroutine_with_priority(50.0)
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
if config[CONF_DISABLED]:
|
if not config[CONF_DISABLED]:
|
||||||
return
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
for conf in config.get(CONF_ON_SAFE_MODE, []):
|
||||||
await cg.register_component(var, config)
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
|
||||||
for conf in config.get(CONF_ON_SAFE_MODE, []):
|
condition = var.should_enter_safe_mode(
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
config[CONF_NUM_ATTEMPTS],
|
||||||
await automation.build_automation(trigger, [], conf)
|
config[CONF_REBOOT_TIMEOUT],
|
||||||
|
config[CONF_BOOT_IS_GOOD_AFTER],
|
||||||
|
)
|
||||||
|
cg.add(RawExpression(f"if ({condition}) return"))
|
||||||
|
|
||||||
condition = var.should_enter_safe_mode(
|
|
||||||
config[CONF_NUM_ATTEMPTS],
|
|
||||||
config[CONF_REBOOT_TIMEOUT],
|
|
||||||
config[CONF_BOOT_IS_GOOD_AFTER],
|
|
||||||
)
|
|
||||||
cg.add(RawExpression(f"if ({condition}) return"))
|
|
||||||
CORE.data[CONF_SAFE_MODE] = {}
|
CORE.data[CONF_SAFE_MODE] = {}
|
||||||
CORE.data[CONF_SAFE_MODE][KEY_PAST_SAFE_MODE] = True
|
CORE.data[CONF_SAFE_MODE][KEY_PAST_SAFE_MODE] = True
|
||||||
|
|
Loading…
Reference in a new issue