Compare commits

..

No commits in common. "master" and "1.0.0" have entirely different histories.

7 changed files with 55 additions and 752 deletions

2
.idea/misc.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Uninitialized environment" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (venv)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>

401
.idea/workspace.xml generated
View File

@ -2,7 +2,11 @@
<project version="4">
<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/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/static/css/shutdownprinter.css" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/static/css/mystromswitch.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/static/js/shutdownprinter.js" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/static/js/mystromswitch.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/templates/shutdownprinter_settings.jinja2" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/templates/mystromswitch_settings.jinja2" afterDir="false" />
<change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/templates/shutdownprinter_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" />
@ -12,17 +16,11 @@
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="master" />
</map>
</option>
</component>
<component name="ProjectId" id="1TqgYXT1S9U5eM0eUvs1YarA1ll" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../LEDStrip/RaspberryPi/Python" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
@ -47,404 +45,17 @@
<option name="presentableId" value="Default" />
<updated>1574193087583</updated>
</task>
<task id="LOCAL-00056" summary="#17 Logging zur Fehleranalyse eingebaut">
<created>1578941071143</created>
<option name="number" value="00056" />
<option name="presentableId" value="LOCAL-00056" />
<option name="project" value="LOCAL" />
<updated>1578941071143</updated>
</task>
<task id="LOCAL-00057" summary="#17 Logging zur Fehleranalyse eingebaut">
<created>1579188503178</created>
<option name="number" value="00057" />
<option name="presentableId" value="LOCAL-00057" />
<option name="project" value="LOCAL" />
<updated>1579188503178</updated>
</task>
<task id="LOCAL-00058" summary="#17 Logging zur Fehleranalyse eingebaut">
<created>1579190155814</created>
<option name="number" value="00058" />
<option name="presentableId" value="LOCAL-00058" />
<option name="project" value="LOCAL" />
<updated>1579190155814</updated>
</task>
<task id="LOCAL-00059" summary="#17 Logs aufgeräumt">
<created>1579190259362</created>
<option name="number" value="00059" />
<option name="presentableId" value="LOCAL-00059" />
<option name="project" value="LOCAL" />
<updated>1579190259362</updated>
</task>
<task id="LOCAL-00060" summary="#17 Logs aufgeräumt">
<created>1579192359403</created>
<option name="number" value="00060" />
<option name="presentableId" value="LOCAL-00060" />
<option name="project" value="LOCAL" />
<updated>1579192359403</updated>
</task>
<task id="LOCAL-00061" summary="#21 Add PowerOFF when print is finished&#10;&#10;neue Einstellmöglichkeiten anzeigen">
<created>1582988883875</created>
<option name="number" value="00061" />
<option name="presentableId" value="LOCAL-00061" />
<option name="project" value="LOCAL" />
<updated>1582988883875</updated>
</task>
<task id="LOCAL-00062" summary="#22 Button taucht nicht auf&#10;&#10;Fehler anzeigen wenn Verbindung zu switch nicht klappt">
<created>1582990110412</created>
<option name="number" value="00062" />
<option name="presentableId" value="LOCAL-00062" />
<option name="project" value="LOCAL" />
<updated>1582990110412</updated>
</task>
<task id="LOCAL-00063" summary="#21 Add PowerOFF when print is finished">
<created>1582990799626</created>
<option name="number" value="00063" />
<option name="presentableId" value="LOCAL-00063" />
<option name="project" value="LOCAL" />
<updated>1582990799626</updated>
</task>
<task id="LOCAL-00064" summary="#21 Add PowerOFF when print is finished">
<created>1582991033421</created>
<option name="number" value="00064" />
<option name="presentableId" value="LOCAL-00064" />
<option name="project" value="LOCAL" />
<updated>1582991033421</updated>
</task>
<task id="LOCAL-00065" summary="#21 Add PowerOFF when print is finished">
<created>1582991352868</created>
<option name="number" value="00065" />
<option name="presentableId" value="LOCAL-00065" />
<option name="project" value="LOCAL" />
<updated>1582991352868</updated>
</task>
<task id="LOCAL-00066" summary="#21 Add PowerOFF when print is finished">
<created>1582991720560</created>
<option name="number" value="00066" />
<option name="presentableId" value="LOCAL-00066" />
<option name="project" value="LOCAL" />
<updated>1582991720560</updated>
</task>
<task id="LOCAL-00067" summary="#21 Add PowerOFF when print is finished">
<created>1582992279872</created>
<option name="number" value="00067" />
<option name="presentableId" value="LOCAL-00067" />
<option name="project" value="LOCAL" />
<updated>1582992279872</updated>
</task>
<task id="LOCAL-00068" summary="#21 Add PowerOFF when print is finished">
<created>1582992989361</created>
<option name="number" value="00068" />
<option name="presentableId" value="LOCAL-00068" />
<option name="project" value="LOCAL" />
<updated>1582992989361</updated>
</task>
<task id="LOCAL-00069" summary="#21 Add PowerOFF when print is finished">
<created>1582993317859</created>
<option name="number" value="00069" />
<option name="presentableId" value="LOCAL-00069" />
<option name="project" value="LOCAL" />
<updated>1582993317859</updated>
</task>
<task id="LOCAL-00070" summary="#21 Add PowerOFF when print is finished">
<created>1593346830444</created>
<option name="number" value="00070" />
<option name="presentableId" value="LOCAL-00070" />
<option name="project" value="LOCAL" />
<updated>1593346830445</updated>
</task>
<task id="LOCAL-00071" summary="#21 Add PowerOFF when print is finished">
<created>1593346998123</created>
<option name="number" value="00071" />
<option name="presentableId" value="LOCAL-00071" />
<option name="project" value="LOCAL" />
<updated>1593346998123</updated>
</task>
<task id="LOCAL-00072" summary="#21 Add PowerOFF when print is finished">
<created>1593347175159</created>
<option name="number" value="00072" />
<option name="presentableId" value="LOCAL-00072" />
<option name="project" value="LOCAL" />
<updated>1593347175159</updated>
</task>
<task id="LOCAL-00073" summary="#21 Add PowerOFF when print is finished">
<created>1593347774339</created>
<option name="number" value="00073" />
<option name="presentableId" value="LOCAL-00073" />
<option name="project" value="LOCAL" />
<updated>1593347774339</updated>
</task>
<task id="LOCAL-00074" summary="#21 Add PowerOFF when print is finished">
<created>1593347857755</created>
<option name="number" value="00074" />
<option name="presentableId" value="LOCAL-00074" />
<option name="project" value="LOCAL" />
<updated>1593347857755</updated>
</task>
<task id="LOCAL-00075" summary="#21 Add PowerOFF when print is finished">
<created>1593347943336</created>
<option name="number" value="00075" />
<option name="presentableId" value="LOCAL-00075" />
<option name="project" value="LOCAL" />
<updated>1593347943336</updated>
</task>
<task id="LOCAL-00076" summary="#21 Add PowerOFF when print is finished">
<created>1593348030528</created>
<option name="number" value="00076" />
<option name="presentableId" value="LOCAL-00076" />
<option name="project" value="LOCAL" />
<updated>1593348030528</updated>
</task>
<task id="LOCAL-00077" summary="#21 Add PowerOFF when print is finished">
<created>1593348512259</created>
<option name="number" value="00077" />
<option name="presentableId" value="LOCAL-00077" />
<option name="project" value="LOCAL" />
<updated>1593348512259</updated>
</task>
<task id="LOCAL-00078" summary="#21 Add PowerOFF when print is finished">
<created>1593348977898</created>
<option name="number" value="00078" />
<option name="presentableId" value="LOCAL-00078" />
<option name="project" value="LOCAL" />
<updated>1593348977898</updated>
</task>
<task id="LOCAL-00079" summary="#21 Add PowerOFF when print is finished">
<created>1593350619006</created>
<option name="number" value="00079" />
<option name="presentableId" value="LOCAL-00079" />
<option name="project" value="LOCAL" />
<updated>1593350619006</updated>
</task>
<task id="LOCAL-00080" summary="#21 Add PowerOFF when print is finished">
<created>1593352569980</created>
<option name="number" value="00080" />
<option name="presentableId" value="LOCAL-00080" />
<option name="project" value="LOCAL" />
<updated>1593352569980</updated>
</task>
<task id="LOCAL-00081" summary="#21 Add PowerOFF when print is finished">
<created>1593352709926</created>
<option name="number" value="00081" />
<option name="presentableId" value="LOCAL-00081" />
<option name="project" value="LOCAL" />
<updated>1593352709926</updated>
</task>
<task id="LOCAL-00082" summary="#21 Add PowerOFF when print is finished">
<created>1593353565224</created>
<option name="number" value="00082" />
<option name="presentableId" value="LOCAL-00082" />
<option name="project" value="LOCAL" />
<updated>1593353565224</updated>
</task>
<task id="LOCAL-00083" summary="#21 Add PowerOFF when print is finished">
<created>1593354627917</created>
<option name="number" value="00083" />
<option name="presentableId" value="LOCAL-00083" />
<option name="project" value="LOCAL" />
<updated>1593354627917</updated>
</task>
<task id="LOCAL-00084" summary="#21 Add PowerOFF when print is finished">
<created>1593354891881</created>
<option name="number" value="00084" />
<option name="presentableId" value="LOCAL-00084" />
<option name="project" value="LOCAL" />
<updated>1593354891881</updated>
</task>
<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">
<option featureType="com.intellij.fileTypeFactory" implementationName="*.js" />
</component>
<component name="Vcs.Log.History.Properties">
<option name="COLUMN_ORDER">
<list>
<option value="0" />
<option value="2" />
<option value="3" />
<option value="1" />
</list>
</option>
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="COLUMN_ORDER" />
</State>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<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" />
<MESSAGE value="#6 UI Updates senden und anzeigen&#10;&#10;logs entfernt" />
<MESSAGE value="#8 Relais ein / ausschalten von Ocotprint aus&#10;&#10;- Toggle Button anzeigen und Events eingebaut&#10;- Api funktionen für Relais ein / aus und toggle implementiert" />
<MESSAGE value="#8 Relais ein / ausschalten von Ocotprint aus&#10;&#10;- Button Style auf default geändert&#10;- get_api_commands implementiert" />
<MESSAGE value="#8 Relais ein / ausschalten von Ocotprint aus&#10;&#10;- url korrigiert" />
<MESSAGE value="#8 Relais ein / ausschalten von Ocotprint aus&#10;&#10;- Toggle Button enable / disable in Einstellunge&#10;- Databinding von Button" />
<MESSAGE value="#8 Relais ein / ausschalten von Ocotprint aus" />
<MESSAGE value="#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" />
<MESSAGE value="#9 Relais ausschalten wenn Octoprint heruntergefahren wird&#10;#7 Relais einschalten wenn Octoprint gestartet wurde" />
<MESSAGE value="#9 Relais ausschalten wenn Octoprint heruntergefahren wird&#10;#7 Relais einschalten wenn Octoprint gestartet wurde&#10;&#10;Api call fix" />
<MESSAGE value="#13 Wenn Request fehlschägt max. 3x versuchen" />
<MESSAGE value="#11 Energieverbrauch näherungsweise berechnen" />
<MESSAGE value="#14 Einstellungen reorganisieren" />
<MESSAGE value="#14 Einstellungen reorganisieren&#10;&#10;- Beschreibungen angepasst" />
<MESSAGE value="#15 Beschreibung erstellen" />
<MESSAGE value="#16 Codereview Octoprint Plugin Repo" />
<MESSAGE value="#17 Logging zur Fehleranalyse eingebaut" />
<MESSAGE value="#17 Logs aufgeräumt" />
<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" />
<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

