From fafc3d54f6fe6ec409205fd13831b3f9804fdb69 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Fri, 27 Dec 2024 10:51:18 +0100 Subject: [PATCH] init --- marlin2.cpp | 0 marlin2.h | 0 sensor.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 marlin2.cpp create mode 100644 marlin2.h create mode 100644 sensor.py diff --git a/marlin2.cpp b/marlin2.cpp new file mode 100644 index 0000000..e69de29 diff --git a/marlin2.h b/marlin2.h new file mode 100644 index 0000000..e69de29 diff --git a/sensor.py b/sensor.py new file mode 100644 index 0000000..c72ca37 --- /dev/null +++ b/sensor.py @@ -0,0 +1,34 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome import pins +from esphome.components import sensor +from esphome.const import ( + CONF_ID, + CONF_MODEL, + CONF_PIN, + CONF_TEMPERATURE, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, + UNIT_PERCENT, + DEVICE_CLASS_TEMPERATURE, +) + +CONFIG_SCHEMA = cv.Schema( + { + 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, + ), + } +).extend(cv.polling_component_schema("60s")) + +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) + for conf in config[CONF_SENSORS]: + sens = await sensor.new_sensor(conf) + index = conf[CONF_INDEX] + cg.add(var.add_sensor(index, sens)) \ No newline at end of file