Add CLI flags for Steam avoidance and instant transitions
If called manually, ignore Steam by default. The systemd service checks for Steam as that is more likely to run at an annoying time.
This commit is contained in:
parent
1db9f88179
commit
9a03bb684b
2 changed files with 23 additions and 6 deletions
|
@ -1,9 +1,11 @@
|
||||||
#!/bin/env python
|
#!/bin/env python
|
||||||
"""Sets the monitor temperature based on the current time using Hyprsunset"""
|
"""Sets the monitor temperature based on the current time using Hyprsunset"""
|
||||||
|
from argparse import ArgumentParser, Namespace
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os import environ
|
from os import environ
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from socket import AF_UNIX, SOCK_STREAM, socket
|
from socket import AF_UNIX, SOCK_STREAM, socket
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
|
|
||||||
type Range = tuple[float, float]
|
type Range = tuple[float, float]
|
||||||
|
@ -63,9 +65,12 @@ def get_temperature(hyprsunset: socket) -> int:
|
||||||
return int(hyprsunset.recv(8))
|
return int(hyprsunset.recv(8))
|
||||||
|
|
||||||
|
|
||||||
def set_temperature(hyprsunset: socket, temperature: float) -> None:
|
def set_temperature(hyprsunset: socket, temperature: float, /, instant: bool = False) -> None:
|
||||||
# In theory the message might not send in one go, but in practice it does so I won't bother handling the error
|
# In theory the message might not send in one go, but in practice it does so I won't bother handling the error
|
||||||
_ = hyprsunset.send(f"temperature {temperature:.1f}".encode())
|
_ = hyprsunset.send(f"temperature {temperature:.1f}".encode())
|
||||||
|
if instant:
|
||||||
|
# Setting the temperature twice in quick succession sometimes skips the transition period
|
||||||
|
set_temperature(hyprsunset, temperature, instant=False)
|
||||||
|
|
||||||
|
|
||||||
def on_steam() -> bool:
|
def on_steam() -> bool:
|
||||||
|
@ -76,17 +81,29 @@ def on_steam() -> bool:
|
||||||
return pid_dir.is_dir()
|
return pid_dir.is_dir()
|
||||||
|
|
||||||
|
|
||||||
def main(sunrise: Range, sunset: Range, temperature_range: Range) -> None:
|
def main(sunrise: Range, sunset: Range, temperature_range: Range, /, check_steam: bool = False, instant: bool = False) -> None:
|
||||||
"""Adjusts the monitor temperature based on the current time"""
|
"""Adjusts the monitor temperature based on the current time"""
|
||||||
hyprsunset = setup_socket()
|
hyprsunset = setup_socket()
|
||||||
temperature = int(calculate_temperature(sunrise, sunset, temperature_range))
|
temperature = int(calculate_temperature(sunrise, sunset, temperature_range))
|
||||||
if temperature != get_temperature(hyprsunset) and not on_steam():
|
if temperature != get_temperature(hyprsunset):
|
||||||
set_temperature(hyprsunset, temperature)
|
if check_steam and on_steam():
|
||||||
|
return
|
||||||
|
set_temperature(hyprsunset, temperature, instant=instant)
|
||||||
|
|
||||||
|
|
||||||
|
class Arguments(Namespace):
|
||||||
|
check_steam: bool = False
|
||||||
|
instant: bool = False
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
parser = ArgumentParser(description="Adjusts the temperature of your screen based on the time of day")
|
||||||
|
_ = parser.add_argument("-s", "--check-steam", action="store_true", help="Don't adjust temperature if Steam is active")
|
||||||
|
_ = parser.add_argument("-i", "--instant", action="store_true", help="Try to instantly change temperature")
|
||||||
|
args = cast(Arguments, parser.parse_args())
|
||||||
main(
|
main(
|
||||||
(day_elapsed(5), day_elapsed(7)),
|
(day_elapsed(5), day_elapsed(7)),
|
||||||
(day_elapsed(21), day_elapsed(23)),
|
(day_elapsed(21), day_elapsed(23)),
|
||||||
(2500.0, 6000.0)
|
(2500.0, 6000.0),
|
||||||
|
check_steam=args.check_steam,
|
||||||
|
instant=args.instant
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,4 +3,4 @@ Description=Sets the monitor temperature based on the time of day
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/bin/env python -O /home/mbradley/scripts/sunset.py
|
ExecStart=/bin/env python -O /home/mbradley/scripts/sunset.py --check-steam
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue