mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Using median CPU temperature.
This commit is contained in:
parent
da6d6a8094
commit
d3074eb3d8
3 changed files with 14 additions and 8 deletions
|
|
@ -114,7 +114,7 @@ def test_get_video_for_app(test_session, simple_channel, simple_video):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
def test_video_delete(test_client, test_session, test_directory, channel_factory, video_factory):
|
||||
async def test_video_delete(test_client, test_session, test_directory, channel_factory, video_factory):
|
||||
"""Video.delete() removes the video's files, but leave the DB record."""
|
||||
channel1, channel2 = channel_factory(), channel_factory()
|
||||
vid1 = video_factory(channel_id=channel1.id, with_video_file=True, with_caption_file=True)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import asyncio
|
|||
import multiprocessing
|
||||
import pathlib
|
||||
import re
|
||||
import statistics
|
||||
import subprocess
|
||||
from dataclasses import dataclass
|
||||
from decimal import Decimal
|
||||
|
|
@ -99,10 +100,11 @@ def get_cpu_info_psutil() -> CPUInfo:
|
|||
# Prefer "coretemp", fallback to the first temperature.
|
||||
temp = psutil.sensors_temperatures()
|
||||
name = 'coretemp' if 'coretemp' in temp else list(temp.keys())[0]
|
||||
# Temperatures may be None.
|
||||
temperature = int(temp.get(name)[0].current or 0)
|
||||
high_temperature = int(temp.get(name)[0].high or 0)
|
||||
critical_temperature = int(temp.get(name)[0].critical or 0)
|
||||
# Temperatures may be None. Get average temperatures from CPU because one core may be hot.
|
||||
temperatures = temp.get(name)
|
||||
temperature = statistics.median([i.current or 0 for i in temperatures])
|
||||
high_temperature = statistics.median([i.high or 0 for i in temperatures])
|
||||
critical_temperature = statistics.median([i.critical or 0 for i in temperatures])
|
||||
|
||||
# Temperatures my not exist.
|
||||
if not high_temperature:
|
||||
|
|
@ -120,9 +122,9 @@ def get_cpu_info_psutil() -> CPUInfo:
|
|||
min_frequency=int(cpu_freq.min),
|
||||
max_frequency=int(cpu_freq.max),
|
||||
percent=int(percent),
|
||||
temperature=temperature,
|
||||
high_temperature=high_temperature,
|
||||
critical_temperature=critical_temperature,
|
||||
temperature=int(temperature),
|
||||
high_temperature=int(high_temperature),
|
||||
critical_temperature=int(critical_temperature),
|
||||
)
|
||||
return info
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ async def test_get_cpu_info():
|
|||
info = await status.get_cpu_info()
|
||||
assert isinstance(info, status.CPUInfo)
|
||||
assert isinstance(info.percent, int)
|
||||
assert isinstance(info.temperature, int)
|
||||
assert isinstance(info.high_temperature, int)
|
||||
assert isinstance(info.critical_temperature, int)
|
||||
|
||||
with mock.patch('wrolpi.status.get_cpu_info_psutil') as mock_get_cpu_info_psutil:
|
||||
# Fallback to subprocess when psutil is not available.
|
||||
|
|
@ -30,6 +33,7 @@ async def test_get_cpu_info():
|
|||
info = await status.get_cpu_info()
|
||||
assert isinstance(info, status.CPUInfo)
|
||||
assert isinstance(info.percent, int)
|
||||
assert info.temperature >= 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue