python.pkgs.pyqt5: 5.14.2 -> 5.15.0
[NixPkgs.git] / nixos / tests / home-assistant.nix
bloba93a28d877a31c790992d2da46eae5591f65ca5e
1 import ./make-test-python.nix ({ pkgs, ... }:
3 let
4   configDir = "/var/lib/foobar";
5   mqttUsername = "homeassistant";
6   mqttPassword = "secret";
7 in {
8   name = "home-assistant";
9   meta = with pkgs.stdenv.lib; {
10     maintainers = with maintainers; [ dotlambda ];
11   };
13   nodes.hass = { pkgs, ... }: {
14     environment.systemPackages = with pkgs; [ mosquitto ];
15     services.mosquitto = {
16       enable = true;
17       users = {
18         "${mqttUsername}" = {
19           acl = [ "pattern readwrite #" ];
20           password = mqttPassword;
21         };
22       };
23     };
24     services.home-assistant = {
25       inherit configDir;
26       enable = true;
27       config = {
28         homeassistant = {
29           name = "Home";
30           time_zone = "UTC";
31           latitude = "0.0";
32           longitude = "0.0";
33           elevation = 0;
34         };
35         frontend = {};
36         mqtt = {
37           broker = "127.0.0.1";
38           username = mqttUsername;
39           password = mqttPassword;
40         };
41         binary_sensor = [{
42           platform = "mqtt";
43           state_topic = "home-assistant/test";
44           payload_on = "let_there_be_light";
45           payload_off = "off";
46         }];
47         logger = {
48           default = "info";
49           logs."homeassistant.components.mqtt" = "debug";
50         };
51       };
52       lovelaceConfig = {
53         title = "My Awesome Home";
54         views = [{
55           title = "Example";
56           cards = [{
57             type = "markdown";
58             title = "Lovelace";
59             content = "Welcome to your **Lovelace UI**.";
60           }];
61         }];
62       };
63       lovelaceConfigWritable = true;
64     };
65   };
67   testScript = ''
68     start_all()
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 '*'"
81         )
82         hass.succeed(
83             "mosquitto_pub -V mqttv311 -t home-assistant/test -u ${mqttUsername} -P '${mqttPassword}' -m let_there_be_light"
84         )
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
96   '';