esphome-tw7100/switch/__init__.py

40 lines
1.1 KiB
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
),
cv.Optional("BTAUDIO"): 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))
cg.add(parent.set_set_power(switch_))
if "BTAUDIO" in config:
switch_ = await switch.new_switch(config["BTAUDIO"])
cg.add(switch_.set_cmd("BTAUDIO"))
cg.add(switch_.set_tw7100_parent(parent))
cg.add(parent.set_set_btaudio(switch_))