#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

16
.idea/workspace.xml generated
View File

@ -48,13 +48,6 @@
<option name="presentableId" value="Default" />
<updated>1574193087583</updated>
</task>
<task id="LOCAL-00006" summary="#6 UI Updates senden und anzeigen">
<created>1574279821388</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1574279821388</updated>
</task>
<task id="LOCAL-00007" summary="Revert &quot;#6 UI Updates senden und anzeigen&quot;&#10;&#10;This reverts commit f83d4259">
<created>1574280075129</created>
<option name="number" value="00007" />
@ -391,7 +384,14 @@
<option name="project" value="LOCAL" />
<updated>1578939868816</updated>
</task>
<option name="localTasksCounter" value="55" />
<task id="LOCAL-00055" summary="#17 Logging zur Fehleranalyse eingebaut">
<created>1578940345174</created>
<option name="number" value="00055" />
<option name="presentableId" value="LOCAL-00055" />
<option name="project" value="LOCAL" />
<updated>1578940345174</updated>
</task>
<option name="localTasksCounter" value="56" />
<servers />
</component>
<component name="UnknownFeatures">

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):