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

Allow WIFI to be disabled and enabled (#4810)

Co-authored-by: Péter Sárközi <xmisterhu@gmail.com>
Co-authored-by: Ash McKenzie <ash@the-rebellion.net>
This commit is contained in:
Jesse Hills
2023-06-01 11:34:35 +12:00
committed by GitHub
parent 1ea5d90ea3
commit b06bdc2da3
3 changed files with 81 additions and 6 deletions

View File

@@ -53,6 +53,9 @@ WIFI_POWER_SAVE_MODES = {
"HIGH": WiFiPowerSaveMode.WIFI_POWER_SAVE_HIGH,
}
WiFiConnectedCondition = wifi_ns.class_("WiFiConnectedCondition", Condition)
WiFiEnabledCondition = wifi_ns.class_("WiFiEnabledCondition", Condition)
WiFiEnableAction = wifi_ns.class_("WiFiEnableAction", automation.Action)
WiFiDisableAction = wifi_ns.class_("WiFiDisableAction", automation.Action)
def validate_password(value):
@@ -253,6 +256,7 @@ def _validate(config):
CONF_OUTPUT_POWER = "output_power"
CONF_PASSIVE_SCAN = "passive_scan"
CONF_ENABLE_ON_BOOT = "enable_on_boot"
CONFIG_SCHEMA = cv.All(
cv.Schema(
{
@@ -286,6 +290,7 @@ CONFIG_SCHEMA = cv.All(
"This option has been removed. Please use the [disabled] option under the "
"new mdns component instead."
),
cv.Optional(CONF_ENABLE_ON_BOOT, default=True): cv.boolean,
}
),
_validate,
@@ -385,6 +390,8 @@ async def to_code(config):
if CONF_OUTPUT_POWER in config:
cg.add(var.set_output_power(config[CONF_OUTPUT_POWER]))
cg.add(var.set_enable_on_boot(config[CONF_ENABLE_ON_BOOT]))
if CORE.is_esp8266:
cg.add_library("ESP8266WiFi", None)
elif CORE.is_esp32 and CORE.using_arduino:
@@ -410,3 +417,18 @@ async def to_code(config):
@automation.register_condition("wifi.connected", WiFiConnectedCondition, cv.Schema({}))
async def wifi_connected_to_code(config, condition_id, template_arg, args):
return cg.new_Pvariable(condition_id, template_arg)
@automation.register_condition("wifi.enabled", WiFiEnabledCondition, cv.Schema({}))
async def wifi_enabled_to_code(config, condition_id, template_arg, args):
return cg.new_Pvariable(condition_id, template_arg)
@automation.register_action("wifi.enable", WiFiEnableAction, cv.Schema({}))
async def wifi_enable_to_code(config, action_id, template_arg, args):
return cg.new_Pvariable(action_id, template_arg)
@automation.register_action("wifi.disable", WiFiDisableAction, cv.Schema({}))
async def wifi_disable_to_code(config, action_id, template_arg, args):
return cg.new_Pvariable(action_id, template_arg)