aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/sys_utils/sysfs_thermal.py
blob: 7409fbe177630a7b459c1a0798ad50c91739add3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# Copyright 2017 Ettus Research, A National Instruments Company
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""
sysfs thermal sensors API
"""

import pyudev

def read_thermal_sensors_value(sensor_type, data_probe):
    """
    This function will return a list of all the float value of
    the thermal sensor subsystem = 'thermal' and type = sensor_type

    Arguments:
    sensor_type -- Is attribute "type" of udev.  This can be fpga-thermal-zone,
                   magnesium-db0-zone, croc-ec-thermal etc.
    data_probe -- is one of the attribute of that sensor. This can be 'temp' in
                  the case of thermal-zone or 'cur_state' in the case of a
                  cooling device.
    """
    reading_sensors = [x.attributes.asint(data_probe) for x in pyudev.Context()
                       .list_devices(subsystem='thermal')
                       .match_attribute('type', sensor_type)]
    return reading_sensors

def read_thermal_sensor_value(sensor_type, data_probe):
    """
    This function will return the float value of the thermal sensor
    which is under thermal subsystem.

    Arguments:
    sensor_type -- Is attribute "type" of udev.  This can be fpga-thermal-zone,
                   magnesium-db0-zone, etc.
    data_probe -- is one of the attribute of that sensor. This can be 'temp' in
                  the case of thermal-zone or 'cur_state' in the case of a
                  cooling device.
    """
    sensor_val = read_thermal_sensors_value(sensor_type, data_probe)
    if not sensor_val:
        raise IndexError("No {} attribute found for {} sensor.".format(data_probe, sensor_type))
    return sensor_val[0]