Skip to content

Instantly share code, notes, and snippets.

@ferretwithaberet
Last active September 23, 2023 08:04
Show Gist options
  • Save ferretwithaberet/4e3e1bb7a8db57e8282696ae34d94c5d to your computer and use it in GitHub Desktop.
Save ferretwithaberet/4e3e1bb7a8db57e8282696ae34d94c5d to your computer and use it in GitHub Desktop.
Throttle policy poller to send notification on throttle policy change for asus-wmi driver
# This script can be bound to a shortcut to show the current throttle policy mode.
import subprocess
TTP_PATH = '/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy'
def send_message(message, icon):
print(message)
subprocess.Popen(['notify-send', '-a', 'Throttle policy', '-i', icon, '-t', '1000', message])
def get_throttle_policy(mode):
if mode == 0:
send_message('Normal mode', '/usr/share/icons/user_custom/fans/normal.png')
elif mode == 1:
send_message('Overboost mode', '/usr/share/icons/user_custom/fans/overboost.png')
elif mode == 2:
send_message('Silent mode', '/usr/share/icons/user_custom/fans/silent.png')
if __name__ == '__main__':
ttp_fd = open(TTP_PATH, 'r')
mode = int(ttp_fd.read())
get_throttle_policy(mode)
# Example systemd/User unit file
[Unit]
Description=Fan throttle policy notifications
[Service]
ExecStart=python3 /usr/bin/throttle_policy_poller.py
[Install]
WantedBy=default.target
# I run this script by using a systemd/User unit file so it autostarts.
# This script can be bound to a shortcut to show the current throttle policy mode.
import select
import subprocess
from get_throttle_policy import TTP_PATH, get_throttle_policy
ttp_fd = open(TTP_PATH, 'r')
ttp_fd.read()
poller = select.poll()
poller.register(ttp_fd, select.POLLERR | select.POLLPRI)
while True:
events = poller.poll()
ttp_fd.seek(0)
mode = int(ttp_fd.read())
get_throttle_policy(mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment