Compare commits

...

17 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
Aline Abler
ba797fe1cc Try straightforward python3 compatibility options 2020-01-20 11:19:30 +01:00
5 changed files with 92 additions and 73 deletions

122
.idea/workspace.xml generated
View File

@ -3,8 +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/__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,62 +47,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" />
@ -392,7 +334,63 @@
<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>
<option name="localTasksCounter" value="105" />
<servers />
</component>
<component name="UnknownFeatures">
@ -422,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" />
@ -447,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
@ -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)
@ -164,7 +168,7 @@ 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
@ -174,7 +178,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 +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:
@ -237,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:
@ -255,7 +263,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 +353,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 +378,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
def get_settings_restricted_paths(self):
return dict(admin=[
['ip']
['ip', 'token']
])
def on_settings_save(self, data):
@ -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.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,
}
########################################################################################################################