#17 Logging zur Fehleranalyse eingebaut

This commit is contained in:
David Zingg
2020-01-13 19:44:31 +01:00
parent c1cdbeebad
commit ad66d2df68
2 changed files with 16 additions and 11 deletions

View File

@ -82,22 +82,24 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
'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._logger.info(
"Energy: " + str(self.energy) + " interval: " + str(intervall) + " power: " + str(
data["power"]))
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.exception(e)
self._logger.info('Connection Error Host: {}, {}'.format(self.ip, e))
except Exception as exp:
self._logger.exception(exp)
self._logger.info(exp.message)
else:
self._logger.info("Ip is None")
@ -132,6 +134,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
try:
try:
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)
self._logger.info("a")
@ -142,9 +145,11 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
self._logger.info(
"Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
except requests.exceptions.ConnectionError as e:
self._logger.exception(e)
self._logger.info("Error during powerCycle Relais: " + e.message)
except Exception as exp:
self._logger.info("Exception aufgetreten: " + exp.message)
self._logger.exception(exp)
nbRetry = nbRetry + 1
def _toggleRelay(self):