@@ -2,6 +2,7 @@ import ./make-test-python.nix ({ pkgs, ... }:
22
33let
44 configDir = "/var/lib/foobar";
5+ mqttUsername = "homeassistant";
56 mqttPassword = "secret";
67in {
78 name = "home-assistant";
@@ -11,6 +12,15 @@ in {
1112
1213 nodes.hass = { pkgs, ... }: {
1314 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+ };
1424 services.home-assistant = {
1525 inherit configDir;
1626 enable = true;
@@ -23,8 +33,11 @@ in {
2333 elevation = 0;
2434 };
2535 frontend = {};
26− # uses embedded mqtt broker
27− mqtt.password = mqttPassword;
36+ mqtt = {
37+ broker = "127.0.0.1";
38+ username = mqttUsername;
39+ password = mqttPassword;
40+ };
2841 binary_sensor = [{
2942 platform = "mqtt";
3043 state_topic = "home-assistant/test";
@@ -64,10 +77,10 @@ in {
6477 with subtest("Toggle a binary sensor using MQTT"):
6578 # wait for broker to become available
6679 hass.wait_until_succeeds(
67− "mosquitto_sub -V mqttv311 -t home-assistant/test -u homeassistant -P '${mqttPassword}' -W 1 -t '*'"
80+ "mosquitto_sub -V mqttv311 -t home-assistant/test -u ${mqttUsername} -P '${mqttPassword}' -W 1 -t '*'"
6881 )
6982 hass.succeed(
70− "mosquitto_pub -V mqttv311 -t home-assistant/test -u homeassistant -P '${mqttPassword}' -m let_there_be_light"
83+ "mosquitto_pub -V mqttv311 -t home-assistant/test -u ${mqttUsername} -P '${mqttPassword}' -m let_there_be_light"
7184 )
7285 with subtest("Print log to ease debugging"):
7386 output_log = hass.succeed("cat ${configDir}/home-assistant.log")