#24 API Token Support
This commit is contained in:
@ -177,8 +177,11 @@ 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}
|
||||
request = requests.get(
|
||||
'http://{}/report'.format(self.ip), timeout=1)
|
||||
'http://{}/report'.format(self.ip), headers=headers, timeout=1)
|
||||
if request.status_code == 200:
|
||||
timestamp = time.time()
|
||||
data = request.json()
|
||||
@ -216,8 +219,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:
|
||||
@ -240,8 +246,12 @@ 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}, timeout=1)
|
||||
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, headers=headers,
|
||||
timeout=1)
|
||||
if request.status_code == 200:
|
||||
return
|
||||
else:
|
||||
@ -258,8 +268,11 @@ 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), timeout=1)
|
||||
'http://{}/toggle'.format(self.ip), headers=headers, timeout=1)
|
||||
if request.status_code == 200:
|
||||
return
|
||||
else:
|
||||
|
Reference in New Issue
Block a user