so many sops
This commit is contained in:
42
modules/desktop-environments/hyprland/config/waybar/scripts/hass.py
Executable file
42
modules/desktop-environments/hyprland/config/waybar/scripts/hass.py
Executable file
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
import argparse
|
||||
import time
|
||||
from homeassistant_api import Client
|
||||
|
||||
hass_url = 'https://hass.mjallen.dev/api'
|
||||
|
||||
parser = argparse.ArgumentParser(prog='hass python wrapper')
|
||||
parser.add_argument('--toggle_light')
|
||||
args = parser.parse_args()
|
||||
|
||||
def loadKey():
|
||||
token_path = ""
|
||||
for folder in range(1,100):
|
||||
if os.path.exists("/run/secrets.d/" + str(folder) + "/desktop/hass_token"):
|
||||
token_path = "/run/secrets.d/" + str(folder) + "/desktop/hass_token"
|
||||
break
|
||||
with open(token_path, "r") as key_file:
|
||||
key = key_file.readline()
|
||||
return key
|
||||
|
||||
def toggle_light(client, light):
|
||||
lights = client.get_domain("light")
|
||||
lights.toggle(entity_id=light)
|
||||
time.sleep(0.5)
|
||||
light_entity = client.get_entity(entity_id=light)
|
||||
state = light_entity.get_state()
|
||||
if state.state == 'on':
|
||||
return ""
|
||||
else:
|
||||
return ""
|
||||
|
||||
def main():
|
||||
token = loadKey()
|
||||
|
||||
with Client(hass_url, token) as client:
|
||||
if args.toggle_light is not None:
|
||||
status = toggle_light(client=client, light=args.toggle_light)
|
||||
|
||||
print("{ text: \"" + status + "\" }")
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user