Skip to content

Commit

Permalink
[Author]:[email protected] [Jira ID]:N/A [Description]: fix fan …
Browse files Browse the repository at this point in the history
…led issue
  • Loading branch information
nicwu-cel committed Apr 11, 2022
1 parent 138ba89 commit 38fce5f
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import os
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
# ------------------------------------------------------------------
# HISTORY:
# 5/1/2022 (A.D.)
# add function:set_status_led,
# Solve the problem that when a fan is pulled out, the Fan LED on the front panel is still green Issue-#11525
# ------------------------------------------------------------------
FAN_DIRECTION_FILE_PATH = "/var/fan_direction"


Expand Down Expand Up @@ -62,3 +68,46 @@ def get_status(self):
status = True if (speed != 0) else False
return status

def get_target_speed(self):
"""
Retrieves the target (expected) speed of the fan
Returns:
An integer, the percentage of full fan speed, in the range 0 (off)
to 100 (full speed)
"""
target_speed = 0
if self.is_psu_fan:
# Target speed not usually supported for PSU fans
target_speed = "N/A"
else:
idx = (self.fantray_index - 1) * 1 + self.fan_index
attr = "fan" + str(idx) + "_pwm"
pwm_path = "/sys/devices/pci0000:00/0000:00:12.0/i2c-0/i2c-2/2-0066/" + attr
pwm = 0
with open(pwm_path, "r") as f:
pwm = f.read()

percentage = int(pwm.strip())
speed_percentage = int(round(percentage / 255 * 100))
target_speed = speed_percentage

return target_speed

def set_status_led(self, color):
color_dict = {"green": "STATUS_LED_COLOR_GREEN",
"red": "STATUS_LED_COLOR_AMBER"}
color = color_dict.get(color, "off")
index = str(self.fantray_index - 1)
led_device_name = "FANTRAY{}".format(self.fantray_index) + "_LED"

result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color)
if result is False:
return False
device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name']
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path())
self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path())

self.pddf_obj.create_attr('dev_ops', 'set_status', self.pddf_obj.get_led_path())
return True

0 comments on commit 38fce5f

Please sign in to comment.