esphome/esphome/components/wake_on_lan/button.py
William Charlton f0b183a552
Wake-on-LAN button (#3030)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: William Charlton <will.charlton1@icloud.com>
2022-01-23 00:13:46 +13:00

32 lines
909 B
Python

import esphome.codegen as cg
from esphome.components import button
import esphome.config_validation as cv
from esphome.const import CONF_ID
CONF_TARGET_MAC_ADDRESS = "target_mac_address"
wake_on_lan_ns = cg.esphome_ns.namespace("wake_on_lan")
WakeOnLanButton = wake_on_lan_ns.class_("WakeOnLanButton", button.Button, cg.Component)
DEPENDENCIES = ["network"]
CONFIG_SCHEMA = cv.All(
button.BUTTON_SCHEMA.extend(cv.COMPONENT_SCHEMA).extend(
cv.Schema(
{
cv.Required(CONF_TARGET_MAC_ADDRESS): cv.mac_address,
cv.GenerateID(): cv.declare_id(WakeOnLanButton),
}
),
),
cv.only_with_arduino,
)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.add(var.set_macaddr(*config[CONF_TARGET_MAC_ADDRESS].parts))
yield cg.register_component(var, config)
yield button.register_button(var, config)