1 import ./make-test-python.nix ({ pkgs, ... }:
4 configDir = "/var/lib/foobar";
5 mqttUsername = "homeassistant";
6 mqttPassword = "secret";
8 name = "home-assistant";
9 meta = with pkgs.stdenv.lib; {
10 maintainers = with maintainers; [ dotlambda ];
13 nodes.hass = { pkgs, ... }: {
14 environment.systemPackages = with pkgs; [ mosquitto ];
15 services.mosquitto = {
19 acl = [ "pattern readwrite #" ];
20 password = mqttPassword;
24 services.home-assistant = {
38 username = mqttUsername;
39 password = mqttPassword;
43 state_topic = "home-assistant/test";
44 payload_on = "let_there_be_light";
49 logs."homeassistant.components.mqtt" = "debug";
53 title = "My Awesome Home";
59 content = "Welcome to your **Lovelace UI**.";
63 lovelaceConfigWritable = true;
69 hass.wait_for_unit("home-assistant.service")
70 with subtest("Check that YAML configuration file is in place"):
71 hass.succeed("test -L ${configDir}/configuration.yaml")
72 with subtest("lovelace config is copied because lovelaceConfigWritable = true"):
73 hass.succeed("test -f ${configDir}/ui-lovelace.yaml")
74 with subtest("Check that Home Assistant's web interface and API can be reached"):
75 hass.wait_for_open_port(8123)
76 hass.succeed("curl --fail http://localhost:8123/lovelace")
77 with subtest("Toggle a binary sensor using MQTT"):
78 # wait for broker to become available
79 hass.wait_until_succeeds(
80 "mosquitto_sub -V mqttv311 -t home-assistant/test -u ${mqttUsername} -P '${mqttPassword}' -W 1 -t '*'"
83 "mosquitto_pub -V mqttv311 -t home-assistant/test -u ${mqttUsername} -P '${mqttPassword}' -m let_there_be_light"
85 with subtest("Print log to ease debugging"):
86 output_log = hass.succeed("cat ${configDir}/home-assistant.log")
87 print("\n### home-assistant.log ###\n")
88 print(output_log + "\n")
90 with subtest("Check that no errors were logged"):
91 assert "ERROR" not in output_log
93 # example line: 2020-06-20 10:01:32 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home-assistant/test: b'let_there_be_light'
94 with subtest("Check we received the mosquitto message"):
95 assert "let_there_be_light" in output_log