mirror of
https://github.com/esphome/esphome.git
synced 2025-09-19 11:42:20 +01:00
Text sensor schema generator similar to sensor (#3172)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
from esphome.components import text_sensor
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_DEVICE,
|
||||
)
|
||||
from esphome.const import CONF_DEVICE
|
||||
|
||||
from . import CONF_DEBUG_ID, DebugComponent
|
||||
|
||||
DEPENDENCIES = ["debug"]
|
||||
@@ -13,9 +11,7 @@ DEPENDENCIES = ["debug"]
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent),
|
||||
cv.Optional(CONF_DEVICE): text_sensor.TEXT_SENSOR_SCHEMA.extend(
|
||||
{cv.GenerateID(): cv.declare_id(text_sensor.TextSensor)}
|
||||
),
|
||||
cv.Optional(CONF_DEVICE): text_sensor.text_sensor_schema(),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -24,6 +20,5 @@ async def to_code(config):
|
||||
debug_component = await cg.get_variable(config[CONF_DEBUG_ID])
|
||||
|
||||
if CONF_DEVICE in config:
|
||||
sens = cg.new_Pvariable(config[CONF_DEVICE][CONF_ID])
|
||||
await text_sensor.register_text_sensor(sens, config[CONF_DEVICE])
|
||||
sens = await text_sensor.new_text_sensor(config[CONF_DEVICE])
|
||||
cg.add(debug_component.set_device_info_sensor(sens))
|
||||
|
Reference in New Issue
Block a user