Skip to content

Commit

Permalink
[BFN] Updated platform API for thermal (#8)
Browse files Browse the repository at this point in the history
* Signed-off-by: Vadym Yashchenko <vadymx.yashchenko@intel.com>
  • Loading branch information
VadymYashchenko authored and Andriy Kokhan committed Dec 17, 2021
1 parent d83d686 commit 066cefe
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ def _value_get(d: dict, key_prefix, key_suffix=''):

# Thermal -> ThermalBase -> DeviceBase
class Thermal(ThermalBase):
def __init__(self, chip, label):
def __init__(self, chip, label, index = 0):
self.__chip = chip
self.__label = label
self.__name = f"{chip}:{label}".lower().replace(' ', '-')
self.__collect_temp = []
self.__index = index

def __get(self, attr_prefix, attr_suffix):
sensor_data = _sensors_get().get(self.__chip, {}).get(self.__label, {})
Expand All @@ -80,7 +82,10 @@ def __get(self, attr_prefix, attr_suffix):

# ThermalBase interface methods:
def get_temperature(self) -> float:
return float(self.__get('temp', 'input'))
temp = self.__get('temp', 'input')
self.__collect_temp.append(float(temp))
self.__collect_temp.sort()
return float(temp)

def get_high_threshold(self) -> float:
return float(self.__get('temp', 'max'))
Expand All @@ -107,11 +112,38 @@ def get_status(self):
def is_replaceable(self):
return False

def get_low_threshold(self) -> float:
return float(self.__get('temp', 'min'))

def get_serial(self):
return 'N/A'

def get_minimum_recorded(self) -> float:
temp = self.__collect_temp[0] if len(self.__collect_temp) > 0 else 0.1
temp = temp if temp > 0.0 else 0.1
return float(temp)

def get_maximum_recorded(self) -> float:
temp = self.__collect_temp[-1] if len(self.__collect_temp) > 0 else 100.0
temp = temp if temp <= 100.0 else 100.0
return float(temp)

def get_position_in_parent(self):
return self.__index

def set_high_threshold(self, temperature):
return False

def set_low_threshold(self, temperature):
return False

def thermal_list_get():
l = []
index = 0
for chip, chip_data in _sensors_get().items():
for sensor, sensor_data in chip_data.items():
# add only temperature sensors
if _value_get(sensor_data, "temp") is not None:
l.append(Thermal(chip, sensor))
l.append(Thermal(chip, sensor, index))
index += 1
return l

0 comments on commit 066cefe

Please sign in to comment.