Skip to content

Commit 55e2271

Browse files
author
Stéphane
committed
Add delayed shutdown delay
1 parent 7a548d9 commit 55e2271

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

octoprint_phom/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def get_settings_defaults(self):
3636
auto_off_nozzle_temp = 50,
3737
auto_connect = False,
3838
auto_connect_time = 5,
39+
auto_off_delay = 2,
3940
security_connection_lost = False,
4041
security_emergency_stop = True,
4142
security_nozzle_temp = 250,
@@ -254,7 +255,7 @@ def on_api_get(self, request):
254255
else:
255256
return flask.jsonify(error="Invalid command")
256257

257-
### Extinction automatique
258+
### Auto shutdown
258259
def on_event(self, event, payload):
259260
if(event == "PrintDone"):
260261
if(self._settings.get(['auto_off']) == True):
@@ -287,6 +288,10 @@ def turn_off(self):
287288
turned_off = True
288289
elif(self._settings.get(['auto_off_type']) == 'delayed'):
289290
address = "/api/{}/lights/{}/state".format(self._settings.get(['hue_token']), self._settings.get(['light_id']))
291+
if(len(self._settings.get(['auto_off_delay'])) == 1):
292+
time = f"PT00:0{self._settings.get(['auto_off_delay'])}:00"
293+
elif(len(self._settings.get(['auto_off_delay'])) == 2):
294+
time = f"PT00:{self._settings.get(['auto_off_delay'])}:00"
290295
data = {
291296
"name": "Power Off Printer",
292297
"description": "Automatic shutdown initiate by OctoPrint",
@@ -297,7 +302,7 @@ def turn_off(self):
297302
},
298303
"method": "PUT"
299304
},
300-
"time": "PT00:02:00"
305+
"time": time
301306
}
302307
requests.post("http://{}/api/{}/schedules/".format(self._settings.get(['hue_ip']), self._settings.get(['hue_token'])), json=data)
303308
import os

octoprint_phom/templates/ophom_settings.jinja2

+12-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,18 @@ Hue Bridge Status: <span id="ophom_generalstatus" class="badge badge-danger" sty
127127
<label class="radio">
128128
<input type="radio" name="optionsRadios" id="optionsRadios2" value="delayed" data-bind="checked: settings.plugins.ophom.auto_off_type">
129129
Delayed power off with system shutdown
130-
<small><font class="text-info">Usefull if you have a Raspberry Pi powered to printer PSU</font><br />This option will create a power off task on the bridge (2 minutes later) and Shutdown the system (the command must be defined in Settings -> Server)</small>
130+
<small><font class="text-info">Usefull if you have a Raspberry Pi powered to printer PSU</font><br />This option will create a power off task on the bridge and Shutdown the system (the command must be defined in Settings -> Server)</small>
131+
<table>
132+
<tr>
133+
<td>Delay before shutdown: </td>
134+
<td>
135+
<div class="input-append">
136+
<input class="form-control form-control-sm col-xs-1" id="auto_off_delay" type="number" data-bind="value: settings.plugins.ophom.auto_off_delay" style="width: 40px;">
137+
<span class="add-on">minutes</span>
138+
</div>
139+
</td>
140+
</tr>
141+
</table>
131142
</label>
132143
</div>
133144

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "Ophom"
1515

1616
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17-
plugin_version = "1.4.2"
17+
plugin_version = "1.5.0"
1818

1919
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
2020
# module

0 commit comments

Comments
 (0)