Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat GPU data for HA and add unit test #35

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions glances_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ async def get_ha_sensor_data(self) -> dict[str, Any]:
if data := self.data.get("gpu"):
sensor_data["gpu"] = {}
for sensor in data:
sensor_data["gpu"][f"GPU_{sensor['gpu_id']}__{sensor['name']}"] = {
"name": sensor["name"],
"temperature": sensor["temperature"],
"mem": sensor["mem"],
"proc": sensor["proc"],
"fan_speed": sensor["fan_speed"] if "fan_speed" in sensor else 0,
sensor_data["gpu"][f"{sensor['name']} (GPU {sensor['gpu_id']})"] = {
"temperature": sensor.get("temperature", 0),
"mem": sensor.get("mem", 0),
"proc": sensor.get("proc", 0),
"fan_speed": sensor.get("fan_speed", 0),
}
return sensor_data
35 changes: 35 additions & 0 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the interaction with the Glances API."""

from typing import Any

import pytest
Expand Down Expand Up @@ -130,6 +131,26 @@
"key": "mnt_point",
},
],
"gpu": [
{
"key": "gpu_id",
"gpu_id": 0,
"name": "NVIDIA GeForce RTX 4080",
"mem": 13.333489176233513,
"proc": 12,
"temperature": 38,
"fan_speed": 30,
},
{
"key": "gpu_id",
"gpu_id": 1,
"name": "NVIDIA GeForce RTX 3080",
"mem": 8.41064453125,
"proc": 26,
"temperature": 51,
"fan_speed": 0,
},
],
"mem": {
"total": 3976318976,
"available": 2878337024,
Expand Down Expand Up @@ -266,6 +287,20 @@
"docker": {"docker_active": 2, "docker_cpu_use": 77.2, "docker_memory_use": 1149.6},
"uptime": "3 days, 10:25:20",
"percpu": {"0": {"cpu_use_percent": 22.1}, "1": {"cpu_use_percent": 17.2}},
"gpu": {
"NVIDIA GeForce RTX 4080 (GPU 0)": {
"mem": 13.333489176233513,
"proc": 12,
"temperature": 38,
"fan_speed": 30,
},
"NVIDIA GeForce RTX 3080 (GPU 1)": {
"mem": 8.41064453125,
"proc": 26,
"temperature": 51,
"fan_speed": 0,
},
},
}


Expand Down
Loading