Skip to content

Commit fd536f9

Browse files
committed
get windows power setting name w. guid
1 parent fe01e22 commit fd536f9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/turnkeyml/common/system_info.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,22 @@ def get_windows_power_setting() -> str:
183183
Returns:
184184
str: Windows power setting.
185185
"""
186+
# https://learn.microsoft.com/en-us/windows/win32/power/power-policy-settings
187+
guid_to_name = {
188+
"a1841308-3541-4fab-bc81-f71556f20b4a": "Power Saver",
189+
"381b4222-f694-41f0-9685-ff5bb260df2e": "Balanced",
190+
"8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c": "High Performance",
191+
"e9a42b02-d5df-448d-aa00-03f14749eb61": "Ultimate Performance",
192+
}
193+
default = "Windows power setting not found"
186194
try:
187-
out = subprocess.check_output(["powercfg", "/getactivescheme"]).decode()
188-
return re.search(r"\((.*?)\)", out).group(1)
195+
out = subprocess.check_output(["powercfg", "/getactivescheme"], text=True)
196+
match = re.search(r"([a-fA-F0-9\-]{36})", out)
197+
if match:
198+
return guid_to_name.get(match.group(1).lower(), default)
189199
except subprocess.CalledProcessError:
190200
pass
191-
return "Windows power setting not found"
201+
return default
192202

193203
def get_dict(self) -> dict:
194204
"""

0 commit comments

Comments
 (0)