std::string MarlinOutput;
This commit is contained in:
parent
dc63017a83
commit
1f9dffc4f3
12
marlin2.cpp
12
marlin2.cpp
@ -90,14 +90,14 @@ namespace esphome {
|
||||
if(bed_set_temperature==0.0 && ext_set_temperature==0.0) {
|
||||
if(ext_temperature < 32.0 && bed_temperature < 32.0) //TODO define constants for these
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('IDLE');
|
||||
find_sensor("printer_status")->publish_state("IDLE");
|
||||
else if(ext_temperature < 150.0 && bed_temperature < 55.0)
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('COOLING');
|
||||
find_sensor("printer_status")->publish_state("COOLING");
|
||||
}
|
||||
if(bed_set_temperature!=0.0 || ext_set_temperature!=0.0) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('PREHEATING');
|
||||
find_sensor("printer_status")->publish_state("PREHEATING");
|
||||
}
|
||||
|
||||
//reset string for next line
|
||||
@ -142,7 +142,7 @@ namespace esphome {
|
||||
//Print Finished
|
||||
if(MarlinOutput.find("Done printing") != std::string::npos) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('FINISHED');
|
||||
find_sensor("printer_status")->publish_state("FINISHED");
|
||||
|
||||
ESP_LOGD(TAG, "Print Finished");
|
||||
|
||||
@ -154,7 +154,7 @@ namespace esphome {
|
||||
//Print Paused
|
||||
if(MarlinOutput.find("Printer halted") != std::string::npos) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('PAUSED');
|
||||
find_sensor("printer_status")->publish_state("PAUSED");
|
||||
|
||||
ESP_LOGD(TAG, "Print Finished");
|
||||
|
||||
@ -166,7 +166,7 @@ namespace esphome {
|
||||
//Print Stoped
|
||||
if(MarlinOutput.find("Print Aborted") != std::string::npos) {
|
||||
if (find_sensor("printer_status") != nullptr)
|
||||
find_sensor("printer_status")->publish_state('ABOARTED');
|
||||
find_sensor("printer_status")->publish_state("ABOARTED");
|
||||
|
||||
ESP_LOGD(TAG, "Print Finished");
|
||||
|
||||
|
@ -21,6 +21,7 @@ class Marlin2 : public PollingComponent , public uart::UARTDevice {
|
||||
int process_print_time_msg(int* d, int* h, int* m, unsigned long* current, unsigned long* remaining);
|
||||
|
||||
std::string MarlinOutput;
|
||||
std::string MarlinTime;
|
||||
std::string PrinterState;
|
||||
|
||||
std::vector<std::pair<std::string, sensor::Sensor *>> sensors;
|
||||
|
14
sensor.py
14
sensor.py
@ -15,7 +15,8 @@ from esphome.const import (
|
||||
UNIT_PERCENT,
|
||||
UNIT_SECOND,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
DEVICE_CLASS_TEMPERATURE
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_DURATION,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@jonatanrek"]
|
||||
@ -69,13 +70,13 @@ CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend(
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PRINT_TIME): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_SECONDS,
|
||||
unit_of_measurement=UNIT_SECOND,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_DURATION,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PRINT_TIME_REMAINING): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_SECONDS,
|
||||
unit_of_measurement=UNIT_SECOND,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_DURATION,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
@ -93,4 +94,9 @@ async def to_code(config):
|
||||
for sName in [CONF_BED_TEMPERATURE, CONF_BED_SET_TEMPERATURE, CONF_EXT_TEMPERATURE, CONF_EXT_SET_TEMPERATURE, CONF_PRINT_PROGRESS, CONF_PRINT_TIME, CONF_PRINT_TIME_REMAINING]:
|
||||
if sName in config:
|
||||
sens = await sensor.new_sensor(config[sName])
|
||||
cg.add(var.add_sensor(sName,sens))
|
||||
cg.add(var.add_sensor(sName,sens))
|
||||
|
||||
for sName in [CONF_PRINTER_STATUS]:
|
||||
if sName in config:
|
||||
sens = await sensor.new_text_sensor(config[sName])
|
||||
cg.add(var.add_textsensor(sName,sens))
|
Loading…
Reference in New Issue
Block a user