Merge pull request #52527 from dotlambda/home-assistant-cli-0.3.0

home-assistant-cli: init at 0.3.0
This commit is contained in:
Franz Pletz 2018-12-20 02:31:09 +00:00 committed by GitHub
commit 25eb8419d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 1 deletions

View File

@ -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";

View File

@ -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 ];
};
}

View File

@ -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 { };