diff --git a/marlin2.cpp b/marlin2.cpp index 34dc8ec..e072d0f 100644 --- a/marlin2.cpp +++ b/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"); diff --git a/marlin2.h b/marlin2.h index a5e278d..a4a9c77 100644 --- a/marlin2.h +++ b/marlin2.h @@ -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> sensors; diff --git a/sensor.py b/sensor.py index 75b5875..1bdaf77 100644 --- a/sensor.py +++ b/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)) \ No newline at end of file + 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)) \ No newline at end of file