Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgillij committed Feb 10, 2021
1 parent 8a0de08 commit 15c8308
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions amdfan/amdfan.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _verify_card(self):
for endpoint in self.AMD_FIELDS:
if endpoint not in self._endpoints:
LOGGER.info(
"skipping card: %s as its missing endpoint %s", self._id, endpoint
f"skipping card: {self._id} missing endpoint {endpoint}"
)
raise FileNotFoundError

Expand All @@ -73,7 +73,7 @@ def write_endpoint(self, endpoint, data):
return e.write(str(data))
except PermissionError:
LOGGER.error(
"Failed writing to devfs file, are you sure your running as root?"
"Failed writing to devfs file, are you running as root?"
)
sys.exit(1)

Expand All @@ -97,10 +97,13 @@ def fan_min(self):
return int(self.read_endpoint("pwm1_min"))

def set_system_controlled_fan(self, state):

system_controlled_fan = 2
manual_control = 1

self.write_endpoint(
"pwm1_enable", 2 if state else 1
) # actually go to the right pwm state
# self.write_endpoint('pwm1_enable', 0 if state else 1)
"pwm1_enable", system_controlled_fan if state else manual_control
)

def set_fan_speed(self, speed):
if speed >= 100:
Expand Down Expand Up @@ -134,7 +137,7 @@ def _get_cards(self, cards_to_scan):
try:
cards[node] = Card(node)
except FileNotFoundError:
# if card lacks hwmon or the required devfs files, its likely not
# if card lacks hwmon or required devfs files, its not
# amdgpu, and definitely not compatible with this software
continue
return cards
Expand All @@ -159,7 +162,10 @@ def main(self):
speed = 0

LOGGER.debug(
f"{name}: Temp {temp}, Setting fan speed to: {speed}, fan speed{card.fan_speed}, min:{card.fan_min}, max:{card.fan_max}"
f"{name}: Temp {temp}, \
Setting fan speed to: {speed}, \
fan speed{card.fan_speed}, \
min:{card.fan_min}, max:{card.fan_max}"
)

card.set_fan_speed(speed)
Expand All @@ -186,7 +192,8 @@ def main():
- [80, 100]
# optional
# cards: # can be any card returned from `ls /sys/class/drm | grep "^card[[:digit:]]$"`
# cards:
# can be any card returned from `ls /sys/class/drm | grep "^card[[:digit:]]$"`
# - card0
"""
config = None
Expand Down Expand Up @@ -218,19 +225,23 @@ def __init__(self, points: list):

if np.min(self.speeds) < 0:
raise ValueError(
"Fan curve contains negative speeds, speed should be in [0,100]"
"Fan curve contains negative speeds, \
speed should be in [0,100]"
)
if np.max(self.speeds) > 100:
raise ValueError(
"Fan curve contains speeds greater than 100, speed should be in [0,100]"
"Fan curve contains speeds greater than 100, \
speed should be in [0,100]"
)
if np.any(np.diff(self.temps) <= 0):
raise ValueError(
"Fan curve points should be strictly monotonically increasing, configuration error ?"
"Fan curve points should be strictly monotonically increasing, \
configuration error ?"
)
if np.any(np.diff(self.speeds) < 0):
raise ValueError(
"Curve fan speeds should be monotonically increasing, configuration error ?"
"Curve fan speeds should be monotonically increasing, \
configuration error ?"
)

def get_speed(self, temp):
Expand Down Expand Up @@ -282,7 +293,9 @@ def show_table(scanner):
elif command == "set":
card_to_set = Prompt.ask("Which card?", choices=scanner.cards.keys())
while True:
fan_speed = Prompt.ask("Fan speed, [1%..100%] or 'auto'", default="auto")
fan_speed = Prompt.ask(
"Fan speed, [1%..100%] or 'auto'", default="auto"
)

if fan_speed.isdigit():
if int(fan_speed) >= 1 and int(fan_speed) <= 100:
Expand All @@ -298,5 +311,9 @@ def show_table(scanner):
scanner.cards.get(card_to_set).set_system_controlled_fan(True)
else:
LOGGER.info(f"Setting fan speed to {fan_speed}%")
c.print(scanner.cards.get(card_to_set).set_fan_speed(int(fan_speed)))
c.print(
scanner.cards.get(card_to_set).set_fan_speed(
int(fan_speed)
)
)
sys.exit(1)

0 comments on commit 15c8308

Please sign in to comment.