ESPHomeMarlin2/sensor.py

47 lines
1.2 KiB
Python
Raw Normal View History

2024-12-27 09:51:18 +00:00
import esphome.codegen as cg
import esphome.config_validation as cv
2024-12-27 09:55:11 +00:00
from esphome import automation
from esphome.components import uart
2024-12-27 09:51:18 +00:00
from esphome.components import sensor
2024-12-27 11:02:11 +00:00
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
)
2024-12-27 09:55:11 +00:00
2024-12-27 10:35:43 +00:00
CODEOWNERS = ["@jonatanrek"]
2024-12-27 09:55:11 +00:00
DEPENDENCIES = ['uart']
2024-12-27 10:47:42 +00:00
CONF_BED_TEMPERATURE = "bed_temperature"
2024-12-27 11:21:33 +00:00
Marlin2 = cg.esphome_ns.class_('Marlin2', cg.Component, sensor.Sensor, uart.UARTDevice)
2024-12-27 09:51:18 +00:00
2024-12-27 10:26:06 +00:00
CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend(
2024-12-27 09:51:18 +00:00
{
2024-12-27 10:35:43 +00:00
cv.GenerateID(): cv.declare_id(Marlin2),
2024-12-27 10:47:42 +00:00
cv.Optional(CONF_BED_TEMPERATURE): sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS,
accuracy_decimals=1,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
2024-12-27 09:51:18 +00:00
),
}
2024-12-27 10:26:06 +00:00
)
2024-12-27 09:55:11 +00:00
2024-12-27 09:51:18 +00:00
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)
2024-12-27 10:47:42 +00:00
if CONF_BED_TEMPERATURE in config:
2024-12-27 11:21:33 +00:00
await sensor.new_sensor(config[CONF_BED_TEMPERATURE])