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:
@@ -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):
|
||||
|
Reference in New Issue
Block a user