ESPHomeMarlin2/text_sensor.py

25 lines
769 B
Python
Raw Permalink Normal View History

2024-12-30 08:42:31 +00:00
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import text_sensor
from esphome.const import (
ENTITY_CATEGORY_DIAGNOSTIC,
)
2024-12-30 09:39:19 +00:00
from . import Marlin2
2024-12-30 08:42:31 +00:00
CONF_MARLIN = "marlin2"
2024-12-30 09:39:19 +00:00
CONFIG_SCHEMA = cv.Schema(
2024-12-30 08:42:31 +00:00
{
cv.GenerateID(CONF_MARLIN): cv.use_id(Marlin2),
2024-12-30 09:39:19 +00:00
cv.Optional("printer_state"): text_sensor.text_sensor_schema(
2024-12-30 08:42:31 +00:00
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
}
2024-12-30 09:39:19 +00:00
).extend(cv.polling_component_schema("15s"))
2024-12-30 08:42:31 +00:00
async def to_code(config):
server = await cg.get_variable(config[CONF_MARLIN])
2024-12-30 09:39:19 +00:00
2024-12-30 08:42:31 +00:00
for sName in ["printer_state"]:
if sName in config:
2024-12-30 09:39:19 +00:00
sens = await text_sensor.new_text_sensor(config[sName])
cg.add(server.add_text_sensor(sName,sens))