Skip to content

Commit 133dbcf

Browse files
committed
Fix sensor names for Intel GPU, avoid exception when fan speed is None
1 parent b2e97af commit 133dbcf

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

library/sensors/sensors_librehardwaremonitor.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,15 @@ def temperature() -> float:
230230
@staticmethod
231231
def fan_percent() -> float:
232232
mb = get_hw_and_update(Hardware.HardwareType.Motherboard)
233-
for sh in mb.SubHardware:
234-
sh.Update()
235-
for sensor in sh.Sensors:
236-
if sensor.SensorType == Hardware.SensorType.Control and "#2" in str(
237-
sensor.Name): # Is Motherboard #2 Fan always the CPU Fan ?
238-
return float(sensor.Value)
233+
try:
234+
for sh in mb.SubHardware:
235+
sh.Update()
236+
for sensor in sh.Sensors:
237+
if sensor.SensorType == Hardware.SensorType.Control and "#2" in str(
238+
sensor.Name): # Is Motherboard #2 Fan always the CPU Fan ?
239+
return float(sensor.Value)
240+
except:
241+
pass
239242

240243
# No Fan Speed sensor for this CPU model
241244
return math.nan
@@ -274,10 +277,15 @@ def stats(cls) -> Tuple[float, float, float, float]: # load (%) / used mem (%)
274277
for sensor in gpu_to_use.Sensors:
275278
if sensor.SensorType == Hardware.SensorType.Load and str(sensor.Name).startswith("GPU Core"):
276279
load = float(sensor.Value)
280+
elif sensor.SensorType == Hardware.SensorType.Load and str(sensor.Name).startswith("D3D 3D") and math.isnan(
281+
load):
282+
# Only use D3D usage if global "GPU Core" sensor is not available, because it is less
283+
# precise and does not cover the entire GPU: https://www.hwinfo.com/forum/threads/what-is-d3d-usage.759/
284+
load = float(sensor.Value)
277285
elif sensor.SensorType == Hardware.SensorType.SmallData and str(sensor.Name).startswith("GPU Memory Used"):
278286
used_mem = float(sensor.Value)
279287
elif sensor.SensorType == Hardware.SensorType.SmallData and str(sensor.Name).startswith(
280-
"D3D Dedicated Memory Used") and math.isnan(used_mem):
288+
"D3D") and str(sensor.Name).endswith("Memory Used") and math.isnan(used_mem):
281289
# Only use D3D memory usage if global "GPU Memory Used" sensor is not available, because it is less
282290
# precise and does not cover the entire GPU: https://www.hwinfo.com/forum/threads/what-is-d3d-usage.759/
283291
used_mem = float(sensor.Value)
@@ -312,9 +320,12 @@ def fan_percent(cls) -> float:
312320
# GPU not supported
313321
return math.nan
314322

315-
for sensor in gpu_to_use.Sensors:
316-
if sensor.SensorType == Hardware.SensorType.Control:
317-
return float(sensor.Value)
323+
try:
324+
for sensor in gpu_to_use.Sensors:
325+
if sensor.SensorType == Hardware.SensorType.Control:
326+
return float(sensor.Value)
327+
except:
328+
pass
318329

319330
# No Fan Speed sensor for this GPU model
320331
return math.nan

0 commit comments

Comments
 (0)