telegraf_to_vu1/dial_configs/GameloaderGamescopeFPS.py
2024-12-02 18:28:01 +01:00

25 lines
861 B
Python

from dial_configs.dial_config import DialConfig
from vu1 import RGBColor
class GameloaderGamescopeFPS(DialConfig):
def __init__(self, target_dial, asset_path):
super().__init__(target_dial, asset_path, "fps.png")
def transform_color(self, value):
if fps < 60:
color = RGBColor(1.0, 0, 0)
else:
color = super().Colors.get_gradient_color(self, value, 30, 0)
return color
def transform_value(self, json_data):
FPS_MAX = 120
fps = float(json_data.get("fields", {}).get("fps", 0))
value = int((fps/FPS_MAX)*100)
return value
def __eq__(self, other):
try:
return (other.get("name", "") == "gamescope" and "fps" in other.get("fields", {}).keys() and other.get("tags", {}).get("host", "") == "gameloader")
except Exception:
return False