···
meta.maintainers = lib.teams.home-assistant.members;
nodes.hass = { pkgs, ... }: {
10
-
environment.systemPackages = with pkgs; [ mosquitto ];
ensureDatabases = [ "hass" ];
···
# Cause a configuration change that requires a service restart as we added a new runtime dependency
specialisation.newFeature = {
inheritParentConfig = true;
111
-
configuration.services.home-assistant.config.device_tracker = [
112
-
{ platform = "bluetooth_tracker"; }
109
+
configuration.services.home-assistant.config.esphome = {};
···
···
package = match.group('path')
132
+
def get_journal_cursor(host) -> str:
133
+
exit, out = host.execute("journalctl -u home-assistant.service -n1 -o json-pretty --output-fields=__CURSOR")
135
+
return json.loads(out)["__CURSOR"]
138
+
def wait_for_homeassistant(host, cursor):
139
+
host.wait_until_succeeds(f"journalctl --after-cursor='{cursor}' -u home-assistant.service | grep -q 'Home Assistant initialized in'")
hass.wait_for_unit("home-assistant.service")
143
+
cursor = get_journal_cursor(hass)
with subtest("Check that YAML configuration file is in place"):
hass.succeed("test -L ${configDir}/configuration.yaml")
···
hass.succeed(f"grep -q 'wake_on_lan' {package}/extra_components")
with subtest("Check that Home Assistant's web interface and API can be reached"):
151
-
hass.wait_until_succeeds("journalctl -u home-assistant.service | grep -q 'Home Assistant initialized in'")
160
+
wait_for_homeassistant(hass, cursor)
hass.wait_for_open_port(8123)
hass.succeed("curl --fail http://localhost:8123/lovelace")
···
with subtest("Check service reloads when configuration changes"):
# store the old pid of the process
pid = hass.succeed("systemctl show --property=MainPID home-assistant.service")
174
+
cursor = get_journal_cursor(hass)
hass.succeed("${system}/specialisation/differentName/bin/switch-to-configuration test")
new_pid = hass.succeed("systemctl show --property=MainPID home-assistant.service")
assert pid == new_pid, "The PID of the process should not change between process reloads"
178
+
wait_for_homeassistant(hass, cursor)
with subtest("check service restarts when package changes"):
182
+
cursor = get_journal_cursor(hass)
hass.succeed("${system}/specialisation/newFeature/bin/switch-to-configuration test")
new_pid = hass.succeed("systemctl show --property=MainPID home-assistant.service")
assert pid != new_pid, "The PID of the process shoudl change when the HA binary changes"
186
+
wait_for_homeassistant(hass, cursor)
with subtest("Check that no errors were logged"):
output_log = hass.succeed("cat ${configDir}/home-assistant.log")