Compare commits

...

30 Commits

Author SHA1 Message Date
da4id
e7bf0762d3
Merge pull request #34 from da4id/Beta
Beta
2020-07-25 16:49:36 +02:00
David Zingg
96fdafb2dc #25 Python 3 Compatibility 2020-07-25 16:48:56 +02:00
David Zingg
c5d8bbd863 #25 Python 3 Compatibility 2020-07-25 16:48:24 +02:00
da4id
dda93e73d3
Merge pull request #33 from da4id/Beta
Beta
2020-07-01 22:02:18 +02:00
David Zingg
96c2e954fa #25 Python 3 Compatibility 2020-07-01 22:01:36 +02:00
David Zingg
107a7ba9de Merge remote-tracking branch 'origin/Beta' into Beta 2020-07-01 21:59:54 +02:00
David Zingg
809369f783 #25 Python 3 Compatibility 2020-07-01 21:59:36 +02:00
da4id
617f21a66e
Merge pull request #32 from da4id/Beta
Merge pull request #31 from Jereviendrai/master
2020-07-01 21:49:30 +02:00
da4id
66889083fd
Merge pull request #31 from Jereviendrai/master
Python3 Compatibility
2020-07-01 21:46:12 +02:00
da4id
1f5efa9c2a
Merge pull request #29 from Jereviendrai/master
Try straightforward python3 compatibility options
2020-07-01 21:44:05 +02:00
da4id
284d54ffa0
Merge pull request #28 from da4id/Beta
Beta
2020-07-01 21:34:09 +02:00
David Zingg
542a633559 #24 API Token Support 2020-07-01 21:33:26 +02:00
David Zingg
6c208ce10b #24 API Token Support 2020-07-01 21:29:24 +02:00
David Zingg
7d80c84393 #24 API Token Support 2020-07-01 21:25:06 +02:00
David Zingg
b3e53821bb #24 API Token Support 2020-07-01 21:19:53 +02:00
David Zingg
be81f64ec1 #24 API Token Support 2020-07-01 21:10:50 +02:00
da4id
ca61b89b3f
Merge pull request #27 from da4id/Beta
#21
2020-07-01 21:05:23 +02:00
David Zingg
330577cc6e #21 Add PowerOFF when print is finished 2020-07-01 21:03:46 +02:00
David Zingg
5fe040d455 #21 Add PowerOFF when print is finished 2020-07-01 21:01:36 +02:00
David Zingg
5298d96d26 #21 Add PowerOFF when print is finished 2020-07-01 20:53:29 +02:00
David Zingg
778821e5e5 #21 Add PowerOFF when print is finished 2020-07-01 20:51:31 +02:00
David Zingg
72de3c4db6 #21 Add PowerOFF when print is finished 2020-07-01 20:49:11 +02:00
David Zingg
f30e769f6a #21 Add PowerOFF when print is finished 2020-07-01 20:46:28 +02:00
David Zingg
c9608fa24f #21 Add PowerOFF when print is finished 2020-07-01 20:43:34 +02:00
David Zingg
af7a581620 #21 Add PowerOFF when print is finished 2020-07-01 20:36:57 +02:00
David Zingg
cba3367d2b #21 Add PowerOFF when print is finished 2020-07-01 20:32:27 +02:00
David Zingg
0816056ded #21 Add PowerOFF when print is finished 2020-07-01 20:30:51 +02:00
David Zingg
92fd2846ac #21 Add PowerOFF when print is finished 2020-07-01 20:13:15 +02:00
David Zingg
85e18076a0 #21 Add PowerOFF when print is finished 2020-07-01 20:10:17 +02:00
Aline Abler
ba797fe1cc Try straightforward python3 compatibility options 2020-01-20 11:19:30 +01:00
5 changed files with 232 additions and 177 deletions

289
.idea/workspace.xml generated
View File

@ -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&#10;#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&#10;#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&#10;#7 Relais einschalten wenn Octoprint gestartet wurde&#10;&#10;Logging schreibfehler&#10;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&#10;#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&#10;#7 Relais einschalten wenn Octoprint gestartet wurde&#10;&#10;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&#10;#7 Relais einschalten wenn Octoprint gestartet wurde&#10;&#10;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&#10;&#10;- 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&#10;&#10;- Bugfix plugin_requires" />
<MESSAGE value="#5 Rest Api integration&#10;&#10;- Nullpointer fix" />
<MESSAGE value="#6 UI Updates senden und anzeigen&#10;&#10;- unnötigen Code entfernen, erster Versuch" />
<MESSAGE value="Revert &quot;#6 UI Updates senden und anzeigen&quot;&#10;&#10;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&#10;&#10;neue Einstellmöglichkeiten anzeigen" />
<MESSAGE value="#22 Button taucht nicht auf&#10;&#10;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>

View File

@ -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__():

View File

@ -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">

View File

@ -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>

View File

@ -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,
}
########################################################################################################################