2019-04-17 12:06:00 +02:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import text_sensor
|
2021-11-07 19:24:52 +01:00
|
|
|
from esphome.const import (
|
|
|
|
ENTITY_CATEGORY_DIAGNOSTIC,
|
|
|
|
ICON_NEW_BOX,
|
|
|
|
CONF_HIDE_TIMESTAMP,
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
version_ns = cg.esphome_ns.namespace("version")
|
|
|
|
VersionTextSensor = version_ns.class_(
|
|
|
|
"VersionTextSensor", text_sensor.TextSensor, cg.Component
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2022-02-08 05:23:45 +01:00
|
|
|
CONFIG_SCHEMA = (
|
|
|
|
text_sensor.text_sensor_schema(
|
|
|
|
icon=ICON_NEW_BOX,
|
|
|
|
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
|
|
|
)
|
|
|
|
.extend(
|
|
|
|
{
|
|
|
|
cv.GenerateID(): cv.declare_id(VersionTextSensor),
|
|
|
|
cv.Optional(CONF_HIDE_TIMESTAMP, default=False): cv.boolean,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.extend(cv.COMPONENT_SCHEMA)
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
async def to_code(config):
|
2022-02-08 05:23:45 +01:00
|
|
|
var = await text_sensor.new_text_sensor(config)
|
2021-05-24 10:58:29 +02:00
|
|
|
await cg.register_component(var, config)
|
2020-07-12 00:55:30 +02:00
|
|
|
cg.add(var.set_hide_timestamp(config[CONF_HIDE_TIMESTAMP]))
|