Merge pull request #28 from da4id/Beta

Beta
This commit is contained in:
da4id 2020-07-01 21:34:09 +02:00 committed by GitHub
commit 284d54ffa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 47 deletions

View File

@ -2,8 +2,6 @@
<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$/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/setup.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -49,41 +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" />
@ -392,7 +355,42 @@
<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>
<option name="localTasksCounter" value="102" />
<servers />
</component>
<component name="UnknownFeatures">
@ -422,7 +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" />
@ -447,6 +444,7 @@
<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" />
<option name="LAST_COMMIT_MESSAGE" value="#24 API Token Support" />
</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)
@ -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):

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

@ -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.1.0"
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module