esphome-tw7100/text_sensor.py
2024-09-15 20:25:34 +02:00

30 lines
698 B
Python

import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import text_sensor
from esphome.const import (
ENTITY_CATEGORY_DIAGNOSTIC,
CONF_ID,
)
from . import tw7100
DEPENDENCIES = ["tw7100"]
CONF_SERIAL = "serial"
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.use_id(tw7100),
cv.Optional(CONF_SERIAL): text_sensor.text_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC
),
}
)
async def to_code(config):
parent = await cg.get_variable(config[CONF_ID])
if CONF_SERIAL in config:
sens = await text_sensor.new_text_sensor(config[CONF_SERIAL])
cg.add(parent.set_serial(sens))