1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-16 14:55:50 +00:00

[debug] Refactor debug sensors to use the normal sensor model. (#3162)

This commit is contained in:
mknjc
2022-02-08 00:45:27 +01:00
committed by GitHub
parent 253161d3d0
commit 1e5004f495
5 changed files with 119 additions and 41 deletions

View File

@@ -0,0 +1,29 @@
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 . import CONF_DEBUG_ID, DebugComponent
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)}
),
}
)
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])
cg.add(debug_component.set_device_info_sensor(sens))