Преглед изворни кода

also check if temperature is still high before turning off

Thomas Buck пре 3 година
родитељ
комит
46a222bacd
1 измењених фајлова са 33 додато и 7 уклоњено
  1. 33
    7
      src/octotray.py

+ 33
- 7
src/octotray.py Прегледај датотеку

@@ -482,6 +482,23 @@ class OctoTray():
482 482
         }
483 483
         return self.sendRequest(host, headers, path)
484 484
 
485
+    def getTemperatureIsSafe(self, host, key):
486
+        r = self.sendGetRequest(host, key, "printer")
487
+        try:
488
+            rd = json.loads(r)
489
+
490
+            if "temperature" in rd:
491
+                if ("tool0" in rd["temperature"]) and ("actual" in rd["temperature"]["tool0"]):
492
+                    if rd["temperature"]["tool0"]["actual"] > 50.0:
493
+                        return False
494
+
495
+                if ("tool1" in rd["temperature"]) and ("actual" in rd["temperature"]["tool1"]):
496
+                    if rd["temperature"]["tool1"]["actual"] > 50.0:
497
+                        return False
498
+        except json.JSONDecodeError:
499
+            pass
500
+        return True
501
+
485 502
     def getTemperatureString(self, host, key):
486 503
         r = self.sendGetRequest(host, key, "printer")
487 504
         s = ""
@@ -619,10 +636,14 @@ class OctoTray():
619 636
         if "off" in item[2][index].lower():
620 637
             state = self.getState(item[0], item[1])
621 638
             if state in self.statesWithWarning:
622
-                if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to run '" + item[2][index] + "'?", True, True) == True:
623
-                    self.setSystemCommand(item[0], item[1], item[2][index])
624
-                else:
639
+                if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to run '" + item[2][index] + "'?", True, True) == False:
640
+                    return
641
+
642
+            safe = self.getTemperatureIsSafe(item[0], item[1])
643
+            if safe == False:
644
+                if self.showDialog("OctoTray Warning", "The printer seems to still be hot!", "Do you really want to turn it off?", True, True) == False:
625 645
                     return
646
+
626 647
         self.setSystemCommand(item[0], item[1], item[2][index])
627 648
 
628 649
     def printerOnAction(self, item):
@@ -631,10 +652,15 @@ class OctoTray():
631 652
     def printerOffAction(self, item):
632 653
         state = self.getState(item[0], item[1])
633 654
         if state in self.statesWithWarning:
634
-            if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to turn it off?", True, True) == True:
635
-                self.setPSUControl(item[0], item[1], False)
636
-        else:
637
-            self.setPSUControl(item[0], item[1], False)
655
+            if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to turn it off?", True, True) == False:
656
+                return
657
+
658
+        safe = self.getTemperatureIsSafe(item[0], item[1])
659
+        if safe == False:
660
+            if self.showDialog("OctoTray Warning", "The printer seems to still be hot!", "Do you really want to turn it off?", True, True) == False:
661
+                return
662
+
663
+        self.setPSUControl(item[0], item[1], False)
638 664
 
639 665
     def printerWebAction(self, item):
640 666
         self.openBrowser(item[0])

Loading…
Откажи
Сачувај