@ -1,11 +1,11 @@
# coding=utf-8
from __future__ import absolute_import
import octoprint.plugin
import requests
import ssl
import time
from octoprint.events import eventManager, Events
import octoprint.plugin
import requests
from octoprint.util import RepeatedTimer
@ -13,32 +13,18 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.StartupPlugin,
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.ShutdownPlugin):
def __init__(self):
self.ip = None
self.token = ""
self.intervall = 1
self.onOffButtonEnabled = False
self.powerOnOnStart = False
self.powerOffOnShutdown = False
self.powerOffDelay = 0
self.showShutdownOctopiOption = False
self.showPowerOffPrintFinishOption = False
self.shutdownDelay = 60
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
self._wait_for_timelapse_timer = None
self._timer = None
self.energy = 0
self.lastTimeStamp = 0
@ -51,9 +37,6 @@ 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,29 +52,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
self.powerOffDelay = self._settings.get_int(["powerOffDelay"])
self._logger.debug("powerOffDelay: %s" % self.powerOffDelay)
self.showShutdownOctopiOption = self._settings.get_boolean(["showShutdownOctopiOption"])
self._logger.debug("showShutdownOctopiOption: %s" % self.showShutdownOctopiOption)
self.showPowerOffPrintFinishOption = self._settings.get_boolean(["showPowerOffPrintFinishOption"])
self._logger.debug("showPowerOffPrintFinishOption: %s" % self.showPowerOffPrintFinishOption)
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()
self._timer_start()
def get_assets(self):
return dict(js=["js/mystromswitch.js"], css=["css/mystromswitch.css"])
@ -103,82 +64,21 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
icon="power-off"),
dict(type="settings", custom_bindings=False)]
def _shutdown_timer_start(self):
if self._abort_timer is not None:
return
self._logger.info("_shutdown_timer_start")
if self._wait_for_timelapse_timer is not None:
self._wait_for_timelapse_timer.cancel()
self._logger.info("Starting abort shutdown timer.")
self._timeout_value = self.shutdownDelay
self._abort_timer = RepeatedTimer(1, self._shutdown_timer_task)
self._abort_timer.start()
def _wait_for_timelapse_start(self):
if self._wait_for_timelapse_timer is not None:
return
self._logger.info("_wait_for_timelapse_start()")
self._wait_for_timelapse_timer = RepeatedTimer(5, self._wait_for_timelapse)
self._wait_for_timelapse_timer.start()
def _wait_for_timelapse(self):
c = len(octoprint.timelapse.get_unrendered_timelapses())
if c > 0:
self._logger.info("Waiting for %s timelapse(s) to finish rendering before starting shutdown timer..." % c)
else:
self._shutdown_timer_start()
def _shutdown_timer_task(self):
if self._timeout_value is None:
return
self._timeout_value -= 1
if self._timeout_value <= 0:
if self._wait_for_timelapse_timer is not None:
self._wait_for_timelapse_timer.cancel()
self._wait_for_timelapse_timer = None
if self._abort_timer is not None:
self._abort_timer.cancel()
self._abort_timer = None
if self.shutdownAfterPrintFinished and self.showShutdownOctopiOption:
self._shutdown_system()
elif self.powerOffAfterPrintFinished and self.showPowerOffPrintFinishOption:
self._logger.info("only Shutdown Relais")
self._setRelaisState(False)
def _status_timer_start(self):
if self._status_timer is not None:
self._status_timer.cancel()
def _timer_start(self):
if self._timer is not None:
self._timer.cancel()
self._logger.info("Canceling Timer")
if self.intervall >= 1 and self.ip is not None:
self._logger.info("Starting timer")
self._status_timer = RepeatedTimer(self.intervall, self._status_timer_task)
self._status_timer.start()
self._timer = RepeatedTimer(self.intervall, self._timer_task)
self._timer.start()
def _shutdown_system(self):
self._logger.info("Shutdown Relais and System")
self._powerCycleRelais(False, self.powerOffDelay)
shutdown_command = self._settings.global_get(["server", "commands", "systemShutdownCommand"])
self._logger.info("Shutting down system with command: {command}".format(command=shutdown_command))
try:
import sarge
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):
def _timer_task(self):
if self.ip is not None:
try:
try:
request = requests.get(
'http://{}/report'.format(self.ip), headers={"Token": self.token}, timeout=1)
'http://{}/report'.format(self.ip), timeout=1)
if request.status_code == 200:
timestamp = time.time()
data = request.json()
@ -186,41 +86,24 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
intervall = timestamp - self.lastTimeStamp
# Energy in Wh
self.energy = self.energy + (intervall * data["power"] / 3600)
self._logger.debug(
"Energy: " + str(self.energy) + " interval: " + str(intervall) + " power: " + str(
data["power"]))
self.lastTimeStamp = timestamp
data["energy"] = self.energy
data["onOffButtonEnabled"] = self.onOffButtonEnabled
data["showShutdownOctopiOption"] = self.showShutdownOctopiOption
data["showPowerOffPrintFinishOption"] = self.showPowerOffPrintFinishOption
data["automaticShutdownEnabled"] = self.shutdownAfterPrintFinished
data["automaticPowerOffEnabled"] = self.powerOffAfterPrintFinished
self._plugin_manager.send_plugin_message(self._identifier, data)
return
except (requests.exceptions.ConnectionError, ValueError) as e:
self._logger.exception(e)
except Exception as exp:
self._logger.exception(exp)
except (requests.exceptions.ConnectionError, ValueError):
self._logger.info('Connection Error Host: {}'.format(self.ip))
else:
self._logger.info("Ip is None")
data = {"relay": True, "energy": 0, "onOffButtonEnabled": False, "showShutdownOctopiOption": False,
"showPowerOffPrintFinishOption": False, "automaticShutdownEnabled": self.shutdownAfterPrintFinished,
"automaticPowerOffEnabled": self.powerOffAfterPrintFinished}
self._plugin_manager.send_plugin_message(self._identifier, data)
def _setRelaisState(self, newState):
nbRetry = 0
value = '0'
if newState:
if (newState == True):
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}, headers=headers, timeout=1)
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
if request.status_code == 200:
return
else:
@ -240,22 +123,14 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
value = 'off'
while nbRetry < 3:
try:
try:
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}, headers={"Token": self.token},
timeout=1)
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
if request.status_code == 200:
return
else:
self._logger.info(
"Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
except requests.exceptions.ConnectionError as e:
self._logger.exception(e)
self._logger.info("Error during powerCycle Relais: " + str(e.message))
except Exception as exp:
self._logger.exception(exp)
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
except requests.exceptions.ConnectionError:
self._logger.info("Error during powerCycle Relais")
nbRetry = nbRetry + 1
def _toggleRelay(self):
@ -263,7 +138,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
while nbRetry < 3:
try:
request = requests.get(
'http://{}/toggle'.format(self.ip), headers={"Token": self.token}, timeout=1)
'http://{}/toggle'.format(self.ip), timeout=1)
if request.status_code == 200:
return
else:
@ -282,44 +157,12 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
elif command == "toggleRelais":
self._logger.info("toggleRelais")
self._toggleRelay()
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(
enableRelais=[],
disableRelais=[],
toggleRelais=[],
disableShutdownAfterFinish=[],
enableShutdownAfterFinish=[],
disablePowerOffAfterFinish=[],
enablePowerOffAfterFinish=[]
toggleRelais=[]
)
def on_after_startup(self):
@ -328,10 +171,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
self._setRelaisState(True)
def on_shutdown(self):
self._logger.info("on_shutdown_event")
if self.powerOffOnShutdown:
if self.powerOffDelay <= 0:
self._logger.info("Turn off Relais on Shutdown")
self._logger.info("Turn on Relais off Shutdown")
self._setRelaisState(False)
else:
self._logger.info("Turn off Relais on Shutdown Delayed")
@ -341,75 +183,30 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
if target > current:
if current <= 1:
self.onOffButtonEnabled = False
pass
if current <= 2:
self.powerOnOnStart = False,
self.powerOffOnShutdown = False,
self.powerOffDelay = 0
if current <= 3:
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 6
return 3
def get_settings_defaults(self):
return dict(
ip=None,
token="",
intervall=1,
onOffButtonEnabled=False,
powerOnOnStart=False,
owerOnOnStart=False,
powerOffOnShutdown=False,
powerOffDelay=0,
showShutdownOctopiOption=False,
showPowerOffPrintFinishOption=False,
shutdownDelay=60,
lastShutdown=False,
lastPowerOff=False,
rememberShutdown=False
powerOffDelay=0
)
def get_settings_restricted_paths(self):
return dict(admin=[
['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
if not self._settings.global_get(["server", "commands", "systemShutdownCommand"]):
self._logger.warning("systemShutdownCommand is not defined. Aborting shutdown...")
return
if event not in [Events.PRINT_DONE, Events.PRINT_FAILED]:
return
if event == Events.PRINT_FAILED and not self._printer.is_closed_or_error():
# Cancelled job
return
if event in [Events.PRINT_DONE, Events.PRINT_FAILED]:
webcam_config = self._settings.global_get(["webcam", "timelapse"], merged=True)
timelapse_type = webcam_config["type"]
if (timelapse_type is not None and timelapse_type != "off"):
self._wait_for_timelapse_start()
else:
self._shutdown_timer_start()
return
def get_update_information(self):
return dict(
mystromswitch=dict(
@ -429,7 +226,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
__plugin_name__ = "MyStrom Switch"
__plugin_pythoncompat__ = ">=2.7,<4"
def __plugin_load__():

View File

@ -7,10 +7,6 @@ $(function() {
self.printer = parameters[2];
self.onOffButtonEnabled = ko.observable();
self.showShutdownOctopiOption = ko.observable();
self.showPowerOffPrintFinishOption = ko.observable();
self.automaticPowerOffEnabled = ko.observable();
self.automaticShutdownEnabled = ko.observable();
self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue")
self.mystromswitchEnergyValue = document.getElementById("mystromswitchEnergyValue")
@ -26,65 +22,23 @@ $(function() {
})
}
//self.onmystromswitchEvent = function() {
self.onmystromswitchEvent = function() {
//}
//self.onOffButtonEnabled.subscribe(self.onmystromswitchEvent, self);
self.onAutomaticShutdownEnabledChanged = function(){
var cmd = "disableShutdownAfterFinish";
if (self.automaticShutdownEnabled()) {
var cmd = "enableShutdownAfterFinish";
}
$.ajax({
url: API_BASEURL + "plugin/mystromswitch",
type: "POST",
dataType: "json",
data: JSON.stringify({
command: cmd
}),
contentType: "application/json; charset=UTF-8"
})
}
self.onAutomaticPowerOffEnabledChanged = function(){
var cmd = "disablePowerOffAfterFinish";
if (self.automaticPowerOffEnabled()) {
var cmd = "enablePowerOffAfterFinish";
}
$.ajax({
url: API_BASEURL + "plugin/mystromswitch",
type: "POST",
dataType: "json",
data: JSON.stringify({
command: cmd
}),
contentType: "application/json; charset=UTF-8"
})
}
self.automaticShutdownEnabled.subscribe(self.onAutomaticShutdownEnabledChanged, self);
self.automaticPowerOffEnabled.subscribe(self.onAutomaticPowerOffEnabledChanged, self);
self.onOffButtonEnabled.subscribe(self.onmystromswitchEvent, self);
self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin != "mystromswitch" && plugin != "octoprint_mystromswitch") {
return;
}
self.onOffButtonEnabled(data.onOffButtonEnabled);
self.showShutdownOctopiOption(data.showShutdownOctopiOption);
self.showPowerOffPrintFinishOption(data.showPowerOffPrintFinishOption);
self.mystromswitchEnergyValue.innerHTML = "Energy: "+data.energy.toFixed(1)+"Wh"
if(data.relay == false){
self.mystromswitchPowerValue.innerHTML = "Relay is off";
} else if (data.power != null) {
self.mystromswitchPowerValue.innerHTML = "Power Consumption "+data.power.toFixed(1)+"W";
}else{
self.mystromswitchPowerValue.innerHTML = "myStrom switch not reachable"
self.mystromswitchEnergyValue.innerHTML = "Check url in Plugin Settings"
}
self.automaticShutdownEnabled(data.automaticShutdownEnabled);
self.automaticPowerOffEnabled(data.automaticPowerOffEnabled);
}
}

View File

@ -1,19 +1,12 @@
<form class="form-horizontal">
<h4>General</h4>
<div class="control-group">
<label class="control-label">{{ _('URL or IP-Address of your switch (without http)') }}</label>
<label class="control-label">{{ _('URL or IP-Address of your switch') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.ip">
</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">
@ -68,44 +61,4 @@
<span class="help-block"><small>{{ _('Delay in seconds after octoprint is shutted down to switch off relays. This settings is recommended to make sure that Raspberry Pi is completely shutted down when you switch power off. Switching off when your Raspberry Pi is running could lead to unrepairable damage to your SD Card!') }}</small></span>
</div>
</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">
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.showShutdownOctopiOption">Show option to automatic shutdown Octoprint after Print is finished
</label>
<span class="help-block"><small>{{ _('This setting shows the option to shut Octoprint down and switch your mySwitch off after your Print is finished. Use the "Delay after print is finished" option to determine after how many seconds Octoprint will be shutted down. After this use "Turn Relais Off Delay" to determine after how many seconds the Relas will be switched off') }}</small></span>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.showPowerOffPrintFinishOption">Show option to turn off Relais after Print is finished
</label>
<span class="help-block"><small>{{ _('This setting shows the option to only switch your mySwitch off after your Print is finished. Use the "Delay after print is finished" Option to determine after how many seconds the Relais will switch off') }}</small></span>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Delay after print is finished') }}</label>
<div class="controls">
<div class="input-append">
<input type="number" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.shutdownDelay">
<span class="add-on">seconds</span>
</div>
<span class="help-block"><small>{{ _('Delay in seconds after after print is finished') }}</small></span>
</div>
</div>
</form>

View File

@ -2,13 +2,4 @@
<label class="control-label" id="mystromswitchPowerValue">Powerconsumption 0.0W</label>
<label class="control-label" id="mystromswitchEnergyValue">Energy 0.0Wh</label>
<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 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 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.2.0"
plugin_version = "1.0.0"
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
@ -57,9 +57,7 @@ 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 = {
"use_2to3": True,
}
additional_setup_parameters = {}
########################################################################################################################