This commit is contained in:
2024-12-30 10:39:19 +01:00
parent 5112a91bec
commit 64183c33d2
5 changed files with 68 additions and 57 deletions

View File

@@ -4,21 +4,22 @@ from esphome.components import text_sensor
from esphome.const import (
ENTITY_CATEGORY_DIAGNOSTIC,
)
from . import ns, Marlin2
from . import Marlin2
CONF_MARLIN = "marlin2"
CONFIG_SCHEMA = cv.Schema(
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_MARLIN): cv.use_id(Marlin2),
cv.Optional(CONF_CONNECTED): text_sensor.text_sensor(
cv.Optional("printer_state"): text_sensor.text_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
}
)
).extend(cv.polling_component_schema("15s"))
async def to_code(config):
server = await cg.get_variable(config[CONF_MARLIN])
for sName in ["printer_state"]:
if sName in config:
sens = await sensor.new_text_sensor(config[sName])
cg.add(var.add_text_sensor(sName,sens))
sens = await text_sensor.new_text_sensor(config[sName])
cg.add(server.add_text_sensor(sName,sens))