Skip to content

Commit

Permalink
Fix runtime issue for older Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mathoudebine committed Jan 28, 2024
1 parent 1474d3b commit 2e78b7c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
7 changes: 4 additions & 3 deletions library/sensors/sensors_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import platform
import random
from abc import ABC, abstractmethod
from typing import List


# Custom data classes must be implemented in this file, inherit the CustomDataSource and implement its 2 methods
Expand All @@ -41,7 +42,7 @@ def as_string(self) -> str:
pass

@abstractmethod
def last_values(self) -> list[float]:
def last_values(self) -> List[float]:
# List of last numeric values will be used for plot graph
# If you do not want to draw a line graph or if your custom data has no numeric values, keep this function empty
pass
Expand Down Expand Up @@ -77,7 +78,7 @@ def as_string(self) -> str:
# --> return f'{self.as_numeric():>4}%'
# Otherwise, part of the previous value can stay displayed ("ghosting") after a refresh

def last_values(self) -> list[float]:
def last_values(self) -> List[float]:
# List of last numeric values will be used for plot graph
return self.last_val

Expand All @@ -92,6 +93,6 @@ def as_string(self) -> str:
# If a custom data class only has text values, it won't be possible to display graph or radial bars
return "Python: " + platform.python_version()

def last_values(self) -> list[float]:
def last_values(self) -> List[float]:
# If a custom data class only has text values, it won't be possible to display line graph
pass
12 changes: 7 additions & 5 deletions library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import os
import platform
import sys
from typing import List

import babel.dates
from psutil._common import bytes2human
Expand Down Expand Up @@ -219,14 +220,14 @@ def display_themed_line_graph(theme_data, values):
)


def save_last_value(value, last_values: list[float]):
def save_last_value(value, last_values: List[float]):
# Store the value to the history list that can be used for line graph
last_values.append(value)
# Also remove the oldest value from history list
last_values.pop(0)


def last_values_list(size: int) -> list[float]:
def last_values_list(size: int) -> List[float]:
return [math.nan] * size


Expand Down Expand Up @@ -320,7 +321,6 @@ def fan_speed(cls):


class Gpu:

last_values_gpu_percentage = last_values_list(size=10)
last_values_gpu_mem_percentage = last_values_list(size=10)
last_values_gpu_temperature = last_values_list(size=10)
Expand Down Expand Up @@ -376,7 +376,8 @@ def stats(cls):

if math.isnan(load):
load = 0
if gpu_percent_graph_data['SHOW'] or gpu_percent_text_data['SHOW'] or gpu_percent_radial_data['SHOW'] or gpu_percent_line_graph_data['SHOW']:
if gpu_percent_graph_data['SHOW'] or gpu_percent_text_data['SHOW'] or gpu_percent_radial_data['SHOW'] or \
gpu_percent_line_graph_data['SHOW']:
logger.warning("Your GPU load is not supported yet")
gpu_percent_graph_data['SHOW'] = False
gpu_percent_text_data['SHOW'] = False
Expand Down Expand Up @@ -650,7 +651,8 @@ def stats():
string_value = custom_stat_class.as_string()
last_values = custom_stat_class.last_values()
except Exception as e:
logger.error("Error loading custom sensor class " + str(custom_stat) + " from sensors_custom.py : " + str(e))
logger.error(
"Error loading custom sensor class " + str(custom_stat) + " from sensors_custom.py : " + str(e))
return

if string_value is None:
Expand Down
24 changes: 12 additions & 12 deletions res/themes/theme_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ STATS:
Y: 220
WIDTH: 133
HEIGHT: 70
MIN_VALUE: 0
MAX_VALUE: 100
AUTOSCALE: False
MIN_VALUE: 30
MAX_VALUE: 120
AUTOSCALE: True
LINE_COLOR: 61, 184, 225
AXIS: True
AXIS_COLOR: 255, 135, 0
Expand Down Expand Up @@ -287,8 +287,8 @@ STATS:
WIDTH: 133
HEIGHT: 70
MIN_VALUE: 0
MAX_VALUE: 100
AUTOSCALE: False
MAX_VALUE: 3000
AUTOSCALE: True
LINE_COLOR: 61, 184, 225
AXIS: True
AXIS_COLOR: 255, 135, 0
Expand Down Expand Up @@ -476,9 +476,9 @@ STATS:
Y: 220
WIDTH: 133
HEIGHT: 70
MIN_VALUE: 0
MAX_VALUE: 100
AUTOSCALE: False
MIN_VALUE: 30
MAX_VALUE: 120
AUTOSCALE: True
LINE_COLOR: 61, 184, 225
AXIS: True
AXIS_COLOR: 255, 135, 0
Expand Down Expand Up @@ -535,8 +535,8 @@ STATS:
WIDTH: 133
HEIGHT: 70
MIN_VALUE: 0
MAX_VALUE: 100
AUTOSCALE: False
MAX_VALUE: 300
AUTOSCALE: True
LINE_COLOR: 61, 184, 225
AXIS: True
AXIS_COLOR: 255, 135, 0
Expand Down Expand Up @@ -593,8 +593,8 @@ STATS:
WIDTH: 133
HEIGHT: 70
MIN_VALUE: 0
MAX_VALUE: 100
AUTOSCALE: False
MAX_VALUE: 3000
AUTOSCALE: True
LINE_COLOR: 61, 184, 225
AXIS: True
AXIS_COLOR: 255, 135, 0
Expand Down

0 comments on commit 2e78b7c

Please sign in to comment.