1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-03 11:52:20 +01:00

add wifi.on_connect and wifi.on_disconnect triggers (#3639)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Charles Johnson
2023-11-07 05:17:13 +00:00
committed by GitHub
parent 888c298d7e
commit 31fec2d692
4 changed files with 44 additions and 5 deletions

View File

@@ -32,6 +32,8 @@ from esphome.const import (
CONF_KEY,
CONF_USERNAME,
CONF_EAP,
CONF_ON_CONNECT,
CONF_ON_DISCONNECT,
)
from esphome.core import CORE, HexInt, coroutine_with_priority
from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant, const
@@ -306,6 +308,10 @@ CONFIG_SCHEMA = cv.All(
"new mdns component instead."
),
cv.Optional(CONF_ENABLE_ON_BOOT, default=True): cv.boolean,
cv.Optional(CONF_ON_CONNECT): automation.validate_automation(single=True),
cv.Optional(CONF_ON_DISCONNECT): automation.validate_automation(
single=True
),
}
),
_validate,
@@ -425,9 +431,21 @@ async def to_code(config):
cg.add_define("USE_WIFI")
# Register at end for OTA safe mode
# must register before OTA safe mode check
await cg.register_component(var, config)
await cg.past_safe_mode()
if on_connect_config := config.get(CONF_ON_CONNECT):
await automation.build_automation(
var.get_connect_trigger(), [], on_connect_config
)
if on_disconnect_config := config.get(CONF_ON_DISCONNECT):
await automation.build_automation(
var.get_disconnect_trigger(), [], on_disconnect_config
)
@automation.register_condition("wifi.connected", WiFiConnectedCondition, cv.Schema({}))
async def wifi_connected_to_code(config, condition_id, template_arg, args):