30 lines
779 B
Python
30 lines
779 B
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import switch
|
|
from esphome.const import CONF_POWER, ENTITY_CATEGORY_CONFIG, CONF_ID
|
|
|
|
from .. import tw7100, tw7100_ns, CONF_TW7100_ID
|
|
|
|
DEPENDENCIES = ["tw7100"]
|
|
CODEOWNERS = ["@sqozz"]
|
|
|
|
tw7100Switch = tw7100_ns.class_("tw7100Switch", switch.Switch, cg.Component)
|
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
{
|
|
cv.GenerateID(): cv.use_id(tw7100),
|
|
cv.Optional("PWR"): switch.switch_schema(
|
|
tw7100Switch
|
|
),
|
|
}
|
|
)
|
|
|
|
|
|
async def to_code(config):
|
|
parent = await cg.get_variable(config[CONF_ID])
|
|
|
|
if "PWR" in config:
|
|
switch_ = await switch.new_switch(config["PWR"])
|
|
cg.add(switch_.set_cmd("PWR"))
|
|
cg.add(switch_.set_tw7100_parent(parent))
|