import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import switch from . import CONF_OPTOMA_RS232_ID, OptomaRS232Component, optoma_ns from ...const import DEVICE_CLASS_SWITCH DEPENDENCIES = ["optoma_rs232"] PowerSwitch = optoma_ns.class_("PowerSwitch", switch.Switch) CONFIG_SCHEMA = switch.switch_schema( PowerSwitch, device_class=DEVICE_CLASS_SWITCH, ).extend({ cv.GenerateID(CONF_OPTOMA_RS232_ID): cv.use_id(OptomaRS232Component), }) async def to_code(config): hub = await cg.get_variable(config[CONF_OPTOMA_RS232_ID]) cont = await switch.new_switch(config) await cg.register_parented(cont, config[CONF_OPTOMA_RS232_ID]) cg.add(hub.set_beamer_power_switch(cont))