nixos/tests/home-assistant: replace internal mqtt broker with mosquitto

The internal broker was deprecated since 0.92.0 and removed in 0.112.0.
This commit is contained in:
Martin Weinelt 2020-07-01 19:17:01 +02:00
parent 963de34c62
commit 1093962cf0
No known key found for this signature in database
GPG Key ID: BD4AA0528F63F17E

View File

@ -2,6 +2,7 @@ import ./make-test-python.nix ({ pkgs, ... }:
let let
configDir = "/var/lib/foobar"; configDir = "/var/lib/foobar";
mqttUsername = "homeassistant";
mqttPassword = "secret"; mqttPassword = "secret";
in { in {
name = "home-assistant"; name = "home-assistant";
@ -11,6 +12,15 @@ in {
nodes.hass = { pkgs, ... }: { nodes.hass = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ mosquitto ]; environment.systemPackages = with pkgs; [ mosquitto ];
services.mosquitto = {
enable = true;
users = {
"${mqttUsername}" = {
acl = [ "pattern readwrite #" ];
password = mqttPassword;
};
};
};
services.home-assistant = { services.home-assistant = {
inherit configDir; inherit configDir;
enable = true; enable = true;
@ -23,8 +33,11 @@ in {
elevation = 0; elevation = 0;
}; };
frontend = {}; frontend = {};
# uses embedded mqtt broker mqtt = {
mqtt.password = mqttPassword; broker = "127.0.0.1";
username = mqttUsername;
password = mqttPassword;
};
binary_sensor = [{ binary_sensor = [{
platform = "mqtt"; platform = "mqtt";
state_topic = "home-assistant/test"; state_topic = "home-assistant/test";
@ -64,10 +77,10 @@ in {
with subtest("Toggle a binary sensor using MQTT"): with subtest("Toggle a binary sensor using MQTT"):
# wait for broker to become available # wait for broker to become available
hass.wait_until_succeeds( hass.wait_until_succeeds(
"mosquitto_sub -V mqttv311 -t home-assistant/test -u homeassistant -P '${mqttPassword}' -W 1 -t '*'" "mosquitto_sub -V mqttv311 -t home-assistant/test -u ${mqttUsername} -P '${mqttPassword}' -W 1 -t '*'"
) )
hass.succeed( hass.succeed(
"mosquitto_pub -V mqttv311 -t home-assistant/test -u homeassistant -P '${mqttPassword}' -m let_there_be_light" "mosquitto_pub -V mqttv311 -t home-assistant/test -u ${mqttUsername} -P '${mqttPassword}' -m let_there_be_light"
) )
with subtest("Print log to ease debugging"): with subtest("Print log to ease debugging"):
output_log = hass.succeed("cat ${configDir}/home-assistant.log") output_log = hass.succeed("cat ${configDir}/home-assistant.log")