mirror of
https://github.com/esphome/esphome.git
synced 2025-09-04 04:12:23 +01:00
Add ability to await safe mode in codegen (#4529)
* Add ability to await OTA safe mode * Make pylint happy
This commit is contained in:
@@ -9,9 +9,13 @@ from esphome.const import (
|
||||
CONF_SETUP_PRIORITY,
|
||||
CONF_UPDATE_INTERVAL,
|
||||
CONF_TYPE_ID,
|
||||
CONF_OTA,
|
||||
CONF_SAFE_MODE,
|
||||
KEY_PAST_SAFE_MODE,
|
||||
)
|
||||
|
||||
from esphome.core import coroutine, ID, CORE
|
||||
from esphome.coroutine import FakeAwaitable
|
||||
from esphome.types import ConfigType, ConfigFragmentType
|
||||
from esphome.cpp_generator import add, get_variable
|
||||
from esphome.cpp_types import App
|
||||
@@ -127,3 +131,19 @@ async def build_registry_list(registry, config):
|
||||
action = await build_registry_entry(registry, conf)
|
||||
actions.append(action)
|
||||
return actions
|
||||
|
||||
|
||||
async def past_safe_mode():
|
||||
safe_mode_enabled = (
|
||||
CONF_OTA in CORE.config and CORE.config[CONF_OTA][CONF_SAFE_MODE]
|
||||
)
|
||||
if not safe_mode_enabled:
|
||||
return
|
||||
|
||||
def _safe_mode_generator():
|
||||
while True:
|
||||
if CORE.data.get(CONF_OTA, {}).get(KEY_PAST_SAFE_MODE, False):
|
||||
return
|
||||
yield
|
||||
|
||||
return await FakeAwaitable(_safe_mode_generator())
|
||||
|
Reference in New Issue
Block a user