2024-09-15 18:44:45 +02:00
|
|
|
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
|
|
|
|
),
|
2024-09-16 02:25:05 +02:00
|
|
|
cv.Optional("BTAUDIO"): switch.switch_schema(
|
|
|
|
tw7100Switch
|
|
|
|
),
|
2024-09-17 02:14:41 +02:00
|
|
|
cv.Optional("MUTE"): switch.switch_schema(
|
|
|
|
tw7100Switch
|
|
|
|
),
|
2024-09-15 18:44:45 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
2024-09-16 02:25:05 +02:00
|
|
|
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_))
|
2024-09-17 02:14:41 +02:00
|
|
|
|
|
|
|
if "MUTE" in config:
|
|
|
|
switch_ = await switch.new_switch(config["MUTE"])
|
|
|
|
cg.add(switch_.set_cmd("MUTE"))
|
|
|
|
cg.add(switch_.set_tw7100_parent(parent))
|
|
|
|
cg.add(parent.set_set_mute(switch_))
|