Tidy up switch schemas (#3754)

This commit is contained in:
Jesse Hills
2022-08-31 13:43:46 +12:00
committed by GitHub
parent bd6bc283b6
commit 4d66fab360
17 changed files with 118 additions and 207 deletions
+12 -10
View File
@@ -1,7 +1,7 @@
from esphome.components import switch
import esphome.config_validation as cv
import esphome.codegen as cg
from esphome.const import CONF_ID, CONF_SWITCH_DATAPOINT
from esphome.const import CONF_SWITCH_DATAPOINT
from .. import tuya_ns, CONF_TUYA_ID, Tuya
DEPENDENCIES = ["tuya"]
@@ -9,19 +9,21 @@ CODEOWNERS = ["@jesserockz"]
TuyaSwitch = tuya_ns.class_("TuyaSwitch", switch.Switch, cg.Component)
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(TuyaSwitch),
cv.GenerateID(CONF_TUYA_ID): cv.use_id(Tuya),
cv.Required(CONF_SWITCH_DATAPOINT): cv.uint8_t,
}
).extend(cv.COMPONENT_SCHEMA)
CONFIG_SCHEMA = (
switch.switch_schema(TuyaSwitch)
.extend(
{
cv.GenerateID(CONF_TUYA_ID): cv.use_id(Tuya),
cv.Required(CONF_SWITCH_DATAPOINT): cv.uint8_t,
}
)
.extend(cv.COMPONENT_SCHEMA)
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
var = await switch.new_switch(config)
await cg.register_component(var, config)
await switch.register_switch(var, config)
paren = await cg.get_variable(config[CONF_TUYA_ID])
cg.add(var.set_tuya_parent(paren))