mirror of
https://github.com/esphome/esphome.git
synced 2024-12-04 04:28:19 +01:00
31 lines
976 B
Python
31 lines
976 B
Python
from esphome.components import binary_sensor
|
|
import esphome.config_validation as cv
|
|
import esphome.codegen as cg
|
|
from esphome.const import CONF_ID, CONF_SENSOR_DATAPOINT
|
|
from .. import tuya_ns, CONF_TUYA_ID, Tuya
|
|
|
|
DEPENDENCIES = ["tuya"]
|
|
CODEOWNERS = ["@jesserockz"]
|
|
|
|
TuyaBinarySensor = tuya_ns.class_(
|
|
"TuyaBinarySensor", binary_sensor.BinarySensor, cg.Component
|
|
)
|
|
|
|
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(TuyaBinarySensor),
|
|
cv.GenerateID(CONF_TUYA_ID): cv.use_id(Tuya),
|
|
cv.Required(CONF_SENSOR_DATAPOINT): cv.uint8_t,
|
|
}
|
|
).extend(cv.COMPONENT_SCHEMA)
|
|
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
await cg.register_component(var, config)
|
|
await binary_sensor.register_binary_sensor(var, config)
|
|
|
|
paren = await cg.get_variable(config[CONF_TUYA_ID])
|
|
cg.add(var.set_tuya_parent(paren))
|
|
|
|
cg.add(var.set_sensor_id(config[CONF_SENSOR_DATAPOINT]))
|