diff --git a/modules/videos/video/test/test_api.py b/modules/videos/video/test/test_api.py index 2a012bdd..b0fe82b2 100644 --- a/modules/videos/video/test/test_api.py +++ b/modules/videos/video/test/test_api.py @@ -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) diff --git a/wrolpi/status.py b/wrolpi/status.py index fee55570..4c337d74 100755 --- a/wrolpi/status.py +++ b/wrolpi/status.py @@ -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 diff --git a/wrolpi/test/test_status.py b/wrolpi/test/test_status.py index f4dc60a4..a7ce1b91 100644 --- a/wrolpi/test/test_status.py +++ b/wrolpi/test/test_status.py @@ -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