46 lines
1.5 KiB
Python
46 lines
1.5 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)
|
|
|
|
switches = [
|
|
("PWR","mdi:power"),
|
|
("BTAUDIO","mdi:speaker-bluetooth"),
|
|
("MUTE","mdi:video-box-off"),
|
|
("WLPWR","mdi:access-point"),
|
|
("AUTOHOME","mdi:cog-clockwise"),
|
|
# ("PRODUCT",""), # present in datasheet but tw7100 only responds with "ERR" (no details)
|
|
("STANDBYCONF","mdi:frequently-asked-questions"),
|
|
("ILLUM","mdi:sunglasses"),
|
|
("VREVERSE","mdi:arrow-expand-vertical"),
|
|
("HREVERSE","mdi:arrow-expand-horizontal"),
|
|
("AUDIOOUT","mdi:audio-input-stereo-minijack"),
|
|
("IMGPROC",""),
|
|
("4KENHANCE","mdi:video-4k-box"),
|
|
("LOGTO",""),
|
|
]
|
|
|
|
schema={cv.GenerateID(): cv.use_id(tw7100)}
|
|
for name,icon in switches:
|
|
schema.update({cv.Optional(name): switch.switch_schema(tw7100Switch, icon=icon)})
|
|
|
|
CONFIG_SCHEMA = cv.Schema(schema)
|
|
|
|
|
|
async def to_code(config):
|
|
parent = await cg.get_variable(config[CONF_ID])
|
|
|
|
for name,icon in switches:
|
|
if name in config:
|
|
switch_ = await switch.new_switch(config[name])
|
|
cg.add(switch_.set_cmd(name))
|
|
cg.add(switch_.set_tw7100_parent(parent))
|
|
cg.add(getattr(parent, "set_set_{}".format(name.lower()))(switch_))
|