Skip to content

Commit 066cefe

Browse files
VadymYashchenkoAndriy Kokhan
authored andcommitted
[BFN] Updated platform API for thermal (#8)
* Signed-off-by: Vadym Yashchenko <[email protected]>
1 parent d83d686 commit 066cefe

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

  • platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform

platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/thermal.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ def _value_get(d: dict, key_prefix, key_suffix=''):
6868

6969
# Thermal -> ThermalBase -> DeviceBase
7070
class Thermal(ThermalBase):
71-
def __init__(self, chip, label):
71+
def __init__(self, chip, label, index = 0):
7272
self.__chip = chip
7373
self.__label = label
7474
self.__name = f"{chip}:{label}".lower().replace(' ', '-')
75+
self.__collect_temp = []
76+
self.__index = index
7577

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

8183
# ThermalBase interface methods:
8284
def get_temperature(self) -> float:
83-
return float(self.__get('temp', 'input'))
85+
temp = self.__get('temp', 'input')
86+
self.__collect_temp.append(float(temp))
87+
self.__collect_temp.sort()
88+
return float(temp)
8489

8590
def get_high_threshold(self) -> float:
8691
return float(self.__get('temp', 'max'))
@@ -107,11 +112,38 @@ def get_status(self):
107112
def is_replaceable(self):
108113
return False
109114

115+
def get_low_threshold(self) -> float:
116+
return float(self.__get('temp', 'min'))
117+
118+
def get_serial(self):
119+
return 'N/A'
120+
121+
def get_minimum_recorded(self) -> float:
122+
temp = self.__collect_temp[0] if len(self.__collect_temp) > 0 else 0.1
123+
temp = temp if temp > 0.0 else 0.1
124+
return float(temp)
125+
126+
def get_maximum_recorded(self) -> float:
127+
temp = self.__collect_temp[-1] if len(self.__collect_temp) > 0 else 100.0
128+
temp = temp if temp <= 100.0 else 100.0
129+
return float(temp)
130+
131+
def get_position_in_parent(self):
132+
return self.__index
133+
134+
def set_high_threshold(self, temperature):
135+
return False
136+
137+
def set_low_threshold(self, temperature):
138+
return False
139+
110140
def thermal_list_get():
111141
l = []
142+
index = 0
112143
for chip, chip_data in _sensors_get().items():
113144
for sensor, sensor_data in chip_data.items():
114145
# add only temperature sensors
115146
if _value_get(sensor_data, "temp") is not None:
116-
l.append(Thermal(chip, sensor))
147+
l.append(Thermal(chip, sensor, index))
148+
index += 1
117149
return l

0 commit comments

Comments
 (0)