14 Commits
1.0.4 ... Beta

5 changed files with 110 additions and 90 deletions

149
.idea/workspace.xml generated
View File

@ -4,7 +4,6 @@
<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$/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/setup.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@ -49,76 +48,6 @@
<option name="presentableId" value="Default" />
<updated>1574193087583</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" />
<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" />
@ -392,7 +321,77 @@
<option name="project" value="LOCAL" />
<updated>1593630096392</updated>
</task>
<option name="localTasksCounter" value="97" />
<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>
<task id="LOCAL-00105" summary="#25 Python 3 Compatibility">
<created>1595688504296</created>
<option name="number" value="00105" />
<option name="presentableId" value="LOCAL-00105" />
<option name="project" value="LOCAL" />
<updated>1595688504296</updated>
</task>
<task id="LOCAL-00106" summary="#25 Python 3 Compatibility">
<created>1595688536404</created>
<option name="number" value="00106" />
<option name="presentableId" value="LOCAL-00106" />
<option name="project" value="LOCAL" />
<updated>1595688536404</updated>
</task>
<option name="localTasksCounter" value="107" />
<servers />
</component>
<component name="UnknownFeatures">
@ -422,8 +421,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" />
@ -447,6 +444,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
@ -50,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)
@ -158,13 +162,17 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
self._status_timer.start()
def _shutdown_system(self):
if not self._settings.global_get(["server", "commands", "systemShutdownCommand"]):
self._logger.warning("systemShutdownCommand is not defined. Aborting shutdown...")
return
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)
p = sarge.run(shutdown_command, async_=True)
except Exception as e:
self._logger.exception("Error when shutting down: {error}".format(error=e))
return
@ -174,7 +182,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
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()
@ -212,8 +220,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:
@ -237,7 +248,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:
@ -255,7 +267,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
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:
@ -345,13 +357,16 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
self.lastShutdown = False
self.lastPowerOff = False
self.rememberShutdown = False
if current <= 5:
self.token = ""
def get_settings_version(self):
return 5
return 6
def get_settings_defaults(self):
return dict(
ip=None,
token="",
intervall=1,
onOffButtonEnabled=False,
powerOnOnStart=False,
@ -367,7 +382,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
def get_settings_restricted_paths(self):
return dict(admin=[
['ip']
['ip', 'token']
])
def on_settings_save(self, data):
@ -379,10 +394,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
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
@ -418,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">

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.4"
plugin_version = "1.2.1"
# 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,
}
########################################################################################################################