1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

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

View File

@@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import switch, uart
from esphome.const import CONF_DATA, CONF_ID, CONF_INVERTED, CONF_SEND_EVERY
from esphome.const import CONF_DATA, CONF_SEND_EVERY
from esphome.core import HexInt
from .. import uart_ns, validate_raw_data
@@ -11,13 +11,10 @@ UARTSwitch = uart_ns.class_("UARTSwitch", switch.Switch, uart.UARTDevice, cg.Com
CONFIG_SCHEMA = (
switch.SWITCH_SCHEMA.extend(
switch.switch_schema(UARTSwitch, block_inverted=True)
.extend(
{
cv.GenerateID(): cv.declare_id(UARTSwitch),
cv.Required(CONF_DATA): validate_raw_data,
cv.Optional(CONF_INVERTED): cv.invalid(
"UART switches do not support inverted mode!"
),
cv.Optional(CONF_SEND_EVERY): cv.positive_time_period_milliseconds,
}
)
@@ -27,9 +24,8 @@ CONFIG_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)
await uart.register_uart_device(var, config)
data = config[CONF_DATA]