#24 API Token Support

This commit is contained in:
David Zingg 2020-07-01 21:29:24 +02:00
parent 7d80c84393
commit 6c208ce10b
2 changed files with 11 additions and 21 deletions

16
.idea/workspace.xml generated
View File

@ -47,13 +47,6 @@
<option name="presentableId" value="Default" />
<updated>1574193087583</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" />
@ -390,7 +383,14 @@
<option name="project" value="LOCAL" />
<updated>1593631193159</updated>
</task>
<option name="localTasksCounter" value="100" />
<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>
<option name="localTasksCounter" value="101" />
<servers />
</component>
<component name="UnknownFeatures">

View File

@ -177,12 +177,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
if self.ip is not None:
try:
try:
headers = {}
if self.token is not None and self.token != "":
headers = {"Token": self.token}
self._logger.info(headers)
request = requests.get(
'http://{}/report'.format(self.ip), headers=headers, timeout=1)
'http://{}/report'.format(self.ip), headers={"Token": self.token}, timeout=1)
if request.status_code == 200:
timestamp = time.time()
data = request.json()
@ -247,11 +243,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
try:
self._logger.info("try to send Powercycle Request")
self._logger.info('http://{}/timer'.format(self.ip))
headers = {}
if self.token is not None and self.token != "":
headers = {"Token": self.token}
request = requests.post(
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, headers=headers,
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, headers={"Token": self.token},
timeout=1)
if request.status_code == 200:
return
@ -269,11 +262,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
nbRetry = 0
while nbRetry < 3:
try:
headers = {}
if self.token is not None and self.token != "":
headers = {"Token": self.token}
request = requests.get(
'http://{}/toggle'.format(self.ip), headers=headers, timeout=1)
'http://{}/toggle'.format(self.ip), headers={"Token": self.token}, timeout=1)
if request.status_code == 200:
return
else: