diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..4a4726a --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_nix diff --git a/krha.py b/krha.py index d97ff4f..3232108 100755 --- a/krha.py +++ b/krha.py @@ -1,10 +1,12 @@ #!/usr/bin/python3 -import dbus.service + +from configparser import ConfigParser from dbus.mainloop.glib import DBusGMainLoop from gi.repository import GLib -import requests +import dbus.service import json import os +import requests DBusGMainLoop(set_as_default=True) @@ -17,8 +19,22 @@ iface = "org.kde.krunner1" class Runner(dbus.service.Object): def __init__(self): dbus.service.Object.__init__(self, dbus.service.BusName("dev.suah.krha", dbus.SessionBus()), objpath) - self.api_key = os.environ.get("HA_API_KEY", "") - self.ha_url = os.environ.get("HA_URL", "").rstrip('/') + config = ConfigParser() + config_path = os.path.expanduser('~/.config/krunnerrc') + config.read(config_path) + + try: + self.api_key = config.get('Runners][HomeAssistant', 'api_key') + except: + self.api_key = os.environ.get("HA_API_KEY", "") + + try: + self.ha_url = config.get('Runners][HomeAssistant', 'ha_url') + except: + self.ha_url = os.environ.get("HA_URL", "") + + if self.ha_url: + self.ha_url = self.ha_url.rstrip('/') @dbus.service.method(iface, in_signature='s', out_signature='a(sssida{sv})') def Match(self, query: str): diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..510e89b --- /dev/null +++ b/shell.nix @@ -0,0 +1,20 @@ +{ pkgs ? import { } }: +with pkgs; +let + pythonEnv = python3.withPackages ( + p: with p; [ + dbus-python + pygobject3 + requests + ] + ); +in pkgs.mkShell { + shellHook = '' + PS1='\u@\h:\w; ' + ''; + buildInputs = with pkgs; [ + pythonEnv + wrapGAppsHook + gobject-introspection + ]; +}