1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Fix cpu temperature reporting for Armbian on Odroid (#48903)

Some systems expose cpu temperatures differently in
psutil. Specifically, running armbian on the Odroid xu4 sbc gives the
following temerature output:

>>> pp.pprint(psutil.sensors_temperatures())
{   'cpu0-thermal':
    [   shwtemp(label='', current=54.0, high=115.0, critical=115.0)],
    'cpu1-thermal':
    [   shwtemp(label='', current=56.0, high=115.0, critical=115.0)],
    'cpu2-thermal':
    [   shwtemp(label='', current=58.0, high=115.0, critical=115.0)],
    'cpu3-thermal':
    [   shwtemp(label='', current=56.0, high=115.0, critical=115.0)],
}

Since the cpu number is embedded inside the name, the current code
can't find it.

To fix this, check both the name and the constructed label for matches
against CPU_SENSOR_PREFIXES, and add the appropriate label
cpu0-thermal in the prefix list.

While this is slightly less efficient that just generating the label
and checking it, it results in easier to understand code.
This commit is contained in:
Phil Hollenback 2021-04-09 01:25:03 -07:00 committed by GitHub
parent d1df6e6fba
commit e7e53b879e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,6 +180,7 @@ CPU_SENSOR_PREFIXES = [
"soc-thermal 1",
"soc_thermal 1",
"Tctl",
"cpu0-thermal",
]
@ -504,7 +505,9 @@ def _read_cpu_temperature() -> float | None:
# In case the label is empty (e.g. on Raspberry PI 4),
# construct it ourself here based on the sensor key name.
_label = f"{name} {i}" if not entry.label else entry.label
if _label in CPU_SENSOR_PREFIXES:
# check both name and label because some systems embed cpu# in the
# name, which makes label not match because label adds cpu# at end.
if _label in CPU_SENSOR_PREFIXES or name in CPU_SENSOR_PREFIXES:
return cast(float, round(entry.current, 1))
return None