diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bfca224..435ccdd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,6 @@ - - @@ -447,6 +445,7 @@ - \ No newline at end of file diff --git a/octoprint_mystromswitch/__init__.py b/octoprint_mystromswitch/__init__.py index 62843a0..153d484 100644 --- a/octoprint_mystromswitch/__init__.py +++ b/octoprint_mystromswitch/__init__.py @@ -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: