Bug fixes and switch

This commit is contained in:
T
2025-03-20 16:49:53 +01:00
parent 2c29ef0e71
commit 76f27cdfeb
5 changed files with 120 additions and 62 deletions

23
switch.py Normal file
View File

@@ -0,0 +1,23 @@
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))