diff options
-rw-r--r-- | nixos/tests/home-assistant.nix | 8 | ||||
-rw-r--r-- | pkgs/servers/home-assistant/cli.nix | 35 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 2 |
3 files changed, 44 insertions, 1 deletions
diff --git a/nixos/tests/home-assistant.nix b/nixos/tests/home-assistant.nix index 7627bb07901d..73c1e71eb516 100644 --- a/nixos/tests/home-assistant.nix +++ b/nixos/tests/home-assistant.nix @@ -4,6 +4,7 @@ let configDir = "/var/lib/foobar"; apiPassword = "some_secret"; mqttPassword = "another_secret"; + hassCli = "hass-cli --server http://hass:8123 --password '${apiPassword}'"; in { name = "home-assistant"; @@ -16,7 +17,7 @@ in { { pkgs, ... }: { environment.systemPackages = with pkgs; [ - mosquitto + mosquitto home-assistant-cli ]; services.home-assistant = { inherit configDir; @@ -71,6 +72,11 @@ in { $hass->waitUntilSucceeds("mosquitto_pub -V mqttv311 -t home-assistant/test -u homeassistant -P '${mqttPassword}' -m let_there_be_light"); $hass->succeed("curl http://localhost:8123/api/states/binary_sensor.mqtt_binary_sensor -H 'x-ha-access: ${apiPassword}' | grep -qF '\"state\": \"on\"'"); + # Toggle a binary sensor using hass-cli + $hass->succeed("${hassCli} entity get binary_sensor.mqtt_binary_sensor | grep -qF '\"state\": \"on\"'"); + $hass->succeed("${hassCli} entity edit binary_sensor.mqtt_binary_sensor --json='{\"state\": \"off\"}'"); + $hass->succeed("curl http://localhost:8123/api/states/binary_sensor.mqtt_binary_sensor -H 'x-ha-access: ${apiPassword}' | grep -qF '\"state\": \"off\"'"); + # Print log to ease debugging my $log = $hass->succeed("cat ${configDir}/home-assistant.log"); print "\n### home-assistant.log ###\n"; diff --git a/pkgs/servers/home-assistant/cli.nix b/pkgs/servers/home-assistant/cli.nix new file mode 100644 index 000000000000..c889610963d6 --- /dev/null +++ b/pkgs/servers/home-assistant/cli.nix @@ -0,0 +1,35 @@ +{ lib, python3 }: + +python3.pkgs.buildPythonApplication rec { + pname = "homeassistant-cli"; + version = "0.3.0"; + + src = python3.pkgs.fetchPypi { + inherit pname version; + sha256 = "42d7cb008801d7a448b62aed1fc46dd450ee67397bf16faabb02f691417db4b2"; + }; + + postPatch = '' + # Ignore pinned versions + sed -i "s/'\(.*\)==.*'/'\1'/g" setup.py + ''; + + propagatedBuildInputs = with python3.pkgs; [ + requests pyyaml netdisco click click-log tabulate idna jsonpath_rw jinja2 + ]; + + checkInputs = with python3.pkgs; [ + pytest requests-mock + ]; + + checkPhase = '' + pytest + ''; + + meta = with lib; { + description = "Command-line tool for Home Asssistant"; + homepage = https://github.com/home-assistant/home-assistant-cli; + license = licenses.asl20; + maintainers = with maintainers; [ dotlambda ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index bd139f8b8f41..fccd863b9c7a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13551,6 +13551,8 @@ in home-assistant = callPackage ../servers/home-assistant { }; + home-assistant-cli = callPackage ../servers/home-assistant/cli.nix { }; + hydron = callPackage ../servers/hydron { }; ircdHybrid = callPackage ../servers/irc/ircd-hybrid { }; |