From a0a7b51a663defb81e68bd258b167ef7ba88b279 Mon Sep 17 00:00:00 2001 From: David Zingg Date: Mon, 13 Jan 2020 19:03:23 +0100 Subject: [PATCH 1/9] #17 Logging zur Fehleranalyse eingebaut --- .idea/workspace.xml | 399 +++++++++++++++++++++++++++- octoprint_mystromswitch/__init__.py | 26 +- 2 files changed, 411 insertions(+), 14 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4cec76d..57d6cde 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,12 +1,9 @@ - + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/octoprint_mystromswitch/__init__.py b/octoprint_mystromswitch/__init__.py index cb3bada..972be36 100644 --- a/octoprint_mystromswitch/__init__.py +++ b/octoprint_mystromswitch/__init__.py @@ -79,13 +79,16 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, try: request = requests.get( 'http://{}/report'.format(self.ip), timeout=1) + self._logger.info("request finish") if request.status_code == 200: + self._logger.info("request OK") timestamp = time.time() data = request.json() if not self.lastTimeStamp == 0: intervall = timestamp - self.lastTimeStamp # Energy in Wh self.energy = self.energy + (intervall * data["power"] / 3600) + self._logger.info("Energy: " + self.energy) self.lastTimeStamp = timestamp data["energy"] = self.energy data["onOffButtonEnabled"] = self.onOffButtonEnabled @@ -123,14 +126,20 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, value = 'off' while nbRetry < 3: try: - request = requests.post( - 'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1) - if request.status_code == 200: - return - else: - self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code)) - except requests.exceptions.ConnectionError: - self._logger.info("Error during powerCycle Relais") + try: + self._logger.info("try to send Powercycle Request") + request = requests.post( + 'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1) + self._logger.info("powerCycle Request Status: " + request.status_code) + if request.status_code == 200: + return + else: + self._logger.info( + "Could not powerCycle Relais, Http Status Code: {}".format(request.status_code)) + except requests.exceptions.ConnectionError as e: + self._logger.info("Error during powerCycle Relais: " + e.message) + except Exception as exp: + self._logger.info("Exception aufgetreten: " + exp.message) nbRetry = nbRetry + 1 def _toggleRelay(self): @@ -171,6 +180,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._setRelaisState(True) def on_shutdown(self): + self._logger.info("on_shutdown_event") if self.powerOffOnShutdown: if self.powerOffDelay <= 0: self._logger.info("Turn on Relais off Shutdown") From 500ed07d79181fc03dc133a3b763d62e783dfd53 Mon Sep 17 00:00:00 2001 From: David Zingg Date: Mon, 13 Jan 2020 19:24:28 +0100 Subject: [PATCH 2/9] #17 Logging zur Fehleranalyse eingebaut --- octoprint_mystromswitch/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/octoprint_mystromswitch/__init__.py b/octoprint_mystromswitch/__init__.py index 972be36..d1df144 100644 --- a/octoprint_mystromswitch/__init__.py +++ b/octoprint_mystromswitch/__init__.py @@ -79,9 +79,10 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, try: request = requests.get( 'http://{}/report'.format(self.ip), timeout=1) - self._logger.info("request finish") + self._logger.info("timer request finish") if request.status_code == 200: - self._logger.info("request OK") + self._logger.info("timer request OK, timestamp: " + str(time.time()) + " lastTimestamp: " + str( + self.lastTimeStamp)) timestamp = time.time() data = request.json() if not self.lastTimeStamp == 0: @@ -130,7 +131,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._logger.info("try to send Powercycle Request") request = requests.post( 'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1) - self._logger.info("powerCycle Request Status: " + request.status_code) + self._logger.info("a") + self._logger.info("powerCycle Request Status: " + str(request.status_code)) if request.status_code == 200: return else: From c1cdbeebad671ab19f64811f959af498aee40085 Mon Sep 17 00:00:00 2001 From: David Zingg Date: Mon, 13 Jan 2020 19:32:25 +0100 Subject: [PATCH 3/9] #17 Logging zur Fehleranalyse eingebaut --- .idea/workspace.xml | 35 ++++++++++++------------ octoprint_mystromswitch/__init__.py | 41 ++++++++++++++++------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 57d6cde..b152604 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,7 @@ - + @@ -48,20 +48,6 @@ @@ -443,6 +443,7 @@ - \ No newline at end of file diff --git a/octoprint_mystromswitch/__init__.py b/octoprint_mystromswitch/__init__.py index d1df144..87c1fde 100644 --- a/octoprint_mystromswitch/__init__.py +++ b/octoprint_mystromswitch/__init__.py @@ -77,25 +77,28 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, def _timer_task(self): if self.ip is not None: try: - request = requests.get( - 'http://{}/report'.format(self.ip), timeout=1) - self._logger.info("timer request finish") - if request.status_code == 200: - self._logger.info("timer request OK, timestamp: " + str(time.time()) + " lastTimestamp: " + str( - self.lastTimeStamp)) - timestamp = time.time() - data = request.json() - if not self.lastTimeStamp == 0: - intervall = timestamp - self.lastTimeStamp - # Energy in Wh - self.energy = self.energy + (intervall * data["power"] / 3600) - self._logger.info("Energy: " + self.energy) - self.lastTimeStamp = timestamp - data["energy"] = self.energy - data["onOffButtonEnabled"] = self.onOffButtonEnabled - self._plugin_manager.send_plugin_message(self._identifier, data) - except (requests.exceptions.ConnectionError, ValueError): - self._logger.info('Connection Error Host: {}'.format(self.ip)) + try: + request = requests.get( + 'http://{}/report'.format(self.ip), timeout=1) + self._logger.info("timer request finish") + if request.status_code == 200: + self._logger.info("timer request OK, timestamp: " + str(time.time()) + " lastTimestamp: " + str( + self.lastTimeStamp)) + timestamp = time.time() + data = request.json() + if not self.lastTimeStamp == 0: + intervall = timestamp - self.lastTimeStamp + # Energy in Wh + self.energy = self.energy + (intervall * data["power"] / 3600) + self._logger.info("Energy: " + str(self.energy)) + self.lastTimeStamp = timestamp + data["energy"] = self.energy + data["onOffButtonEnabled"] = self.onOffButtonEnabled + self._plugin_manager.send_plugin_message(self._identifier, data) + except (requests.exceptions.ConnectionError, ValueError) as e: + self._logger.info('Connection Error Host: {}, {}'.format(self.ip, e)) + except Exception as exp: + self._logger.info(exp.message) else: self._logger.info("Ip is None") From ad66d2df68dbb93ccdfaa4db3b19e99cd94ebaf8 Mon Sep 17 00:00:00 2001 From: David Zingg Date: Mon, 13 Jan 2020 19:44:31 +0100 Subject: [PATCH 4/9] #17 Logging zur Fehleranalyse eingebaut --- .idea/workspace.xml | 16 ++++++++-------- octoprint_mystromswitch/__init__.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b152604..fd5005a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -48,13 +48,6 @@