1
0
mirror of https://github.com/gryf/pywmtemp.git synced 2025-12-19 04:10:17 +01:00

Handle lack of config for graphs.

This commit is contained in:
2022-05-01 15:51:39 +02:00
parent 797490dec3
commit 98294b5a27

View File

@@ -187,7 +187,9 @@ class SensorDockApp(wmdocklib.DockApp):
self.warning = 0 self.warning = 0
self._history = {} self._history = {}
self._read_config() self._read_config()
self._current_graph = list(self._history.keys())[0] self._current_graph = ''
if list(self._history.keys()):
self._current_graph = list(self._history.keys())[0]
helpers.add_mouse_region(0, self.graph_coords[0], self.graph_coords[1], helpers.add_mouse_region(0, self.graph_coords[0], self.graph_coords[1],
width=self.graph_width, width=self.graph_width,
height=self.graph_max_height) height=self.graph_max_height)
@@ -288,7 +290,7 @@ class SensorDockApp(wmdocklib.DockApp):
# TODO: add some logging? # TODO: add some logging?
pass pass
for item in self.conf['readings'][:2]: for item in self.conf.get('readings', [])[:2]:
self._history[item.get('name')] = [0 for _ in self._history[item.get('name')] = [0 for _ in
range(self.graph_width)] range(self.graph_width)]
@@ -304,6 +306,9 @@ class SensorDockApp(wmdocklib.DockApp):
return True return True
def _draw_graph(self): def _draw_graph(self):
if not self._current_graph:
return
for count, item in enumerate(self._history[self._current_graph]): for count, item in enumerate(self._history[self._current_graph]):
height = int((item/100) * self.graph_max_height) height = int((item/100) * self.graph_max_height)
helpers.copy_xpm_area(65, self.graph_coords[1], helpers.copy_xpm_area(65, self.graph_coords[1],