#17 Logging zur Fehleranalyse eingebaut

This commit is contained in:
David Zingg 2020-01-13 19:32:25 +01:00
parent 500ed07d79
commit c1cdbeebad
2 changed files with 40 additions and 36 deletions

35
.idea/workspace.xml generated
View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="7e2e0eec-b22e-4d48-8f24-196d1ed9b51a" name="Default Changelist" comment="#17 Logging zur Fehleranalyse eingebaut">
<list default="true" id="7e2e0eec-b22e-4d48-8f24-196d1ed9b51a" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/__init__.py" afterDir="false" />
</list>
@ -48,20 +48,6 @@
<option name="presentableId" value="Default" />
<updated>1574193087583</updated>
</task>
<task id="LOCAL-00004" summary="#5 Rest Api integration&#10;&#10;- Nullpointer fix">
<created>1574277496115</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1574277496115</updated>
</task>
<task id="LOCAL-00005" summary="#6 UI Updates senden und anzeigen&#10;&#10;- unnötigen Code entfernen, erster Versuch">
<created>1574279164975</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1574279164975</updated>
</task>
<task id="LOCAL-00006" summary="#6 UI Updates senden und anzeigen">
<created>1574279821388</created>
<option name="number" value="00006" />
@ -391,7 +377,21 @@
<option name="project" value="LOCAL" />
<updated>1575192543311</updated>
</task>
<option name="localTasksCounter" value="53" />
<task id="LOCAL-00053" summary="#17 Logging zur Fehleranalyse eingebaut">
<created>1578938604039</created>
<option name="number" value="00053" />
<option name="presentableId" value="LOCAL-00053" />
<option name="project" value="LOCAL" />
<updated>1578938604039</updated>
</task>
<task id="LOCAL-00054" summary="#17 Logging zur Fehleranalyse eingebaut">
<created>1578939868815</created>
<option name="number" value="00054" />
<option name="presentableId" value="LOCAL-00054" />
<option name="project" value="LOCAL" />
<updated>1578939868816</updated>
</task>
<option name="localTasksCounter" value="55" />
<servers />
</component>
<component name="UnknownFeatures">
@ -443,6 +443,7 @@
<MESSAGE value="#14 Einstellungen reorganisieren&#10;&#10;- Beschreibungen angepasst" />
<MESSAGE value="#15 Beschreibung erstellen" />
<MESSAGE value="#16 Codereview Octoprint Plugin Repo" />
<option name="LAST_COMMIT_MESSAGE" value="#16 Codereview Octoprint Plugin Repo" />
<MESSAGE value="#17 Logging zur Fehleranalyse eingebaut" />
<option name="LAST_COMMIT_MESSAGE" value="#17 Logging zur Fehleranalyse eingebaut" />
</component>
</project>

View File

@ -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")