truenas / py-SMART

Wrapper for smartctl (smartmontools)
GNU Lesser General Public License v2.1
76 stars 35 forks source link

Added support for multiple temperature sensors #28

Closed gsuberland closed 4 years ago

gsuberland commented 4 years ago

NVMe drives often report data from multiple temperature sensors alongside the standard "Temperature" reading. This PR adds support for extracting those additional sensor values. Negative temperatures are supported.

The extracted temperature sensor data is formatted as a dict where each key represents the numeric index of the sensor, and the value represents the temperature value as reported, for example:

# cat test.py
from pySMART import DeviceList, Device
dl = DeviceList()
nv = dl.devices[-1]
print(nv.temperatures)

# python test.py
{1: 53, 2: 64, 3: 79}

I chose to use a dict with explicit keys rather than a list so that each specific sensor can still be tracked individually, even if one of the sensor readings could not be parsed. For example, if the code just exposed a list (e.g. [43, 46, 44]) as the temperature readings, then later one of the sensors reported an empty value (e.g. - in the smartctl output), we'd just get [42, 47] and have no idea which of the two sensors actually reported valid data.