Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e7bf0762d3 | ||
|
96fdafb2dc | ||
|
c5d8bbd863 | ||
|
dda93e73d3 | ||
|
96c2e954fa | ||
|
107a7ba9de | ||
|
809369f783 | ||
|
617f21a66e | ||
|
66889083fd | ||
|
1f5efa9c2a | ||
|
284d54ffa0 | ||
|
542a633559 | ||
|
6c208ce10b | ||
|
7d80c84393 | ||
|
b3e53821bb | ||
|
be81f64ec1 | ||
|
ca61b89b3f | ||
|
330577cc6e | ||
|
5fe040d455 | ||
|
5298d96d26 | ||
|
778821e5e5 | ||
|
72de3c4db6 | ||
|
f30e769f6a | ||
|
c9608fa24f | ||
|
af7a581620 | ||
|
cba3367d2b | ||
|
0816056ded | ||
|
92fd2846ac | ||
|
85e18076a0 | ||
|
ba797fe1cc |
289
.idea/workspace.xml
generated
289
.idea/workspace.xml
generated
@ -3,7 +3,6 @@
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="7e2e0eec-b22e-4d48-8f24-196d1ed9b51a" name="Default Changelist" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -48,146 +47,6 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1574193087583</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00036" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
||||
<created>1574609901438</created>
|
||||
<option name="number" value="00036" />
|
||||
<option name="presentableId" value="LOCAL-00036" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574609901438</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00037" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
||||
<created>1574610253466</created>
|
||||
<option name="number" value="00037" />
|
||||
<option name="presentableId" value="LOCAL-00037" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574610253466</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00038" summary="#9 Relais ausschalten wenn Octoprint heruntergefahren wird #7 Relais einschalten wenn Octoprint gestartet wurde">
|
||||
<created>1574707150761</created>
|
||||
<option name="number" value="00038" />
|
||||
<option name="presentableId" value="LOCAL-00038" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574707150761</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00039" summary="#9 Relais ausschalten wenn Octoprint heruntergefahren wird #7 Relais einschalten wenn Octoprint gestartet wurde">
|
||||
<created>1574707411686</created>
|
||||
<option name="number" value="00039" />
|
||||
<option name="presentableId" value="LOCAL-00039" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574707411686</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00040" summary="#9 Relais ausschalten wenn Octoprint heruntergefahren wird #7 Relais einschalten wenn Octoprint gestartet wurde Logging schreibfehler Url Fix für Powercycle">
|
||||
<created>1574707826329</created>
|
||||
<option name="number" value="00040" />
|
||||
<option name="presentableId" value="LOCAL-00040" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574707826329</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00041" summary="#9 Relais ausschalten wenn Octoprint heruntergefahren wird #7 Relais einschalten wenn Octoprint gestartet wurde">
|
||||
<created>1574708023156</created>
|
||||
<option name="number" value="00041" />
|
||||
<option name="presentableId" value="LOCAL-00041" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574708023156</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00042" summary="#9 Relais ausschalten wenn Octoprint heruntergefahren wird #7 Relais einschalten wenn Octoprint gestartet wurde Api call fix">
|
||||
<created>1574708245896</created>
|
||||
<option name="number" value="00042" />
|
||||
<option name="presentableId" value="LOCAL-00042" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574708245896</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00043" summary="#9 Relais ausschalten wenn Octoprint heruntergefahren wird #7 Relais einschalten wenn Octoprint gestartet wurde Api call fix">
|
||||
<created>1574708497039</created>
|
||||
<option name="number" value="00043" />
|
||||
<option name="presentableId" value="LOCAL-00043" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574708497039</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00044" summary="#13 Wenn Request fehlschägt max. 3x versuchen">
|
||||
<created>1574710870028</created>
|
||||
<option name="number" value="00044" />
|
||||
<option name="presentableId" value="LOCAL-00044" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574710870028</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00045" summary="#11 Energieverbrauch näherungsweise berechnen">
|
||||
<created>1574712024409</created>
|
||||
<option name="number" value="00045" />
|
||||
<option name="presentableId" value="LOCAL-00045" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574712024409</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00046" summary="#11 Energieverbrauch näherungsweise berechnen">
|
||||
<created>1574712205852</created>
|
||||
<option name="number" value="00046" />
|
||||
<option name="presentableId" value="LOCAL-00046" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574712205852</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00047" summary="#14 Einstellungen reorganisieren">
|
||||
<created>1574873790898</created>
|
||||
<option name="number" value="00047" />
|
||||
<option name="presentableId" value="LOCAL-00047" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574873790898</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00048" summary="#14 Einstellungen reorganisieren">
|
||||
<created>1574873809876</created>
|
||||
<option name="number" value="00048" />
|
||||
<option name="presentableId" value="LOCAL-00048" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574873809876</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00049" summary="#14 Einstellungen reorganisieren - Beschreibungen angepasst">
|
||||
<created>1574874286229</created>
|
||||
<option name="number" value="00049" />
|
||||
<option name="presentableId" value="LOCAL-00049" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574874286229</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00050" summary="#15 Beschreibung erstellen">
|
||||
<created>1574876224274</created>
|
||||
<option name="number" value="00050" />
|
||||
<option name="presentableId" value="LOCAL-00050" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574876224274</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00051" summary="#15 Beschreibung erstellen">
|
||||
<created>1574876349466</created>
|
||||
<option name="number" value="00051" />
|
||||
<option name="presentableId" value="LOCAL-00051" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574876349466</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00052" summary="#16 Codereview Octoprint Plugin Repo">
|
||||
<created>1575192543311</created>
|
||||
<option name="number" value="00052" />
|
||||
<option name="presentableId" value="LOCAL-00052" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1575192543311</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00053" summary="#17 Logging zur Fehleranalyse eingebaut">
|
||||
<created>1578938604039</created>
|
||||
<option name="number" value="00053" />
|
||||
<option name="presentableId" value="LOCAL-00053" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1578938604039</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00054" summary="#17 Logging zur Fehleranalyse eingebaut">
|
||||
<created>1578939868815</created>
|
||||
<option name="number" value="00054" />
|
||||
<option name="presentableId" value="LOCAL-00054" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1578939868816</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00055" summary="#17 Logging zur Fehleranalyse eingebaut">
|
||||
<created>1578940345174</created>
|
||||
<option name="number" value="00055" />
|
||||
<option name="presentableId" value="LOCAL-00055" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1578940345174</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00056" summary="#17 Logging zur Fehleranalyse eingebaut">
|
||||
<created>1578941071143</created>
|
||||
<option name="number" value="00056" />
|
||||
@ -391,7 +250,147 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593354891881</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="85" />
|
||||
<task id="LOCAL-00085" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593356663020</created>
|
||||
<option name="number" value="00085" />
|
||||
<option name="presentableId" value="LOCAL-00085" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593356663020</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00086" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593627018087</created>
|
||||
<option name="number" value="00086" />
|
||||
<option name="presentableId" value="LOCAL-00086" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593627018088</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00087" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593627195608</created>
|
||||
<option name="number" value="00087" />
|
||||
<option name="presentableId" value="LOCAL-00087" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593627195608</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00088" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593628251128</created>
|
||||
<option name="number" value="00088" />
|
||||
<option name="presentableId" value="LOCAL-00088" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593628251128</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00089" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593628347105</created>
|
||||
<option name="number" value="00089" />
|
||||
<option name="presentableId" value="LOCAL-00089" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593628347105</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00090" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593628617461</created>
|
||||
<option name="number" value="00090" />
|
||||
<option name="presentableId" value="LOCAL-00090" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593628617461</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00091" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593629014910</created>
|
||||
<option name="number" value="00091" />
|
||||
<option name="presentableId" value="LOCAL-00091" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593629014910</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00092" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593629188987</created>
|
||||
<option name="number" value="00092" />
|
||||
<option name="presentableId" value="LOCAL-00092" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593629188987</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00093" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593629352018</created>
|
||||
<option name="number" value="00093" />
|
||||
<option name="presentableId" value="LOCAL-00093" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593629352018</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00094" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593629491361</created>
|
||||
<option name="number" value="00094" />
|
||||
<option name="presentableId" value="LOCAL-00094" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593629491361</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00095" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593629609079</created>
|
||||
<option name="number" value="00095" />
|
||||
<option name="presentableId" value="LOCAL-00095" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593629609079</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00096" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593630096392</created>
|
||||
<option name="number" value="00096" />
|
||||
<option name="presentableId" value="LOCAL-00096" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593630096392</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00097" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593630227011</created>
|
||||
<option name="number" value="00097" />
|
||||
<option name="presentableId" value="LOCAL-00097" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593630227011</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00098" summary="#24 API Token Support">
|
||||
<created>1593630650365</created>
|
||||
<option name="number" value="00098" />
|
||||
<option name="presentableId" value="LOCAL-00098" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593630650365</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00099" summary="#24 API Token Support">
|
||||
<created>1593631193159</created>
|
||||
<option name="number" value="00099" />
|
||||
<option name="presentableId" value="LOCAL-00099" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593631193159</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00100" summary="#24 API Token Support">
|
||||
<created>1593631506549</created>
|
||||
<option name="number" value="00100" />
|
||||
<option name="presentableId" value="LOCAL-00100" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593631506549</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00101" summary="#24 API Token Support">
|
||||
<created>1593631764282</created>
|
||||
<option name="number" value="00101" />
|
||||
<option name="presentableId" value="LOCAL-00101" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593631764282</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00102" summary="#24 API Token Support">
|
||||
<created>1593632006106</created>
|
||||
<option name="number" value="00102" />
|
||||
<option name="presentableId" value="LOCAL-00102" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593632006106</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00103" summary="#25 Python 3 Compatibility">
|
||||
<created>1593633576198</created>
|
||||
<option name="number" value="00103" />
|
||||
<option name="presentableId" value="LOCAL-00103" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593633576198</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00104" summary="#25 Python 3 Compatibility">
|
||||
<created>1593633696895</created>
|
||||
<option name="number" value="00104" />
|
||||
<option name="presentableId" value="LOCAL-00104" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593633696895</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="105" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="UnknownFeatures">
|
||||
@ -421,8 +420,6 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="#5 Rest Api integration - Bugfix plugin_requires" />
|
||||
<MESSAGE value="#5 Rest Api integration - Nullpointer fix" />
|
||||
<MESSAGE value="#6 UI Updates senden und anzeigen - unnötigen Code entfernen, erster Versuch" />
|
||||
<MESSAGE value="Revert "#6 UI Updates senden und anzeigen" This reverts commit f83d4259" />
|
||||
<MESSAGE value="#6 UI Updates senden und anzeigen" />
|
||||
@ -446,6 +443,8 @@
|
||||
<MESSAGE value="#21 Add PowerOFF when print is finished neue Einstellmöglichkeiten anzeigen" />
|
||||
<MESSAGE value="#22 Button taucht nicht auf Fehler anzeigen wenn Verbindung zu switch nicht klappt" />
|
||||
<MESSAGE value="#21 Add PowerOFF when print is finished" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="#21 Add PowerOFF when print is finished" />
|
||||
<MESSAGE value="#24 API Token Support" />
|
||||
<MESSAGE value="#25 Python 3 Compatibility" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="#25 Python 3 Compatibility" />
|
||||
</component>
|
||||
</project>
|
@ -19,6 +19,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
|
||||
def __init__(self):
|
||||
self.ip = None
|
||||
self.token = ""
|
||||
self.intervall = 1
|
||||
self.onOffButtonEnabled = False
|
||||
self.powerOnOnStart = False
|
||||
@ -27,8 +28,13 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self.showShutdownOctopiOption = False
|
||||
self.showPowerOffPrintFinishOption = False
|
||||
self.shutdownDelay = 60
|
||||
self.shutdownAfterPrintFinished = False
|
||||
self.powerOffAfterPrintFinished = False
|
||||
|
||||
self.rememberShutdown = False
|
||||
self.lastPowerOff = False
|
||||
self.lastShutdown = False
|
||||
|
||||
self.shutdownAfterPrintFinished = self.lastShutdown if self.rememberShutdown else False
|
||||
self.powerOffAfterPrintFinished = self.lastPowerOff if self.rememberShutdown else False
|
||||
|
||||
self._status_timer = None
|
||||
self._abort_timer = None
|
||||
@ -45,6 +51,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self.ip = self._settings.get(["ip"])
|
||||
self._logger.debug("ip: %s" % self.ip)
|
||||
|
||||
self.token = self._settings.get(["token"])
|
||||
self._logger.debug("token: %s" % self.token)
|
||||
|
||||
self.intervall = self._settings.get_int(["intervall"])
|
||||
self._logger.debug("intervall: %s" % self.intervall)
|
||||
|
||||
@ -69,6 +78,19 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self.shutdownDelay = self._settings.get_int(["shutdownDelay"])
|
||||
self._logger.debug("shutdownDelay: %s" % self.shutdownDelay)
|
||||
|
||||
self.rememberShutdown = self._settings.get_boolean(["rememberShutdown"])
|
||||
self._logger.info("rememberShutdown: %s" % self.rememberShutdown)
|
||||
|
||||
self.lastPowerOff = self._settings.get_boolean(["lastPowerOff"])
|
||||
self._logger.info("lastPowerOff: %s" % self.lastPowerOff)
|
||||
|
||||
self.lastShutdown = self._settings.get_boolean(["lastShutdown"])
|
||||
self._logger.info("lastShutdown: %s" % self.lastShutdown)
|
||||
|
||||
if self.rememberShutdown:
|
||||
self.powerOffAfterPrintFinished = self.lastPowerOff
|
||||
self.shutdownAfterPrintFinished = self.lastShutdown
|
||||
|
||||
self._status_timer_start()
|
||||
|
||||
def get_assets(self):
|
||||
@ -123,9 +145,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
if self._abort_timer is not None:
|
||||
self._abort_timer.cancel()
|
||||
self._abort_timer = None
|
||||
if self.shutdownAfterPrintFinished:
|
||||
if self.shutdownAfterPrintFinished and self.showShutdownOctopiOption:
|
||||
self._shutdown_system()
|
||||
elif self.powerOffAfterPrintFinished:
|
||||
elif self.powerOffAfterPrintFinished and self.showPowerOffPrintFinishOption:
|
||||
self._logger.info("only Shutdown Relais")
|
||||
self._setRelaisState(False)
|
||||
|
||||
@ -146,18 +168,17 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.info("Shutting down system with command: {command}".format(command=shutdown_command))
|
||||
try:
|
||||
import sarge
|
||||
p = sarge.run(shutdown_command, async=True)
|
||||
p = sarge.run(shutdown_command, async_=True)
|
||||
except Exception as e:
|
||||
self._logger.exception("Error when shutting down: {error}".format(error=e))
|
||||
return
|
||||
|
||||
|
||||
def _status_timer_task(self):
|
||||
if self.ip is not None:
|
||||
try:
|
||||
try:
|
||||
request = requests.get(
|
||||
'http://{}/report'.format(self.ip), timeout=1)
|
||||
'http://{}/report'.format(self.ip), headers={"Token": self.token}, timeout=1)
|
||||
if request.status_code == 200:
|
||||
timestamp = time.time()
|
||||
data = request.json()
|
||||
@ -185,10 +206,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.info("Ip is None")
|
||||
data = {"relay": True, "energy": 0, "onOffButtonEnabled": False, "showShutdownOctopiOption": False,
|
||||
"showPowerOffPrintFinishOption": False, "automaticShutdownEnabled": self.shutdownAfterPrintFinished,
|
||||
"v": self.powerOffAfterPrintFinished}
|
||||
"automaticPowerOffEnabled": self.powerOffAfterPrintFinished}
|
||||
self._plugin_manager.send_plugin_message(self._identifier, data)
|
||||
|
||||
|
||||
def _setRelaisState(self, newState):
|
||||
nbRetry = 0
|
||||
value = '0'
|
||||
@ -196,8 +216,11 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
value = '1'
|
||||
while nbRetry < 3:
|
||||
try:
|
||||
headers = {}
|
||||
if self.token is not None and self.token != "":
|
||||
headers = {"Token": self.token}
|
||||
request = requests.get(
|
||||
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
|
||||
'http://{}/relay'.format(self.ip), params={'state': value}, headers=headers, timeout=1)
|
||||
if request.status_code == 200:
|
||||
return
|
||||
else:
|
||||
@ -207,7 +230,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.info("Error during set Relais state")
|
||||
nbRetry = nbRetry + 1
|
||||
|
||||
|
||||
# Sets the switch to a specific inverse newState,
|
||||
# waits for a specified amount of time (max 3h),
|
||||
# then sets the the switch to the newState.
|
||||
@ -222,7 +244,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.info("try to send Powercycle Request")
|
||||
self._logger.info('http://{}/timer'.format(self.ip))
|
||||
request = requests.post(
|
||||
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
|
||||
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, headers={"Token": self.token},
|
||||
timeout=1)
|
||||
if request.status_code == 200:
|
||||
return
|
||||
else:
|
||||
@ -235,13 +258,12 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.exception(exp)
|
||||
nbRetry = nbRetry + 1
|
||||
|
||||
|
||||
def _toggleRelay(self):
|
||||
nbRetry = 0
|
||||
while nbRetry < 3:
|
||||
try:
|
||||
request = requests.get(
|
||||
'http://{}/toggle'.format(self.ip), timeout=1)
|
||||
'http://{}/toggle'.format(self.ip), headers={"Token": self.token}, timeout=1)
|
||||
if request.status_code == 200:
|
||||
return
|
||||
else:
|
||||
@ -250,7 +272,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.info("Error during toggle Relais state")
|
||||
nbRetry = nbRetry + 1
|
||||
|
||||
|
||||
def on_api_command(self, command, data):
|
||||
if command == "enableRelais":
|
||||
self._logger.info("enableRelais")
|
||||
@ -264,16 +285,31 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
elif command == "enableShutdownAfterFinish":
|
||||
self._logger.info("enableShutdownAfterFinish")
|
||||
self.shutdownAfterPrintFinished = True
|
||||
if self.rememberShutdown:
|
||||
self.lastShutdown = self.shutdownAfterPrintFinished
|
||||
self._settings.set_boolean(["lastShutdown"], self.lastShutdown)
|
||||
self._settings.save()
|
||||
elif command == "disableShutdownAfterFinish":
|
||||
self._logger.info("disableShutdownAfterFinish")
|
||||
self.shutdownAfterPrintFinished = False
|
||||
if self.rememberShutdown:
|
||||
self.lastShutdown = self.shutdownAfterPrintFinished
|
||||
self._settings.set_boolean(["lastShutdown"], self.lastShutdown)
|
||||
self._settings.save()
|
||||
elif command == "enablePowerOffAfterFinish":
|
||||
self._logger.info("enablePowerOffAfterFinish")
|
||||
self.powerOffAfterPrintFinished = True
|
||||
if self.rememberShutdown:
|
||||
self.lastPowerOff = self.powerOffAfterPrintFinished
|
||||
self._settings.set_boolean(["lastPowerOff"], self.lastPowerOff)
|
||||
self._settings.save()
|
||||
elif command == "disablePowerOffAfterFinish":
|
||||
self._logger.info("disablePowerOffAfterFinish")
|
||||
self.powerOffAfterPrintFinished = False
|
||||
|
||||
if self.rememberShutdown:
|
||||
self.lastPowerOff = self.powerOffAfterPrintFinished
|
||||
self._settings.set_boolean(["lastPowerOff"], self.lastPowerOff)
|
||||
self._settings.save()
|
||||
|
||||
def get_api_commands(self):
|
||||
return dict(
|
||||
@ -286,13 +322,11 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
enablePowerOffAfterFinish=[]
|
||||
)
|
||||
|
||||
|
||||
def on_after_startup(self):
|
||||
if self.powerOnOnStart:
|
||||
self._logger.info("Turn on Relais on Start")
|
||||
self._setRelaisState(True)
|
||||
|
||||
|
||||
def on_shutdown(self):
|
||||
self._logger.info("on_shutdown_event")
|
||||
if self.powerOffOnShutdown:
|
||||
@ -303,7 +337,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.info("Turn off Relais on Shutdown Delayed")
|
||||
self._powerCycleRelais(False, self.powerOffDelay)
|
||||
|
||||
|
||||
def on_settings_migrate(self, target, current):
|
||||
if target > current:
|
||||
if current <= 1:
|
||||
@ -316,15 +349,20 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self.showShutdownOctopiOption = False
|
||||
self.showPowerOffPrintFinishOption = False
|
||||
self.shutdownDelay = 60
|
||||
|
||||
if current <= 4:
|
||||
self.lastShutdown = False
|
||||
self.lastPowerOff = False
|
||||
self.rememberShutdown = False
|
||||
if current <= 5:
|
||||
self.token = ""
|
||||
|
||||
def get_settings_version(self):
|
||||
return 4
|
||||
|
||||
return 6
|
||||
|
||||
def get_settings_defaults(self):
|
||||
return dict(
|
||||
ip=None,
|
||||
token="",
|
||||
intervall=1,
|
||||
onOffButtonEnabled=False,
|
||||
powerOnOnStart=False,
|
||||
@ -332,22 +370,22 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
powerOffDelay=0,
|
||||
showShutdownOctopiOption=False,
|
||||
showPowerOffPrintFinishOption=False,
|
||||
shutdownDelay=60
|
||||
shutdownDelay=60,
|
||||
lastShutdown=False,
|
||||
lastPowerOff=False,
|
||||
rememberShutdown=False
|
||||
)
|
||||
|
||||
|
||||
def get_settings_restricted_paths(self):
|
||||
return dict(admin=[
|
||||
['ip']
|
||||
['ip', 'token']
|
||||
])
|
||||
|
||||
|
||||
def on_settings_save(self, data):
|
||||
self._logger.info("on_settings_save")
|
||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||
self.initialize()
|
||||
|
||||
|
||||
def on_event(self, event, payload):
|
||||
if not self.shutdownAfterPrintFinished and not self.powerOffAfterPrintFinished:
|
||||
return
|
||||
@ -372,7 +410,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._shutdown_timer_start()
|
||||
return
|
||||
|
||||
|
||||
def get_update_information(self):
|
||||
return dict(
|
||||
mystromswitch=dict(
|
||||
@ -392,6 +429,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
|
||||
|
||||
__plugin_name__ = "MyStrom Switch"
|
||||
__plugin_pythoncompat__ = ">=2.7,<4"
|
||||
|
||||
|
||||
def __plugin_load__():
|
||||
|
@ -7,6 +7,13 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('API Token') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.token">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label">Refresh Intervall</label>
|
||||
<div class="controls">
|
||||
@ -63,6 +70,15 @@
|
||||
</div>
|
||||
|
||||
<h4>Automatic Power Off Features</h4>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.rememberShutdown">remember Shutdown
|
||||
</label>
|
||||
<span class="help-block"><small>{{ _('Remember state of the checkboxes after reboot') }}</small></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
|
@ -4,11 +4,11 @@
|
||||
<button class="btn btn-primary" data-bind="click: onToggleRelayEvent, visible : onOffButtonEnabled">{{ _('Toggle Relais') }}</button>
|
||||
<label class="checkbox" data-bind="visible :showShutdownOctopiOption">
|
||||
<input type="checkbox" data-bind="enable: loginState.isUser(), checked: automaticShutdownEnabled, visible :showShutdownOctopiOption">
|
||||
{{ _('Shutdown Octoprint after print finishes') }}
|
||||
{{ _('Shutdown Octoprint after print finished') }}
|
||||
</label>
|
||||
|
||||
<label class="checkbox" data-bind="visible: showPowerOffPrintFinishOption">
|
||||
<input type="checkbox" data-bind="enable: loginState.isUser(), checked: automaticPowerOffEnabled, visible: showPowerOffPrintFinishOption">
|
||||
{{ _('Power Off Relais after print finishes') }}
|
||||
{{ _('Power Off Relais after print finished') }}
|
||||
</label>
|
||||
</div>
|
||||
|
6
setup.py
6
setup.py
@ -14,7 +14,7 @@ plugin_package = "octoprint_mystromswitch"
|
||||
plugin_name = "OctoPrint-MyStromSwitch"
|
||||
|
||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||
plugin_version = "1.0.3"
|
||||
plugin_version = "1.2.0"
|
||||
|
||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||
# module
|
||||
@ -57,7 +57,9 @@ plugin_ignored_packages = []
|
||||
# Example:
|
||||
# plugin_requires = ["someDependency==dev"]
|
||||
# additional_setup_parameters = {"dependency_links": ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]}
|
||||
additional_setup_parameters = {}
|
||||
additional_setup_parameters = {
|
||||
"use_2to3": True,
|
||||
}
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user