ESPHome external component for Samsung 2x20 serial VFD
Component (components/samsung_vfd), example device config, README and CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
bd9389e04a
9 files changed
+796
No files matched your search
@@ -0,0 +1,124 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.components import time as time_, uart
|
||||
from esphome.const import CONF_ID, CONF_TEXT, CONF_TIME_ID
|
||||
|
||||
DEPENDENCIES = ["uart", "time"]
|
||||
|
||||
CONF_COLS = "cols"
|
||||
CONF_ROWS = "rows"
|
||||
CONF_LINE = "line"
|
||||
CONF_FORMAT = "format"
|
||||
CONF_CENTERED = "centered"
|
||||
CONF_SEND_NEWLINES = "send_newlines"
|
||||
|
||||
samsung_vfd_ns = cg.esphome_ns.namespace("samsung_vfd")
|
||||
|
||||
SamsungVfd = samsung_vfd_ns.class_("SamsungVfd", cg.Component, uart.UARTDevice)
|
||||
|
||||
PrintAction = samsung_vfd_ns.class_("PrintAction", automation.Action)
|
||||
PrintfAction = samsung_vfd_ns.class_("PrintfAction", automation.Action)
|
||||
ClearAction = samsung_vfd_ns.class_("ClearAction", automation.Action)
|
||||
HomeAction = samsung_vfd_ns.class_("HomeAction", automation.Action)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(SamsungVfd),
|
||||
cv.Optional(CONF_COLS, default=20): cv.int_range(min=1, max=80),
|
||||
cv.Optional(CONF_ROWS, default=2): cv.int_range(min=1, max=8),
|
||||
# Off by default: lines are padded to exactly `cols` characters and the
|
||||
# display wraps to the next line by itself.
|
||||
cv.Optional(CONF_SEND_NEWLINES, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
)
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
||||
"samsung_vfd", baud_rate=9600, require_tx=True
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
||||
cg.add(var.set_size(config[CONF_COLS], config[CONF_ROWS]))
|
||||
cg.add(var.set_send_newlines(config[CONF_SEND_NEWLINES]))
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"samsung_vfd.print",
|
||||
PrintAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(SamsungVfd),
|
||||
cv.Required(CONF_TEXT): cv.templatable(cv.string),
|
||||
cv.Optional(CONF_LINE): cv.templatable(cv.int_range(min=0, max=7)),
|
||||
cv.Optional(CONF_CENTERED): cv.templatable(cv.boolean),
|
||||
}
|
||||
),
|
||||
synchronous=True,
|
||||
)
|
||||
async def samsung_vfd_print_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
cg.add(var.set_text(await cg.templatable(config[CONF_TEXT], args, cg.std_string)))
|
||||
if CONF_LINE in config:
|
||||
cg.add(var.set_line(await cg.templatable(config[CONF_LINE], args, cg.int_)))
|
||||
if CONF_CENTERED in config:
|
||||
cg.add(var.set_centered(await cg.templatable(config[CONF_CENTERED], args, cg.bool_)))
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"samsung_vfd.printf",
|
||||
PrintfAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(SamsungVfd),
|
||||
cv.Required(CONF_TIME_ID): cv.use_id(time_.RealTimeClock),
|
||||
cv.Required(CONF_FORMAT): cv.templatable(cv.string),
|
||||
cv.Optional(CONF_LINE): cv.templatable(cv.int_range(min=0, max=7)),
|
||||
cv.Optional(CONF_CENTERED): cv.templatable(cv.boolean),
|
||||
}
|
||||
),
|
||||
synchronous=True,
|
||||
)
|
||||
async def samsung_vfd_printf_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
cg.add(var.set_time(await cg.get_variable(config[CONF_TIME_ID])))
|
||||
cg.add(var.set_format(await cg.templatable(config[CONF_FORMAT], args, cg.std_string)))
|
||||
if CONF_LINE in config:
|
||||
cg.add(var.set_line(await cg.templatable(config[CONF_LINE], args, cg.int_)))
|
||||
if CONF_CENTERED in config:
|
||||
cg.add(var.set_centered(await cg.templatable(config[CONF_CENTERED], args, cg.bool_)))
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"samsung_vfd.clear",
|
||||
ClearAction,
|
||||
cv.Schema({cv.Required(CONF_ID): cv.use_id(SamsungVfd)}),
|
||||
synchronous=True,
|
||||
)
|
||||
async def samsung_vfd_clear_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"samsung_vfd.home",
|
||||
HomeAction,
|
||||
cv.Schema({cv.Required(CONF_ID): cv.use_id(SamsungVfd)}),
|
||||
synchronous=True,
|
||||
)
|
||||
async def samsung_vfd_home_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
Reference in new issue
Block a user