36 lines
1.2 KiB
Bash
Executable File
36 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
fail() {
|
|
printf 'Home Assistant helper contract: %s\n' "$1" >&2
|
|
exit 1
|
|
}
|
|
|
|
project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
helper="$project_root/config/dot/quickshell/scripts/panama-home-assistant"
|
|
|
|
[[ -x "$helper" ]] || fail 'helper is missing or not executable'
|
|
|
|
probe="$($helper probe)"
|
|
jq -e '
|
|
.configured == true and
|
|
.reachable == true and
|
|
(.entityCount | type == "number" and . > 0) and
|
|
.error == ""
|
|
' <<<"$probe" >/dev/null || fail 'live API probe failed'
|
|
|
|
snapshot="$($helper snapshot)"
|
|
jq -e --argjson expected "$(jq '.entityCount' <<<"$probe")" '
|
|
.ok == true and
|
|
.configured == true and
|
|
.error == "" and
|
|
(.generatedAt | type == "number") and
|
|
(.entities | type == "array" and length == $expected) and
|
|
([.entities[] | (keys | sort) == (["active", "available", "domain", "id", "name", "state"] | sort)] | all) and
|
|
([.entities[] | (.active | type == "boolean") and (.available | type == "boolean")] | all)
|
|
' <<<"$snapshot" >/dev/null || fail 'live snapshot shape is invalid'
|
|
|
|
printf 'Home Assistant helper contract: PASS (configured=true, %s favourites; contents redacted)\n' \
|
|
"$(jq '.entities | length' <<<"$snapshot")"
|