fix vmware, fix hass script
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
{
|
||||
specialisation.cosmic.configuration = {
|
||||
imports = [ ./default.nix ];
|
||||
environment.etc."specialisation".text = "cosmic";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,7 +64,9 @@ in
|
||||
|
||||
# black
|
||||
color0 = theme.nord.polarNight.nord0;
|
||||
color8 = theme.nord.polarNight.nord1;
|
||||
|
||||
# Autosuggestion
|
||||
color8 = theme.nord.frost.nord10;
|
||||
|
||||
# red
|
||||
color1 = theme.nord.aurora.nord11;
|
||||
|
||||
@@ -23,6 +23,7 @@ let
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./scripts/hass.nix
|
||||
./scripts/weather.nix
|
||||
];
|
||||
# https://github.com/Alexays/Waybar/wiki/Module:-Hyprland
|
||||
@@ -48,7 +49,6 @@ in
|
||||
|
||||
modules-right = [
|
||||
"tray"
|
||||
# "custom/updates"
|
||||
"custom/lights"
|
||||
"temperature"
|
||||
"temperature#gpu"
|
||||
@@ -84,18 +84,10 @@ in
|
||||
spacing = 10;
|
||||
};
|
||||
|
||||
# "custom/updates" = {
|
||||
# tooltip = true;
|
||||
# format = { };
|
||||
# interval = 30;
|
||||
# exec = "waybar-updates";
|
||||
# return-type = "json";
|
||||
# };
|
||||
|
||||
"custom/lights" = {
|
||||
tooltip = false;
|
||||
format = "";
|
||||
on-click = "nix-shell /home/matt/.config/waybar/scripts/hass.nix --run \"python /home/matt/.config/waybar/scripts/hass.py --toggle_light light.bedroom_lights\"";
|
||||
on-click = "waybar-hass --toggle_light light.living_room_lights";
|
||||
};
|
||||
|
||||
temperature = {
|
||||
@@ -372,13 +364,6 @@ in
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
#custom-updates {
|
||||
color: ${theme.nord.frost.nord8};
|
||||
background-color: ${theme.nord.polarNight.nord0};
|
||||
${defaultOpacity}
|
||||
${borderLeft}
|
||||
}
|
||||
|
||||
#custom-lights {
|
||||
color: ${theme.nord.frost.nord8};
|
||||
background-color: ${theme.nord.polarNight.nord0};
|
||||
|
||||
@@ -1,18 +1,89 @@
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
homeassistant-api = pkgs.python3.pkgs.buildPythonPackage rec {
|
||||
pname = "homeassistant_api";
|
||||
version = "5.0.0";
|
||||
format = "pyproject";
|
||||
src = pkgs.fetchPypi {
|
||||
inherit pname version;
|
||||
sha256 = "sha256-UNKTtgInrVJtjHb1WVlUbcbhjBOtTX00eHmm54ww0rY=";
|
||||
};
|
||||
|
||||
pkgs.mkShell {
|
||||
# The Nix packages provided in the environment
|
||||
packages = [
|
||||
pkgs.python312
|
||||
pkgs.python3Packages.pip
|
||||
# Whatever other packages are required
|
||||
];
|
||||
shellHook = ''
|
||||
export TMPDIR=/tmp
|
||||
export VENV_DIR=/tmp/lights
|
||||
mkdir $VENV_DIR
|
||||
python -m venv $VENV_DIR/.venv
|
||||
source $VENV_DIR/.venv/bin/activate
|
||||
pip install homeassistant-api
|
||||
'';
|
||||
# do not run tests
|
||||
doCheck = false;
|
||||
nativeBuildInputs = with pkgs.python3.pkgs; [ poetry-core requests-cache ];
|
||||
dependencies = with pkgs.python3.pkgs; [
|
||||
requests-cache
|
||||
pydantic
|
||||
websockets
|
||||
];
|
||||
propagatedBuildInputs = with pkgs.python3.pkgs; [
|
||||
aiohttp
|
||||
aiohttp-client-cache
|
||||
requests
|
||||
simplejson
|
||||
|
||||
requests-cache
|
||||
pydantic
|
||||
websockets
|
||||
];
|
||||
pythonRelaxDeps = [
|
||||
"requests-cache"
|
||||
"pydantic"
|
||||
"websockets"
|
||||
];
|
||||
pythonImportsCheck = [
|
||||
"homeassistant_api"
|
||||
];
|
||||
};
|
||||
|
||||
pythonEnv = pkgs.python3.withPackages (ps: [
|
||||
homeassistant-api
|
||||
]);
|
||||
|
||||
waybar-hass = pkgs.writeScriptBin "waybar-hass" ''
|
||||
#!${pythonEnv}/bin/python
|
||||
|
||||
import os
|
||||
import argparse
|
||||
import time
|
||||
from homeassistant_api import Client
|
||||
|
||||
hass_url = 'http://homeassistant.local:8123/api'
|
||||
|
||||
parser = argparse.ArgumentParser(prog='hass python wrapper')
|
||||
parser.add_argument('--toggle_light')
|
||||
args = parser.parse_args()
|
||||
|
||||
def loadKey():
|
||||
token_path = "/run/secrets/desktop/hass_token"
|
||||
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()
|
||||
'';
|
||||
in
|
||||
{
|
||||
home.packages = [ waybar-hass ];
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
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()
|
||||
@@ -1,90 +0,0 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i python3 --pure
|
||||
#! nix-shell -p python3
|
||||
|
||||
import os
|
||||
import json
|
||||
import subprocess
|
||||
import re
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
tmp_path = '/tmp/waybar-scripts/updates'
|
||||
json_cache = tmp_path + "/data.json"
|
||||
git_repo = 'git@github.com:mjallen18/nix-config.git'
|
||||
|
||||
def cache_json(data):
|
||||
with open(json_cache, mode="w") as cache:
|
||||
json.dump(data, cache)
|
||||
|
||||
def create_folders():
|
||||
if not os.path.exists(tmp_path):
|
||||
os.makedirs(tmp_path)
|
||||
os.chdir(tmp_path)
|
||||
|
||||
def clone_repo():
|
||||
reset_repo()
|
||||
if os.path.exists(tmp_path) and len(os.listdir(tmp_path)) == 0:
|
||||
subprocess.run(["git", "clone", git_repo, tmp_path])
|
||||
|
||||
def check_for_flake_updates():
|
||||
return subprocess.run(["sudo", "nix", "flake", "update", "-I", tmp_path, tmp_path], capture_output=True, text=True)
|
||||
|
||||
def reset_repo():
|
||||
if os.path.exists(tmp_path) and not len(os.listdir(tmp_path)) == 0:
|
||||
subprocess.run(["git", "reset", "--hard"])
|
||||
subprocess.run(["git", "pull"])
|
||||
|
||||
def parse_output(output):
|
||||
updates_dict = {}
|
||||
updates = re.findall(r"(• Updated input '(.+)':((\n|\r|\n)(.+\((\d\d\d\d-\d\d-\d\d\)))){2})", output)
|
||||
for update in updates:
|
||||
input = re.findall(r"'(.+)':", update[0])[0].strip()
|
||||
dates = re.findall(r"(\d{4}-\d{2}-\d{2})", update[0])
|
||||
updates_dict[input] = dates
|
||||
return updates_dict
|
||||
|
||||
def check():
|
||||
data = {}
|
||||
# print("create folders")
|
||||
create_folders()
|
||||
# print("clone repo")
|
||||
clone_repo()
|
||||
# print("checking for updates")
|
||||
updates = check_for_flake_updates()
|
||||
updates_dict = parse_output(updates.stderr)
|
||||
|
||||
if len(updates_dict.keys()) > 0:
|
||||
data["text"] = ("")
|
||||
else:
|
||||
data["text"] = (u"\u00A0")
|
||||
if len(updates_dict.keys()) <= 0:
|
||||
data["tooltip"] = ("flake inputs up to date")
|
||||
else:
|
||||
data["tooltip"] = ("flake input updates:\n\n")
|
||||
|
||||
for input in updates_dict.keys():
|
||||
data["tooltip"] += "<b>{}</b>\n".format(input)
|
||||
data["tooltip"] += "Old Ref: {0} → {1}\n\n".format(updates_dict[input][0].strip(), updates_dict[input][1].strip())
|
||||
|
||||
cache_json(data)
|
||||
|
||||
print(json.dumps(data))
|
||||
|
||||
def read_cache():
|
||||
with open(json_cache, mode="r") as cache:
|
||||
print(json.dumps(json.load(cache)))
|
||||
|
||||
def main():
|
||||
now = int(datetime.now().strftime("%H"))
|
||||
if os.path.exists(json_cache):
|
||||
mtime = int(time.localtime(os.stat(json_cache).st_ctime).tm_hour)
|
||||
else:
|
||||
mtime = now + 1
|
||||
|
||||
if (now % 2 == 0 and mtime < now) or not os.path.exists(json_cache):
|
||||
check()
|
||||
else:
|
||||
read_cache()
|
||||
|
||||
main()
|
||||
@@ -67,9 +67,14 @@ in
|
||||
services = {
|
||||
preload-bing-wallpaper = {
|
||||
enable = true;
|
||||
wants = [ "network.target" ];
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "graphical-session.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
before = [ "display-manager.service" ];
|
||||
requiredBy = [
|
||||
"plymouth-quit-wait.service"
|
||||
"display-manager.service"
|
||||
];
|
||||
wantedBy = [ "display-manager.service" ];
|
||||
path = [
|
||||
pkgs.bash
|
||||
pkgs.jq
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
{
|
||||
specialisation.hyprland.configuration = {
|
||||
imports = [ ./default.nix ];
|
||||
environment.etc."specialisation".text = "hyprland";
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user