From 1d31a8b63fbffe4ef0acff0c29a796119bae63ac Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Fri, 27 Dec 2024 11:35:43 +0100 Subject: [PATCH] Progress --- README.md | 21 +++++++++++++++++++++ sensor.py | 19 ++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b3b61a0 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# A component that reads CSV values from the uart. + +A configured uart is required. + +Configure a list of sensors. The index is required, the rest is the standard sensor config. + +Example: +```yaml +sensor: + - platform: serial_csv + uart_id: my_uart # optional + sensors: + - index: 0 + name: First value + - index: 3 + name: Fourth value +``` + + +https://github.com/ssieb/esphome_components/tree/master/components/serial_csv +https://github.com/esphome/esphome/blob/dev/esphome/components/dht/sensor.py#L34 diff --git a/sensor.py b/sensor.py index 6278aba..ca940d0 100644 --- a/sensor.py +++ b/sensor.py @@ -3,25 +3,26 @@ import esphome.config_validation as cv from esphome import automation from esphome.components import uart from esphome.components import sensor -from esphome.const import CONF_ID, CONF_INDEX, CONF_SENSORS +from esphome.const import CONF_ID, CONF_INDEX, CONF_SENSORS, CONF_HUMIDITY, CONF_MODEL, CONF_PIN, CONF_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, DEVICE_CLASS_TEMPERATURE -CODEOWNERS = ["@ssieb"] +CODEOWNERS = ["@jonatanrek"] DEPENDENCIES = ['uart'] serial_ns = cg.esphome_ns.namespace('serial') -SerialCSV = serial_ns.class_('SerialCSV', cg.Component, sensor.Sensor, uart.UARTDevice) +Marlin2 = serial_ns.class_('Marlin2', cg.Component, sensor.Sensor, uart.UARTDevice) CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend( { - cv.GenerateID(): cv.declare_id(SerialCSV), + cv.GenerateID(): cv.declare_id(Marlin2), cv.Required(CONF_SENSORS): cv.ensure_list( - sensor.SENSOR_SCHEMA.extend( - { - cv.Required(CONF_INDEX): cv.positive_int, - } - ) + cv.Optional("bed_current"): sensor.sensor_schema( + unit_of_measurement=UNIT_CELSIUS, + accuracy_decimals=1, + device_class=DEVICE_CLASS_TEMPERATURE, + state_class=STATE_CLASS_MEASUREMENT, + ), ), } )