Skip to content

Commit

Permalink
update fan.py and thermal.py to can show psu.temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostar Yang committed Jul 29, 2021
1 parent 3cec3a2 commit 4eac8ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try:
from sonic_platform_base.psu_base import PsuBase
#from sonic_platform.fan import Fan
from sonic_platform.thermal import Thermal
from .helper import APIHelper
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
Expand Down Expand Up @@ -64,6 +64,8 @@ def __initialize_fan(self):
for fan_index in range(0, PSU_NUM_FAN[self.index]):
fan = Fan(fan_index, 0, is_psu_fan=True, psu_index=self.index)
self._fan_list.append(fan)

self._thermal_list.append(Thermal(is_psu=True, psu_index=self.index))

def get_voltage(self):
"""
Expand Down
28 changes: 12 additions & 16 deletions device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@
},
}

THERMAL_NAME_LIST = ["Temp sensor 1", "Temp sensor 2",
"Temp sensor 3", "Temp sensor 4"]

PSU_THERMAL_NAME_LIST = ["PSU-1 temp sensor 1", "PSU-2 temp sensor 2"]

SYSFS_PATH = "/sys/bus/i2c/devices"

class Thermal(ThermalBase):
"""Platform-specific Thermal class"""

THERMAL_NAME_LIST = []
PSU_THERMAL_NAME_LIST = []
SYSFS_PATH = "/sys/bus/i2c/devices"

def __init__(self, thermal_index=0, is_psu=False, psu_index=0):
self.index = thermal_index
self.is_psu = is_psu
Expand All @@ -59,13 +61,7 @@ def __init__(self, thermal_index=0, is_psu=False, psu_index=0):
psu_i2c_bus = PSU_CPLD_I2C_MAPPING[psu_index]["num"]
psu_i2c_addr = PSU_CPLD_I2C_MAPPING[psu_index]["addr"]
self.cpld_path = PSU_I2C_PATH.format(psu_i2c_bus, psu_i2c_addr)
# Add thermal name
self.THERMAL_NAME_LIST.append("Temp sensor 1")
self.THERMAL_NAME_LIST.append("Temp sensor 2")
self.THERMAL_NAME_LIST.append("Temp sensor 3")
self.PSU_THERMAL_NAME_LIST.append("PSU-1 temp sensor 1")
self.PSU_THERMAL_NAME_LIST.append("PSU-2 temp sensor 1")


# Set hwmon path
i2c_path = {
0: "18-004b/hwmon/hwmon*/",
Expand All @@ -74,8 +70,8 @@ def __init__(self, thermal_index=0, is_psu=False, psu_index=0):
3: "21-004a/hwmon/hwmon*/"
}.get(self.index, None)

self.hwmon_path = "{}/{}".format(self.SYSFS_PATH, i2c_path)
self.ss_key = self.THERMAL_NAME_LIST[self.index]
self.hwmon_path = "{}/{}".format(SYSFS_PATH, i2c_path)
self.ss_key = THERMAL_NAME_LIST[self.index]
self.ss_index = 1

def __read_txt_file(self, file_path):
Expand Down Expand Up @@ -137,7 +133,7 @@ def get_high_threshold(self):
up to nearest thousandth of one degree Celsius, e.g. 30.125
"""
if self.is_psu:
return 0
return 80

temp_file = "temp{}_max".format(self.ss_index)
return self.__get_temp(temp_file)
Expand All @@ -164,9 +160,9 @@ def get_name(self):
string: The name of the thermal device
"""
if self.is_psu:
return self.PSU_THERMAL_NAME_LIST[self.psu_index]
return PSU_THERMAL_NAME_LIST[self.psu_index]
else:
return self.THERMAL_NAME_LIST[self.index]
return THERMAL_NAME_LIST[self.index]

def get_presence(self):
"""
Expand Down

0 comments on commit 4eac8ba

Please sign in to comment.